Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Markus Maier
Liferay faces bridge 3.0.0-BETA2 / Url context structure
May 16, 2012 12:47 AM
Answer

Markus Maier

Rank: New Member

Posts: 13

Join Date: May 15, 2012

Recent Posts

Hello!

I am currently migrating a jsf 1.2 project (jboss portlet bridge) to a jsf 2.1 project (liferay portlet bridge).

The project has lots of views that reference custom servlets registered on portal level:
1<h:outputLink value="/portalservletcontext/">
2    linktext
3    <f:param name="id" value="123"/>
4    <f:param name="name" value="abc"/>
5</h:outputLink>

Previously this markup generated links like:
1http://liferayserver:liferayport/portalservletcontext/?id=123&name=abc

Now with the new bridge i get an extra portletcontext inserted into all urls:
1http://liferayserver:liferayport/portletcontext/portalservletcontext/?id=123&name=abc

Because of that additional context, the generated urls are no longer handled by the portal level servlets.

I debugged into
1com.liferay.faces.bridge.context.url.BridgeResourceURLImpl.toBaseURL()
but there doesn't seem to be a case that generates the urls i would require (without the portletcontext inserted).

How can i best solve that problem? I also tried the new Beta3 of the Jboss portlet bridge, the portletcontext is not inserted there, but i am not sure why links work differently with that bridge. Are there any plans to change/enhance the link generating for the final version of the Liferay faces bridge?

Thanks,

Max

Environment:
Liferay 6.0.6
Liferay Faces Bridge 3.0.0-BETA2
Mojarra 2.1.7
Neil Griffin
RE: Liferay faces bridge 3.0.0-BETA2 / Url context structure
May 16, 2012 7:46 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2365

Join Date: July 26, 2005

Recent Posts

Hi Markus,

Liferay Faces Bridge implements the JSR 329 spec so that all of the Test Compatibility Kit (TCK) tests pass, which would include tests regarding generation of URLs. We can try and support your use case, but we would have to do it in such a way that the TCK tests continue to pass.

Are you sure that h:outputLink is calling BridgeResourceURLImpl.toBaseURL() and not BridgeActionURLImpl.toBaseURL() ?

Thanks,

Neil
Markus Maier
RE: Liferay faces bridge 3.0.0-BETA2 / Url context structure
May 16, 2012 8:10 AM
Answer

Markus Maier

Rank: New Member

Posts: 13

Join Date: May 15, 2012

Recent Posts

Hello Neil,

thank you for your quick reply.

I just re-checked with the debugger, actually the class
1com.liferay.faces.bridge.context.url.liferay.BridgeResourceURLLiferayImpl
is called by the output link, and it uses the inherited method from the class BridgeResourceURLImpl.

I think it's not an uncommon usecase to call portal servlets from a portlet and it would be great if you could support it in some way!

Thanks,

Max
Neil Griffin
RE: Liferay faces bridge 3.0.0-BETA2 / Url context structure
May 16, 2012 9:49 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2365

Join Date: July 26, 2005

Recent Posts

OK thanks for finding that in the debugger. In the case of URLs that start with a forward-slash like /portalservletcontext the JSR 329 spec requires that the context-path be prepended. In the case of Liferay Faces Bridge, the BaseURLEncodedInternalStringImpl class does the prepending operation.

Questions for you:
1) What app server are you using?
2) In your specific situation, what is the actual value of /portalservletcontext ?
Markus Maier
RE: Liferay faces bridge 3.0.0-BETA2 / Url context structure
May 16, 2012 10:33 PM
Answer

Markus Maier

Rank: New Member

Posts: 13

Join Date: May 15, 2012

Recent Posts

Hello Neil!

1) I am using the Liferay Portal Server 6.0.6 CE.
2) One specific value would be /handleResource (+ various parameters) that maps to a custom portal servlet that globally serves and caches resources, images for example. Another portal servlet maps logical names to configured liferay pages, an example call in that case would be /callpage?page=home. When the user clicks the respective link he is redirected to the appropriate location.

Best regards,

