h:commandLink 在列表内时不起作用

发布于 2024-11-26 17:29:08 字数 787 浏览 4 评论 0原文

我对 RichFaces 和创建链接列表有疑问。如果您尝试在列表中使用任何类型的 commandLink(我已尝试过 ui:repeat 和 rich:list),则不会调用该链接上的操作。我还尝试过 commandButton 和它们的 a4j 变体。我在 Jboss 6 上使用 JSF 2、RichFaces 4。

<rich:list var="venue" value="#{searchManager.results}" type="definitions" stateVar="status">
  <h:form>
    <h:commandLink value="CLICK IT" immediate="true" action="#{score.selectVenue}" />
  </h:form>
</rich:list>

表单的位置也并不重要。

<h:form>
   <rich:list var="venue" value="#{searchManager.results}" type="definitions" stateVar="status">
       <h:commandLink value="CLICK IT" immediate="true" action="#{score.selectVenue}" />
   </rich:list>
</h:form>

如果我只有链接本身(没有列表),它就可以工作。

任何帮助将不胜感激。

I have a problem with RichFaces and creating lists of links. If you attempt to use any type of commandLink inside a list (I've tried ui:repeat and rich:list) the action on that link is not called. I've also tried commandButton and the a4j variations of those. I'm using JSF 2, RichFaces 4 on Jboss 6.

<rich:list var="venue" value="#{searchManager.results}" type="definitions" stateVar="status">
  <h:form>
    <h:commandLink value="CLICK IT" immediate="true" action="#{score.selectVenue}" />
  </h:form>
</rich:list>

The position of the form also doesn't matter.

<h:form>
   <rich:list var="venue" value="#{searchManager.results}" type="definitions" stateVar="status">
       <h:commandLink value="CLICK IT" immediate="true" action="#{score.selectVenue}" />
   </rich:list>
</h:form>

If I just have the link by itself (no list) it works.

Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

深者入戏 2024-12-03 17:29:08

当您单击命令链接或按命令按钮提交表单时,JSF 将在应用请求值阶段扫描组件树以查找相关命令链接/按钮,以便找到与其关联的操作表达式,即在你的情况下#{score.selectVenue}

但是,为了能够实现这一目标,您需要确保 #{searchManager.results} 返回与显示表单时完全相同的列表。因为结果列表为空,所以在表单提交的应用请求值阶段,视图中根本不会有命令链接/按钮。

您的 #{searchManager} bean 似乎是请求范围的。请求作用域 bean 的生命周期恰好是一个请求-响应周期。因此,当您提交表单时,您将获得一个全新的请求范围 bean 的另一个 实例,而不是显示表单时的实例。 results 属性似乎在 bean 构建(后)期间没有被保留,因此仍然为空。因此,JSF 无法找到有问题的命令链接/按钮,因此无法找到与其关联的操作表达式,从而无法调用它。

当您使用 JSF2 时,一个简单的修复方法是将 bean 放置在视图范围中。这样,只要您通过在操作方法中返回 nullvoid 提交并导航到完全相同的视图,bean 就会一直存在。

@ManagedBean
@ViewScoped
public class SearchManager {
    // ...
}

另请参阅:

When you click a command link or press a command button to submit a form, JSF will during the apply request values phase scan the component tree for the command link/button in question so that it can find the action expression associated with it, which is in your case #{score.selectVenue}.

However to be able to ever reach that, you would need to ensure that #{searchManager.results} returns exactly the same list as it did when the form was displayed. Because with an empty result list, there would be no command link/button in the view at all during the apply request values phase of the form submit.

Your #{searchManager} bean seems to be request scoped. Request scoped beans have a lifetime of exactly one request-response cycle. So when you submit the form, you'll get a brand new and another instance of the request scoped bean than it was when the form was displayed. The results property seems not to be preserved during (post)construction of the bean and thus remains empty. So JSF cannot find the command link/button in question and thus cannot find the action expression associated with it and thus cannot invoke it.

As you're using JSF2, an easy fix is to place the bean in the view scope. This way the bean will live as long as you're submitting and navigating to exactly the same view by returning null or void in action methods.

@ManagedBean
@ViewScoped
public class SearchManager {
    // ...
}

See also:

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