Hi Paul ,
Actually I have solved almost all problems I have encountered. But I need
still your help.
First of all I have changed the my way because I understood it is not a good
way. Now I have a such an implementation.
public class AbstractResource {
/**
* For Validation
*/
private Boolean hasError = false;
}
public class myResource extends AbstractResource {
@GET
@Path("pathA/{ad}")
public Response getPageA(@PathParam Integer accId){
// Returning a simple page with a form
}
@POST
@Path("pathA")
@ValidationEnabled
public Response postPageA(@Inject Account acc){
if (!isHasError()) {
// do business logic
// redirect to a new URL.... For example It will use
getPageB
return Response.status(302).location(uri.build()).build();
} else {
return getPageA(acc.getId());
}
}
}
public class ValidationAdvice {
@Around("@annotation(valAnno)")
public Object check(ProceedingJoinPoint jp, ValidationEnabled valAnno) {
// validation ---> JSR 303
Map<String, String> map = validate(jp, valAnno);
// If Problem occurs
if (!map.isEmpty()) {
// add error flag to parent of resource (AbstractResource)
addErrorFlagToTarget(jp.getTarget());
// Proceed method
Object o = jp.proceed();
// add posted values to Response Object and returns it
// Note that o is a instance of Response Class
return o;
}
else
return jp.proceed();
;
}
}
I hope that I could explain clearly my usage...
My question will be about jersey internal invocation part of resources. My
implementation about adding errors to each resource is not very good... I
prefer doing with AOP that part too... But I do not know how to call
instead of this
@ValidationEnabled
public Response postPageA(@Inject Account acc){/**/}
I prefer this
@ValidationEnabled(URL="pathA/{ad}")
public Response postPageA(@Inject Account acc){/**/}
And a result of this, my ugly implementation about setting error and
returning page will not be used anymore...
My question is simply:
1) How can I call a resource in another resource... For example my url
string will be like this "pathA/{ad}"
but note that in my advice I have no knowledge about what is "ad" and my
resource context. I want a generic solution...
Thank you so much
Paul Sandoz wrote:
>
> Hi Cemo,
>
> Note that clients, such as browsers, when receiving a response to a
> POST request, do not automatically redirect to the Location URI for a
> redirection-based response.
>
> It seems the right thing to do here is to return the error data in the
> POST response. That response can contain a link to return the the page
> to POST again. However, I would expect in browser-based cases to use
> AJAX such that original page can be updated accordingly without having
> to go back and forth.
>
> Paul.
>
>
--
View this message in context: http://n2.nabble.com/Call-another-Resource-with-some-other-values-tp4205347p4231858.html
Sent from the Jersey mailing list archive at Nabble.com.