HOME - Recent Changes - Search:

Academic Work


Personal

* pot de départ


dblp


(:twitter:)

-----

[ edit | logout ]
[ help | sandbox | passwd ]

Set some render parameters from action

#############################

Problem

You have a portlet that shows some results based on some render parameters. You have a link to which you want to assign an action. This will refresh the portlet but you want to show the same result, i.e. you want to reuse the same render parameters. However, when an action is activated, render parameters are reset.

Solution

When processAction is executed, you can set some render parameters.

Example 1

See http://www.caucho.com/resin-3.0/portlet/tutorial/basic-action/index.xtp#Render-parameters-are-reset for a basic example.

Example 2

Create an action URL in the JSP:

private String getActionLink(String instName, int currLevel)
{
    PortletURL portletUrl = response.createActionURL();

    // this is for the action
    portletUrl.setParameter("tps2instance", instName);

    // this is for the rendering
    portletUrl.setParameter("setLevelOf", instName);
    portletUrl.setParameter(instName, ""+currLevel);
    portletUrl.setParameter("level", ""+globalLevel);

    return portletUrl.toString();
}

Here I want to put tps2instance to the session (for passing it to another portlet), and I want to use the other three variables for the rendering phase. However, since we create an action URL here, you cannot get the value of setLevelOf via request.getParameter("setLevelOf") for instance. In order to do so, we must do the following.

The portlet's code:

public void processAction(ActionRequest request, ActionResponse response)
throws IOException, PortletException
{
    // this one goes in the session
    String tps2instance = request.getParameter("tps2instance");
    if (tps2instance != null) {
        request.getPortletSession().setAttribute("tps2instance", tps2instance, PortletSession.APPLICATION_SCOPE);
    }

    //////////

    /*
     * Put back the necessary render parameters.
     * These will be available with request.getParameter("...")
     */
    response.setRenderParameters(request.getParameterMap());
}
Cloud City


anime | bash | blogs | bsd | c/c++ | c64 | calc | comics | convert | cube | del.icio.us | digg | east | eBooks | egeszseg | elite | firefox | flash | fun | games | gimp | google | groovy | hardware | hit&run | howto | java | javascript | knife | lang | latex | liferay | linux | lovecraft | magyar | maths | movies | music | p2p | perl | pdf | photoshop | php | pmwiki | prog | python | radio | recept | rts | scala | scene | sci-fi | scripting | security | shell | space | súlyos | telephone | torrente | translate | ubuntu | vim | wallpapers | webutils | wikis | windows


Blogs and Dev.

* Ubuntu Incident
* Python Adventures
* me @ GitHub


Places

Debrecen | France | Hungary | Montreal | Nancy


Notes

full circle | km


Hobby Projects

* Jabba's Codes
* PmWiki
* Firefox
* PHP
* JavaScript
* Scriptorium
* Tutorials
* me @ GitHub


Quick Links


[ edit ]

View - Edit - History - Attach - Print *** Report - Recent Changes - Search
Page last modified on 2010 March 04, 22:04