Foros de discusión

Using ADT in JSF Facelet ?

Christophe Noel, modificado hace 7 años.

Using ADT in JSF Facelet ?

New Member Mensajes: 7 Fecha de incorporación: 16/10/13 Mensajes recientes
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.
thumbnail
Kyle Joseph Stiemann, modificado hace 7 años.

RE: Using ADT in JSF Facelet ?

Liferay Master Mensajes: 760 Fecha de incorporación: 14/01/13 Mensajes recientes
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
thumbnail
Kyle Joseph Stiemann, modificado hace 7 años.

RE: Using ADT in JSF Facelet ?

Liferay Master Mensajes: 760 Fecha de incorporación: 14/01/13 Mensajes recientes
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, modificado hace 6 años.

RE: Using ADT in JSF Facelet ?

New Member Mensajes: 7 Fecha de incorporación: 16/10/13 Mensajes recientes
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.
thumbnail
Kyle Joseph Stiemann, modificado hace 6 años.

RE: Using ADT in JSF Facelet ?

Liferay Master Mensajes: 760 Fecha de incorporación: 14/01/13 Mensajes recientes
That's great to know, Christophe! Thanks for using Liferay Faces!

- Kyle