Max
Neil Griffin
RE: Liferay faces bridge 3.0.0-BETA2 / Url context structure
May 17, 2012 7:11 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2365

Join Date: July 26, 2005

Recent Posts

Hi Max,

Are you using Tomcat? Also, can you paste here an actual absolute path to one of your servlets? Would it be like the following, referencing the ROOT context?
http://servername:port/callpage?page=home

Thanks,

Neil
Markus Maier
RE: Liferay faces bridge 3.0.0-BETA2 / Url context structure
May 17, 2012 10:47 PM
Answer

Markus Maier

Rank: New Member

Posts: 13

Join Date: May 15, 2012

Recent Posts

Hello Neil,

yes, the Liferay is set up on top of Apache Tomcat 6.
The url structure that you have assumed is exactly what the current bridge for jsf 1.2 is rendering!
The beta of the Liferay Faces Bridge is inserting the additional portlet-context and outputs that url like this:
http://servername:port/portlet-name/callpage?page=home

I also thought about reconfiguring the servlet mappings but i might run into conflicts there and would prefer a solution without that additional context in the url.

Best regards,

Max
Neil Griffin
RE: Liferay faces bridge 3.0.0-BETA2 / Url context structure
May 18, 2012 8:21 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2365

Join Date: July 26, 2005

Recent Posts

If you specify an absolute URL (one that includes the http://servername part) then it might work without making any changes to the bridge. You can easily do this by adding the Liferay Faces Portal dependency to your portlet project. It contains an EL keyword named "liferay" that you could use like this:
1<h:outputLink value="#{liferay.portalURL}/callpage?page=home" />
Markus Maier
RE: Liferay faces bridge 3.0.0-BETA2 / Url context structure
May 23, 2012 5:05 AM
Answer

Markus Maier

Rank: New Member

Posts: 13

Join Date: May 15, 2012

Recent Posts

Hello Neil!

I've tried prepending the portalURL to existing links (with both the EL-keyword and the respective method call LiferayFacesContext.getInstance().getPortalURL()) and thus making them absolute. It worked because the bridge then treats the url as external url and inserts no portlet context. The problem with that workaround is, that it cannot be used in libraries that are shared across portlets with different bridges (common taglibs for example).

I have reconfigured the portlet to use the latest Jboss Portlet Bridge (beta3) to see how such relative links are handled differently there.

The code that handles the encoding there is located in
1org.jboss.portletbridge.context.PortletExternalContextImpl.encodeResourceURL(String)
2
3Line 625:
4else if (!isInContext(portalUrl)) {
5    // 2) hierarchial url outside context.
6    encodeBackLink(portalUrl);
7    return encodeURL(portalUrl.toString());


Would be great if you could have a look at it and how i could achieve a similiar behavior with the liferay-optimized Liferay Faces Bridge.

Thank you,

Max
Neil Griffin
RE: Liferay faces bridge 3.0.0-BETA2 / Url context structure
May 23, 2012 10:00 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2365

Join Date: July 26, 2005

Recent Posts

Hi Markus,

Glad to hear that the absolute path worked. emoticon

Regarding the code you mentioned, if the context-path is not prepended, then the TCK "encodeResourceURLTest" will fail. I think the problem here is that the JSR 329 spec doesn't seem to support your use-case. emoticon

In order to utilize the absolute path solution in app your portlets, you could do something like the following in your libraries that are shared across portlets with different bridges:

1public String getPortalURL(PortletRequest portletRequest) {
2    ThemeDisplay themeDisplay = (ThemeDisplay) getPortletRequest().getAttribute(WebKeys.THEME_DISPLAY);
3    return themeDisplay().getPortalURL();
4}


Kind Regards,

Neil
Neil Griffin
RE: Liferay faces bridge 3.0.0-BETA2 / Url context structure
July 28, 2012 2:06 PM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2365

Join Date: July 26, 2005

Recent Posts

@Max: It turns out that you were right the whole time. Please see the last few comments of FACES-1331 for more info. The fix will appear in the GA1 release of Liferay Faces.