I have a backing bean Authority
in the view scope and I have two pages viewRoles
and editRole
mapped to this backing bean.
In the viewRoles
page there's a link to go to editRole
page:
<h:form>
<h:commandLink value="#{au.displayName}" action="pretty:editRole">
<f:setPropertyActionListener target="#{authority.authorityId}" value="#{au.id}"/>
</h:commandLink>
</h:form>
It navigates to the other page, but the property is not getting set, even though the bean is in the view scope and the both pages are mapped to the same backing bean. It only works when I change the view scope to session scope.
Note: my beans are managed by Spring, also this view scope is not the JSF default @ViewScoped
, it's a custom one which I found on http://cagataycivici.wordpress.com/2010/02/17/port-jsf-2-0s-viewscope-to-spring-3-0/ . Also I am using PrettyFaces to manage my navigation.
The question is, is the above scenario supposed to work with a real JSF2 @ViewScoped
@ManagedBean
or is the problem related to Spring or another problem? please advise.
No, this will also not work with a JSF2 @ViewScoped
bean. You're basically navigating to a different view. A @ViewScoped
bean lives as long as you're interacting with the same view by returning null
or void
in the action methods. Using <f:param>
in the command link in combination with <f:viewParam>
in the target view should do it.
Eg in the command link:
<h:form>
<h:commandLink value="#{au.displayName}" action="pretty:editRole">
<f:param name="authorityId" value="#{au.id}"/>
</h:commandLink>
</h:form>
and in the target view:
<f:metadata>
<f:viewParam name="authorityId" value="#{authority.authorityId}"
required="true" requiredMessage="Invalid page access. Please use a link from within the system."
/>
</f:metadata>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.