0

On a Liferay-Faces portlet, I want to navigate from a .xhtml page to another .xhtml page passing a parameter so that this second page displays the parameter passed. As I don’t want to give any clue about the parameter I’m passing, I decided to tackle that task on the basis of a POST request, so I chose to use a <h:commandLink> feature.

faces-config.xml:

<managed-bean>
    <managed-bean-name>bUser</managed-bean-name>
    <managed-bean-class>es.my.samples.UserBean</managed-bean-class>                         
    <managed-bean-scope>view</managed-bean-scope>
</managed-bean>

<navigation-rule>
    <from-view-id>WEB-INF/views/index.xhtml</from-view-id>
    <navigation-case>
        <from-action>#{bUser.viewDetailsAction}</from-action>                               
        <from-outcome>action-view-details</from-outcome>
        <to-view-id>WEB-INF/views/result1.xhtml</to-view-id>            
    </navigation-case>
</navigation-rule>

page1 (index.xhtml):

<h:form>
    <h:commandLink value="commandLink" action="#{bUser.viewDetailsAction()}">
        <f:param name="id" value="13" />
    </h:commandLink>
</h:form>

page2 (results2.xhtml):

<h:panelGrid columns="2">
    <h:outputLabel value="Requested id: " />
    <h:outputText value="#{bUser.id}" />
</h:panelGrid>

Viewscoped bean (UserBean.java):

@ManagedBean(name = "bUser")
@ViewScoped
public class UserBean {

    private String id;

    public UserBean() {
        logger.trace("bean created");
    }

    @PostConstruct
    public void postConstruct() {
        logger.trace("start");
        logger.trace("this.id:" + this.id);     
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        logger.trace("start [id]:" + id);
        this.id = id;
    }

    @PreDestroy
    public void preDestroy() {
        logger.trace("start");
        logger.trace("this.id:" + this.id);         
    }

    public String viewDetailsAction() {
        String _return = "action-view-details";

        Map<String,String> params = 
        FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
        this.id = params.get("id");

        logger.trace("this.id:" + this.id);

        return _return;
    }

Being the URL set to http://localhost:8080/web/guest/mission, when I press the ‘commandLink’ link I’m getting displayed on the screen the following error message (translated):

Cannot find the matching navigation case of the view ID '/WEB-INF/views/index.xhtml' for the action {1} with the result {2}.

If I omit on the faces-config.xml file the line <from-action>#{bUser.viewDetailsAction}</from-action>, then the navigation is carried out, the but the page does not display the parameter passed, despite of the fact that the parameter is extracted from the JSF params object, and as a consequence of a sort of a RENDER_RESPONSE phase started once the action method has finished, as it can be seen on the log displayed:

[TRACE] UserBean:<init>():start
[TRACE] UserBean:<init>():this.id:null
[TRACE] UserBean:<init>():bean created
[TRACE] UserBean:postConstruct():start
[TRACE] UserBean:postConstruct():this.id:null
[TRACE] UserBean:viewDetailsAction():this.id:13
[TRACE] UserBean:viewDetailsAction():_return:action-view-details
[TRACE] UserBean:preDestroy():start
[TRACE] UserBean:preDestroy():this.id:13
13:47:11,454 DEBUG [DebugPhaseListener:53] AFTER phaseId=[INVOKE_APPLICATION 5] viewId=[/WEB-INF/views/result1.xhtml]
13:47:11,539 DEBUG [DebugPhaseListener:69] BEFORE phaseId=[RENDER_RESPONSE 6] viewId=[/WEB-INF/views/result1.xhtml]
[TRACE] UserBean:<init>():start
[TRACE] UserBean:<init>():this.id:null
[TRACE] UserBean:<init>():bean created
[TRACE] UserBean:postConstruct():start
[TRACE] UserBean:postConstruct():this.id:null
13:47:11,832 DEBUG [DebugPhaseListener:53] AFTER phaseId=[RENDER_RESPONSE 6] viewId=[/WEB-INF/views/result1.xhtml]

Moreover, the URL has changed from http://localhost:8080/web/guest/mission to http://localhost:8080/web/guest/mission?p_auth=TBepgy6o&p_p_id=testparam_WAR_testparam&p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&p_p_col_id=&p_p_col_count=0&_testparam_WAR_testparam__facesViewIdRender=%2FWEB-INF%2Fviews%2Findex.xhtml, which is something I wanted to avoid.

I don't know if my approach to perform what I want is the right one or not. If it isn't, I’d appreciate any clarification; if I’m in the right path, I’d appreciate any clarification about why this second RENDER_RESPONSE phase is being carried out.

Background:

  • JSF 2.2,
  • Liferay 7.4 ga1
  • Liferay Faces.
txapeldot
  • 71
  • 2
  • 10

1 Answers1

0

I've sorted it out by using implicit navigation. It seems that explicit navigation doesn't just work on JSF 2.x, which is something I conclude from this post. In the quoted post it is said that faces-config.xml file is not needed at all. But I think that one thing is the fact of not being needed, and another very diferent thing is the fact of being compulsory not having to use it whatsover. Personally, and from my JSF1.x experience, I used to like the way page navigation was organized in a config file like faces-config.xml.

txapeldot
  • 71
  • 2
  • 10