Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Portlets - Differences between setAttribute and setRenderParameter

Tags:

portlet

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 ?

like image 505
user2472508 Avatar asked Jun 10 '13 21:06

user2472508


1 Answers

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(){
like image 113
Mark Chorley Avatar answered Jan 01 '23 12:01

Mark Chorley