It's up to you but I think there is a more beautiful/easier way. Just configure the public render params the same in the portlet.xml. Use this to set params in e.g. an onClick:

ActionResponse actionResponse = (ActionResponse) ((PortletRequestContext)PortletRequestContext.get()).getPortletResponse();
actionResponse.setRenderParameter(name.getValue(), value);

And this to retrieve a parameter anywhere:
PortletRequestContext prc = (PortletRequestContext)RequestContext.get();
Map<String, String[]> map = prc.getPortletRequest().getPublicParameterMap();
map.get(name.getValue());

But that's up to you :)

Rob

On 8/14/09 1:50 AM, Gonzalo Aguilar Delgado wrote:
Hi all!

I managed to do it with wicket 1.4. This is how:

Define it in portlet.xml

<portlet-app>
...
<public-render-parameter>
         <identifier>crmportal:userId</identifier>
         <qname
xmlns:x="http://www.level2crm.com/params";>x:userId</qname>
</public-render-parameter>
</portlet-app>

Every portlet that will use it must also be configured with:
<portlet>
...
<supported-public-render-parameter>crmportal:userId</supported-public-render-parameter>
</portlet>

After doing this the portlet must have access to this parameter. But as
I have not access from Page processing to the
Wicket Portlet class I should hold the variable in session for a while:

                                 Link link = new Link("id", new
PropertyModel<String>(userObject, "uuid.uuid"))
                                {
                                        @Override
                                        public void onClick()
                                        {
                                        
                                                UUID uuid =  (UUID) 
this.getModelObject();
                                                
                                                PortletSession session =
((PortletRequestContext)RequestContext.get()).getPortletRequest()
                                                        .getPortletSession();
                                                
session.setAttribute(CustomerListPortlet.CURRENT_UUID,
uuid.toString());
                                        }
                                };


And after in the function processActionResponseState we can set the
public parameter after we recover it from session.

        @Override
        protected void processActionResponseState(String wicketURL,
                        String wicketFilterPath, String wicketFilterQuery,
                        PortletRequest request, ActionResponse response,
                        WicketResponseState responseState) throws 
PortletException,
                        IOException {
                
                PortletSession session = request.getPortletSession();
                String uuid = (String)session.getAttribute(CURRENT_UUID);
                if(uuid!=null)
                {
                        response.setRenderParameter("crmportal:userId", uuid);
                }
                
                // TODO Auto-generated method stub
                super.processActionResponseState(wicketURL, wicketFilterPath,
                                wicketFilterQuery, request, response, 
responseState);
        }



The other portlets will see this public render parameter as normal
parameter (NOTE: I don't know why not differentiate from the rest of
parameters. Can it have security considerations?).

This is accessible directly in the page (This is other portlet and other
application inside the portal):
        IModel loadableUserModel = new LoadableDetachableModel() {
                
                @Override
                protected Object load(){
                        User selectedUser = null;
                        String value =
((PortletRequestContext)RequestContext.get()).getPortletRequest().getParameter("crmportal:userId");
                        if(value!=null)
                        {
                                UuidUserType uuid = 
UuidUserType.fromString(value);
                                selectedUser = userDAO.find(uuid);
                                
                                if(!userDAO.isAttached(selectedUser))
                                {
                                        userDAO.save(selectedUser); //Attach it
                                }
                                
                                Set<ContactBasicDetail>  setDetails =
selectedUser.getContactBasicDetails();
                                setDetails.isEmpty();
                                
                                return setDetails.toArray();
                        }
                        return null;
                }
                
                
        };


It seems to work right.

But means are subject of discussion...

Tnx


El jue, 13-08-2009 a las 13:43 +0200, Gonzalo Aguilar Delgado escribió:

Hi all!,

I have some questions about parameter passing in portal environment. I
saw that WebPage class can have access to the Application class
but not the portlet class. This makes a little tricky to handle requests
because:

We can set session paramaters. And can call functions inside Application
(WicketExamplesMenuApplication.getExamples()).

@Override
public void onClick()
{
        int index = ((LoopItem)getParent()).getIteration();
        ExampleApplication ea =
WicketExamplesMenuApplication.getExamples().get(
                index + 1);
        PortletSession session =
((PortletRequestContext)RequestContext.get()).getPortletRequest()
                .getPortletSession();

session.setAttribute(WicketExamplesMenuPortlet.EXAMPLE_APPLICATION_ATTR,
ea);
}

But it will be the portlet class the responsible for handling
processing. So the only way to pass information from the onClick
function to the
portlet application for rendering (for example) is using the portlet
session.

But I suppose that's not the preferred way.


What's the best way to pass information to the portlet class? Is there
any way to use the portlet class like we use the application class
(WicketExamplesMenuApplication.getExamples() ->
WicketExamplesMenuPortlet.getExamples())


I also saw that in the portlet example, the examples structure is
initialized by the WicketExamplesMenuPortlet and sent to the
WicketExamplesMenuApplication using the servlet context. But this will
overbloat the servlet attributes storage space. Also this should be
solved if webpages could access to the portlet class directly.

Why to do this way?



I want to know all this because I want to use shared render parameters
(I put there a user id and all the portlets update accordingly). To do
this I will do:



         1.- Onclick: Put the Id on the session like above.
         2.- Portlet.DoView: Recover id from session and store it in
         shared render params.
         3.- Delete it from session.


Is this the correct way to do it?


Thank you very much in advance...



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to