h:commandLink在列表中时不起作用 [英] h:commandLink not working when inside a list

查看:161
本文介绍了h:commandLink在列表中时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在RichFaces和创建链接列表时遇到问题.如果您尝试在列表中使用任何类型的commandLink(我尝试过ui:repeat和rich:list),则不会调用该链接上的操作.我也尝试过commandButton和这些的a4j变体.我在Jboss 6上使用的是JSF 2,RichFaces 4.

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.

任何帮助将不胜感激.

推荐答案

当您单击命令链接或按命令按钮提交表单时,JSF将在应用请求值"阶段扫描组件树中的命令链接/有问题的按钮,以便它可以找到与之关联的动作表达式,在您的情况下为#{score.selectVenue}.

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

无论如何,您需要确保#{searchManager.results}返回与显示表单时完全相同的列表.因为结果列表为空,所以在表单提交的应用请求值阶段,视图中根本没有命令链接/按钮.

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.

您的#{searchManager} bean似乎是请求范围的.请求范围的Bean的生存期仅为一个请求-响应周期.因此,当您提交表单时,与显示表单时相比,您将获得请求范围的bean的全新实例和另一个另一个实例. results属性似乎在Bean的(后)构造期间未保留,因此保持为空.因此,JSF找不到相关的命令链接/按钮,因此找不到与之关联的动作表达式,因此无法调用它.

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.

使用JSF2时,一个简单的解决方法是将bean放置在视图范围内.这样,只要您在操作方法中返回nullvoid来提交并导航到完全相同的视图,该Bean就会一直存在.

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 {
    // ...
}

另请参见:

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