从一个页面导航到另一页面(查看范围)时在支持 bean 中设置属性不起作用

发布于 2024-12-12 04:08:11 字数 963 浏览 0 评论 0原文

我在视图范围中有一个支持 bean Authority,并且有两个页面 viewRoleseditRole 映射到该支持 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

め可乐爱微笑 2024-12-19 04:08:11

不,这也不适用于 JSF2 @ViewScoped bean。您基本上是在导航到不同的视图。 @ViewScoped 只要您通过在操作方法中返回 nullvoid相同视图进行交互,bean 就会存在。使用 ;在命令链接中与 应该执行此操作。

例如在命令链接中:

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

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.

E.g. 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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文