Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Olivier ROMAND
JSF tags not rendered on doView
February 22, 2012 9:08 AM
Answer

Olivier ROMAND

Rank: Junior Member

Posts: 25

Join Date: January 7, 2012

Recent Posts

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:

 1
 2 <portlet>
 3        <portlet-name>AutonomySearch</portlet-name>
 4        <display-name>AutonomySearch</display-name>
 5        <portlet-class>fr.sg.steria.portlet.SearchActionPortlet</portlet-class>
 6        <init-param>
 7            <name>javax.portlet.faces.defaultViewId.view</name>
 8            <value>/xhtml/autonomysearch/portletAdvancedSearch.xhtml</value>
 9        </init-param>
10        <supports>
11            <mime-type>text/html</mime-type>
12            <portlet-mode>view</portlet-mode>
13        </supports>
14        <portlet-info>
15            <title>AutonomySearch</title>
16            <short-title>AutonomySearch</short-title>
17        </portlet-info>
18        <security-role-ref>
19            <role-name>administrator</role-name>
20        </security-role-ref>
21        <security-role-ref>
22            <role-name>guest</role-name>
23        </security-role-ref>
24        <security-role-ref>
25            <role-name>power-user</role-name>
26        </security-role-ref>
27        <security-role-ref>
28            <role-name>user</role-name>
29        </security-role-ref>
30    </portlet>


I overriden the doView method that way:
1
2    @Override
3    protected void doView(RenderRequest renderRequest,
4            RenderResponse renderResponse) throws PortletException, IOException {
5                    PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher("/xhtml/autonomysearch/portletSearchResults.xhtml");
6                     rd.include(renderRequest,renderResponse);
7         }


Finally, the .xhtml file is as follow:

 1
 2<ui:composition
 3    xmlns="http://www.w3.org/1999/xhtml"
 4    xmlns:aui="http://portletfaces.org/alloyfaces/aui"
 5    xmlns:c="http://java.sun.com/jsp/jstl/core"
 6    xmlns:f="http://java.sun.com/jsf/core"
 7    xmlns:h="http://java.sun.com/jsf/html"
 8    xmlns:bridge="http://portletfaces.org/bridge"
 9    xmlns:example-cc="http://java.sun.com/jsf/composite/example-cc"
10    xmlns:ui="http://java.sun.com/jsf/facelets"
11    >
12   
13    <ui:remove>
14    <!--
15            Necessary to include jsf.js manually to get the library loaded.
16         -->
17    </ui:remove>
18    <h:outputScript library="javax.faces" name="jsf.js" />
19   
20    <p>Here, there's the list of results</p>
21
22    <br/>
23
24    <div style="border:1px black solid;">
25   
26    </div>


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.
David H Nebinger
RE: JSF tags not rendered on doView
February 22, 2012 11:22 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11771

Join Date: September 1, 2006

Recent Posts

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...
Olivier ROMAND
RE: JSF tags not rendered on doView
February 22, 2012 12:35 PM
Answer

Olivier ROMAND

Rank: Junior Member

Posts: 25

Join Date: January 7, 2012

Recent Posts

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 !
David H Nebinger
RE: JSF tags not rendered on doView
February 22, 2012 4:08 PM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11771

Join Date: September 1, 2006

Recent Posts

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...
Olivier ROMAND
RE: JSF tags not rendered on doView
March 1, 2012 11:48 PM
Answer

Olivier ROMAND

Rank: Junior Member

Posts: 25

Join Date: January 7, 2012

Recent Posts

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 !
Ranga Rao Bobbili
RE: JSF tags not rendered on doView
March 12, 2013 8:14 PM
Answer

Ranga Rao Bobbili

Rank: Regular Member

Posts: 152

Join Date: July 20, 2007

Recent Posts

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 Pietzsch
RE: JSF tags not rendered on doView
May 5, 2015 6:43 AM
Answer

Steven Pietzsch

Rank: New Member

Posts: 19

Join Date: January 22, 2014

Recent Posts

Thank's! For me this worked also:

In portlet.xml:
1
2        <portlet-class>Path_To_Your_PortletClass</portlet-class>
3        <init-param>
4            <name>jsf-view1</name>
5            <value>/WEB-INF/html/jsftest/jsfview.xhtml</value>
6        </init-param>


In Portlet code:
1
2  public void doView(RenderRequest request, RenderResponse response) throws IOException, PortletException
3  {
4    getDefaultViewIdMap().put("view",getInitParameter("jsf-view1"));
5    super.doView(request, response);
6  }