Reputation: 1553
So I have the following jsf page (working):
<ui:define name="content">
<h:form>
<p:dataTable id="projectList" value="#{studyController.studyList}" var="item">
<p:column headerText="ID" >
<h:outputText value="#{item.id}"/>
</p:column>
<p:column headerText="Name">
<h:outputText value="#{item.name}"/>
</p:column>
<p:column headerText="Action">
<h:commandLink action="#{projectController.openProject(item.id)}" value="Project">
</h:commandLink>
</p:column>
</p:dataTable>
</h:form>
</ui:define>
And this is the bean, that is called on link click:
@Named
public class ProjectController{
private Integer projectId;
public String openProject(Integer projectId){
// this works, System.out.println shows correct setting
this.projectId = projectId;
// now redirect to correct jsf page via faces-config.xml
return "show_project";
}
// this is called by the jsf page to be shown
public Integer getProjectId(){
// this is null :(
return this.projectId;
}
}
My faces-config.xml is something like:
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>show_project</from-outcome>
<to-view-id>/project.xhtml</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
It all works, except the projectId of the ProjectController is lost between the call of openProject - which is called and debug shows correct id in the console - and the rendering of the page, where the page does someting linke #{projectController.getProjectId} - because this returns null.
How can i retain the value in the bean until the page is rendered? I tried with some @SessionScope, @RequestScope and stuff, but frankly I don't understand the full Extend of the JFS lifecycle.
Just to provide some more info, I'm using JBoss AS 7.2 with PrimeFaces 3.4.2
Upvotes: 1
Views: 497
Reputation: 1109715
As to your concrete problem, that (old fashioned) navigation case is specifying a redirect. A redirect basically instructs the client to send a brand new HTTP request on the given resource. The initial request on which you've set the attribtue is been trashed for that.
I'm not sure what your concrete functional requirement is, so it's hard to propose the right solution to achieve that. One way would be to remove <redirect>
entry from your navigation case. Another way would be to use a plain link with a <f:param>
and the <f:viewParam>
in the target page in order to set/convert it (this instantly also improves bookmarkability and thus SEO and UX). Again another way would be to use the flash scope.
Upvotes: 1