Fórumok

JSF tags not rendered on doView

thumbnail
Olivier ROMAND, módosítva 12 év-val korábban

JSF tags not rendered on doView

New Member Bejegyzések: 24 Csatlakozás dátuma: 2012.01.07. Legújabb bejegyzések
Hi people,

I'm struggling on some very simple stuff, but can't get it working.

I have a portlet with a dedicated portlet class inheriting from GenericsFacesPortlet. I want the portlet to choose which view to display depending on some action.

- When the user triggers the search command, we would run the search and display the results.
- When the user triggers the advanced search command, we would display the advanced search view.

The portlet.xml file is as follow:


 <portlet>
        <portlet-name>AutonomySearch</portlet-name>
        <display-name>AutonomySearch</display-name>
        <portlet-class>fr.sg.steria.portlet.SearchActionPortlet</portlet-class>
        <init-param>
            <name>javax.portlet.faces.defaultViewId.view</name>
            <value>/xhtml/autonomysearch/portletAdvancedSearch.xhtml</value>
        </init-param>
        <supports>
            <mime-type>text/html</mime-type>
            <portlet-mode>view</portlet-mode>
        </supports>
        <portlet-info>
            <title>AutonomySearch</title>
            <short-title>AutonomySearch</short-title>
        </portlet-info>
        <security-role-ref>
            <role-name>administrator</role-name>
        </security-role-ref>
        <security-role-ref>
            <role-name>guest</role-name>
        </security-role-ref>
        <security-role-ref>
            <role-name>power-user</role-name>
        </security-role-ref>
        <security-role-ref>
            <role-name>user</role-name>
        </security-role-ref>
    </portlet>


I overriden the doView method that way:

	@Override
	protected void doView(RenderRequest renderRequest,
			RenderResponse renderResponse) throws PortletException, IOException {
                    PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher("/xhtml/autonomysearch/portletSearchResults.xhtml"); 
                     rd.include(renderRequest,renderResponse);
     	}


Finally, the .xhtml file is as follow:


<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:aui="http://portletfaces.org/alloyfaces/aui" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:bridge="http://portletfaces.org/bridge" xmlns:example-cc="http://java.sun.com/jsf/composite/example-cc" xmlns:ui="http://java.sun.com/jsf/facelets">
	
	<ui:remove>
	<!-- 
			Necessary to include jsf.js manually to get the library loaded.
		 -->
	</ui:remove>
	<h:outputscript library="javax.faces" name="jsf.js" />
	
	<p>Here, there's the list of results</p>

	<br>

	<div style="border:1px black solid;">
	
	</div>
</ui:composition>


1) What happens is that the include would just "copy" the view, whithout interpreting anything of it. See below:



2) If I use forward in the doView method, rather than include, I would end up in error with "Portlet isn't available ... "

Would you be so kind to bring a bit of expertise here ?

Thanks really much in advance.
thumbnail
David H Nebinger, módosítva 12 év-val korábban

RE: JSF tags not rendered on doView

Liferay Legend Bejegyzések: 14916 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
Rather than including the xhtml directly, try including the /xhtml/autonomysearch/portletSearchResults.faces instead. Include is just pulling in the file and including (but not interpreting it), but you need to include the result of the faces servlet's rendering of the xhtml file...
thumbnail
Olivier ROMAND, módosítva 12 év-val korábban

RE: JSF tags not rendered on doView

New Member Bejegyzések: 24 Csatlakozás dátuma: 2012.01.07. Legújabb bejegyzések
Thanks for the input David,

But the framework didn't get tricked.

1) Is the way of working conceptually correct ?
2) Any chance to have some workaround ? or reason of such poor behavior ?

Thanks !
thumbnail
David H Nebinger, módosítva 12 év-val korábban

RE: JSF tags not rendered on doView

Liferay Legend Bejegyzések: 14916 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
Well normally I'd handle this stuff directly within the JSF page itself, rather than trying to patch together a solution using the import option within the doView() method...
thumbnail
Olivier ROMAND, módosítva 12 év-val korábban

RE: JSF tags not rendered on doView

New Member Bejegyzések: 24 Csatlakozás dátuma: 2012.01.07. Legújabb bejegyzések
Thanks for the input David.

It took me a while to understand what you meant by handling it in JSF.
I went for a view with show/hide controls using a boolean attribute, but it didn't fit my needs.
Next step has been to handle navigation through redirection within a Backing Beans to pass parameters to a <f:viewParam>

Anyway, thanks again !
thumbnail
Ranga Rao Bobbili, módosítva 11 év-val korábban

RE: JSF tags not rendered on doView

Regular Member Bejegyzések: 152 Csatlakozás dátuma: 2007.07.20. Legújabb bejegyzések
Hi All,

My solution to override view dynamically in the doView()

Step1:
Mention init-parameter for default view

<init-param>
<name>javax.portlet.faces.defaultViewId.view</name>
<value>/template/ctmgmt/appealsImpl/providerAppealsImpl.xhtml</value>
</init-param>

Step2:

Override doView() or render() method in custom GenericFacesPortlet and mention below code snippet instead of RequestDispacher.include() or RequestDispacher.forward().


public void render(RenderRequest renderRequest,
RenderResponse renderResponse) throws PortletException, IOException {
getDefaultViewIdMap().put("view","/template/ctmgmt/appealsImpl/programAppealsImpl.xhtml");
super.render();
}


Thanks,
Ranga Rao Bobbili
Adaequare INC
Steven Birr, módosítva 8 év-val korábban

RE: JSF tags not rendered on doView

New Member Bejegyzések: 18 Csatlakozás dátuma: 2014.01.22. Legújabb bejegyzések
Thank's! For me this worked also:

In portlet.xml:

		<portlet-class>Path_To_Your_PortletClass</portlet-class>
		<init-param>
			<name>jsf-view1</name>
			<value>/WEB-INF/html/jsftest/jsfview.xhtml</value>
		</init-param>


In Portlet code:

  public void doView(RenderRequest request, RenderResponse response) throws IOException, PortletException
  {
    getDefaultViewIdMap().put("view",getInitParameter("jsf-view1"));
    super.doView(request, response);
  }