I'm a beginner with portlets, and I don't understand the difference between request.setAttribute and response.setRenderParameter (for an action). Both save an attribute into the request and allow to access to it after. I think specially about transmission between a processAction and the render which is just after the action method.
I know that with setRenderParameter we cannot "stock" a complex object, but if I just want to transfer a String which one should I use?
In which case should we use the setRenderParameter
method or the setAttribute
method ?
Well, one sets an attribute on a request. The other sets a parameter on the response. They are different objects, obviously.
response.setRenderParameter is of use if you wish to call different render methods based on your action. For example, imagine your action method sends an email, and you want to show the user a different view on success and failure. In this case, you would do something like this in your ActionMapping
if(sentOK){
response.setRenderParameter("result", "success");
}else{
response.setRenderParameter("result", "fail");
}
And then have two RenderMapping methods:
@RenderMapping(params = "result=success")
public String success(){
@RenderMapping(params = "result=fail")
public String fail(){
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With