从一页导航到另一页(View Scope)时,在支持bean中设置属性不起作用 [英] Setting property in backing bean while navigating from one page to another (View Scope) doesn't work

查看:107
本文介绍了从一页导航到另一页(View Scope)时,在支持bean中设置属性不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在视图范围内有一个支持bean Authority,并且有两个页面viewRoleseditRole映射到该支持bean.

I have a backing bean Authority in the view scope and I have two pages viewRoles and editRole mapped to this backing bean.

viewRoles页面中,有一个链接可以转到editRole页面:

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>

它导航到另一个页面,但是即使Bean在视图范围内并且两个页面都映射到同一个支持Bean,也没有设置该属性.仅在将视图范围更改为会话范围时有效.

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.

注意:我的bean是由Spring管理的,该视图范围也不是JSF的默认@ViewScoped,这是我在

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.

问题是,上述场景是否应该与实际的JSF2 @ViewScoped @ManagedBean一起使用,还是该问题与Spring或其他问题有关? 请指教.

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.

推荐答案

否,这也不适用于JSF2 @ViewScoped bean的生存时间只要您通过在操作方法中返回nullvoid相同视图进行交互.在中使用 <f:param> 命令链接与 <f:viewParam>结合使用在目标视图中应该执行此操作.

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.

例如在命令链接中:

<h:form>
  <h:commandLink value="#{au.displayName}" action="pretty:editRole">
    <f:param name="authorityId" value="#{au.id}"/>                   
  </h:commandLink>
</h:form>

并在目标视图中:

<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>

这篇关于从一页导航到另一页(View Scope)时,在支持bean中设置属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