从一个页面导航到另一页面(查看范围)时在支持 bean 中设置属性不起作用
我在视图范围中有一个支持 bean Authority
,并且有两个页面 viewRoles
和 editRole
映射到该支持 bean。
在 viewRoles
页面中,有一个转到 editRole
页面的链接:
<h:form>
<h:commandLink value="#{au.displayName}" action="pretty:editRole">
<f:setPropertyActionListener target="#{authority.authorityId}" value="#{au.id}"/>
</h:commandLink>
</h:form>
它导航到其他页面,但该属性未设置,即使 bean 位于视图中范围并且两个页面都映射到同一个支持 bean。仅当我将视图范围更改为会话范围时它才有效。
注意:我的 bean 由 Spring 管理,而且此视图范围不是 JSF 默认的 @ViewScoped
,它是我在 http://cagataycivici.wordpress.com/2010/02/17/port-jsf-2-0s-viewscope-to-spring-3-0/。我还使用 PrettyFaces 来管理我的导航。
问题是,上述场景是否适用于真正的 JSF2 @ViewScoped
@ManagedBean
或者该问题与 Spring 或其他问题有关? 请指教。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,这也不适用于 JSF2
@ViewScoped
bean。您基本上是在导航到不同的视图。@ViewScoped
只要您通过在操作方法中返回null
或void
与相同视图进行交互,bean 就会存在。使用;
在命令链接中与应该执行此操作。
例如在命令链接中:
和在目标视图中:
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 returningnull
orvoid
in the action methods. Using<f:param>
in the command link in combination with<f:viewParam>
in the target view should do it.E.g. in the command link:
and in the target view: