myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Freedman <>
Subject Re: action link in custom component (inside a portlet)
Date Tue, 22 Jan 2008 16:29:55 GMT
Safer bet is to call ViewHandler.getActionURL passing in your viewId 
followed by ExternalContext.encodeActionURL.  With bridges prior to the 
JSR 301 bridge you may have problems adding/retaining the extra QS 
params you want to add (namely PARAM_ITEMID, PARAM_ITEMTYPE).  With the 
301 bridge you can either add these QS params directly to the viewId 
passed to getActionURL or you can add them to the URL returned by 
getActionURL before calling encodeActionURL.

Martin Goldhahn wrote:
> Hi!
> I need to render some text containing links i a JSF component. I
> cannot render a full commandLink element, since the data comes from a
> content management system and the contract allows me to only modify
> the href attribute of the anker element. The whole thing runs under
> Liferay, a portlet container.
> The solution I came up with is:
> - declare a outputText element in the jsp and use its binding
> attribute to create my own UIComponent.
> - my UIComponent renders its children (getRendersChildren returns true)
> - override encodeChildren and output the text while modifying the href
> attribute of the href tokens.
> I can click the link in the rendered page but the lifecycle gets
> somehow distorted, because the viewrott is not restored properly, i.e.
> The RestoreViewExecutor cannot restore the view. T
> he result is that the lifecycle is interrupted and the request doesn't
> get through to the "Invoke Application" phase.
> Here is how I create the action link: ( the code is mostly copied from
> org.apache.myfaces.shared_impl.renderkit.html.HtmlLinkRenderBase
>     String viewId = "/article/article.jsp";
>     if (PortletUtil.isRenderResponse(context)) {
>       RenderResponse response =
> (RenderResponse)context.getExternalContext().getResponse();
>       PortletURL url = response.createActionURL();
>       url.setParameter(MyFacesGenericPortlet.VIEW_ID, viewId);
>       url.setParameter(PARAM_ITEMID, hrefToken.getLinkData());
>       url.setParameter(PARAM_ITEMTYPE, hrefToken.getLinkType().toString());
>       return url.toString() + '#';
>     }
> Is there a better way of generating an action url. This implementation
> has a hard-coded navigation and is so ugly. There must be a better
> way.
> Any ideas are much appreciated.
> Cheers
> Martin

View raw message