Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Christophe Noel
Using ADT in JSF Facelet ?
March 2, 2017 7:24 AM
Answer

Christophe Noel

Rank: New Member

Posts: 7

Join Date: October 16, 2013

Recent Posts

Hi guys,

Congrats and thanks for all the impressive enhancements of Liferay 7 !

I would like to use application display templates (ADT) in JSF facelet (instead of JSP page). Is there a way to do so ?
May I use at least "PortletDisplayTemplateUtil.renderDDMTemplate" in a <h:outputText> (does it return HTML? I see no description in the Javadocs).

Alternatively, is there a way to mix JSP and JSF into a single portlet ? (edit: found a topic for this part- link)

Thanks a lot for your guidelines.
Kyle Joseph Stiemann
RE: Using ADT in JSF Facelet ?
March 8, 2017 9:20 AM
Answer

Kyle Joseph Stiemann

LIFERAY STAFF

Rank: Liferay Master

Posts: 583

Join Date: January 14, 2013

Recent Posts

Hi Christophe,

Sorry it took so long to respond.

Christophe Noel:
Hi guys,

Congrats and thanks for all the impressive enhancements of Liferay 7 !

Thanks for the kind words!

Christophe Noel:
Alternatively, is there a way to mix JSP and JSF into a single portlet ? (edit: found a topic for this part- link)

Similar to Neil's recommendation in that forum post, I would recommend creating a non-JSF JSP based portlet using all of Liferay's JSP features (and adding any templates you need). Then you can use the portal:runtime component to include the JSP portlet within your JSF portlet views.

Christophe Noel:
I would like to use application display templates (ADT) in JSF facelet (instead of JSP page). Is there a way to do so ?
May I use at least "PortletDisplayTemplateUtil.renderDDMTemplate" in a <h:outputText> (does it return HTML? I see no description in the Javadocs).

I'm not sure about this, but I'm currently looking into it. If you have time, it should be pretty easy to test.

In your Bean.java file, do something like this:

public String getRenderedTemplateMarkup() {

FacesContext facesContext = FacesContext.getCurrentInstance();

ExternalContext externalContext = facesContext.getExternalContext();

PortletRequest portletRequest = (PortletRequest) externalContext.getRequest();

PortletResponse portletResponse = (PortletResponse) externalContext.getResponse();

HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(portletRequest);

HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(portletResponse);

/* Obtain ddmTemplate and entries here... */

return PortletDisplayTemplateUtil.renderDDMTemplate(httpServletRequest, httpServletResponse, ddmTemplate, entries);

}


In your facelet .xhtml file do something like this:

<h:outputText value="#{bean.renderedTemplateMarkup}" escape="false" />

I'll let you know if I find any limitations to using PortletDisplayTemplateUtil in a JSF portlet. I don't expect any though.

- Kyle
Kyle Joseph Stiemann
RE: Using ADT in JSF Facelet ?
March 8, 2017 11:52 AM
Answer

Kyle Joseph Stiemann

LIFERAY STAFF

Rank: Liferay Master

Posts: 583

Join Date: January 14, 2013

Recent Posts

I was able to test PortletDisplayTemplateUtil.renderDDMTemplate() with h:outputText escape="false" in the jsf-ds-applicant-portlet and it worked correctly. The (rough) example code is here: https://github.com/stiemannkj1/liferay-faces-portal/tree/test-DDMTemplate-in-jsf-ds-portlet-3.x/demo/jsf-ds-applicant-portlet. Here is the diff for all changes that I made to the jsf-ds-applicant-portlet: https://github.com/stiemannkj1/liferay-faces-portal/commit/140586de867b41d6d9a096a7411a45d7d1ec631b. These changes are likely imperfect, but I think they are a good start. You may also want to take a look at the ApplicationDisplayTemplates documentation and the primefaces-users-portlet (for an example of best practices when using Liferay's service utilities).

- Kyle
Christophe Noel
RE: Using ADT in JSF Facelet ?
November 20, 2017 2:25 AM
Answer

Christophe Noel

Rank: New Member

Posts: 7

Join Date: October 16, 2013

Recent Posts

Thank you Kyle. Sorry I moved to other projects and forgot to reply. Your suggestions were applied by a colleague and I think it helped a lot.
Kyle Joseph Stiemann
RE: Using ADT in JSF Facelet ?
November 20, 2017 5:55 AM
Answer

Kyle Joseph Stiemann

LIFERAY STAFF

Rank: Liferay Master

Posts: 583

Join Date: January 14, 2013

Recent Posts

That's great to know, Christophe! Thanks for using Liferay Faces!

- Kyle

Participate in the State of Liferay Community 2017. Help the community and even win some prizes!