【问题标题】:JSF2: Is there any way to use a4j:param with rich:select or h:selectOneMenuJSF2:有什么方法可以将 a4j:param 与 rich:select 或 h:selectOneMenu 一起使用
【发布时间】:2011-08-14 04:34:49
【问题描述】:

是否可以与下拉菜单一起使用,或者它是否也依赖于实现 ActionSource 的父对象,就像 f:setPropertyActionLister 一样?

理想情况下,我会执行以下操作:

<h:selectOneMenu value="#{myCustomBean.selectedItemIndex}">
    <f:selectItems value="#{adminLetterAdminBean.missingSettings}" var="n" itemValue="#{n.id}" itemLabel="#{n.name}"/>
    <f:setPropertyActionListener value="42" target="#{adminLetterAdminBean.someProperty}" />
    <a4j:ajax />
</rich:select>

但这不起作用,因为 h:selectOneMenu 没有实现 javax.faces.component.ActionSource。该页面没有呈现,它给了我一个友好的堆栈跟踪来告诉我这个依赖。

在 Richfaces 文档中没有看到任何关于此约束的内容,我尝试了以下方法:

<h:selectOneMenu value="#{myCustomBean.selectedItemIndex}">
    <f:selectItems value="#{adminLetterAdminBean.missingSettings}" var="n" itemValue="#{n.id}" itemLabel="#{n.name}"/>
    <a4j:param assignTo="#{adminLetterAdminBean.someProperty}" value="42" name="randomRequestParamName"/>
    <a4j:ajax />
</rich:select>

这不会炸毁,但它也会设置属性。我想知道是否以类似的方式设置了一个(或多个)属性。

【问题讨论】:

    标签: ajax jsf-2 richfaces ajax4jsf


    【解决方案1】:

    a4j:param 只能嵌套在 a4j:commandButon、a4j:commandLink 和 a4j:jsFunction 等动作组件中。您还可以将它与标准按钮/链接组件一起使用。

    【讨论】:

    • 感谢您的回复。您是否知道任何涉及此限制的文档?
    • 没有,但我问过 RichFaces 团队的人 ;)
    • 这对我来说已经足够了。感谢您的信息。我个人的建议是以与 f:setPropertyActionListener 类似的方式炸毁,因为它实际上无法正常工作,但可惜我离题了。再次感谢,你得到了积分!
    【解决方案2】:

    我遇到了类似的问题。在完成自动完成请求之前,我的页面必须传输有关自动完成的信息。我通过使用 jsFunction 实现了这一点。我的自动完成看起来像:

    <rich:autocomplete mode="ajax" showButton="true" value="#{conf.fieldValue}" 
          autocompleteMethod="#{BackingBean.search.autocomplete}" 
          minChars="3" onfocus="sendInfo('#{conf.label}')">
    </rich:autocomplete>
    

    根据 conf.label(conf 是一个 forEach 变量),支持 bean 在自动完成方法中获取不同的数据。

    这些信息的传递是由 jsFunction 完成的(就在自动完成声明之后):

    <a4j:jsFunction name="sendInfo">
         <a4j:param name="param1" assignTo="#{BackingBean.search.currentAutocomplete}"/>
    </a4j:jsFunction>
    

    只是,当用户将焦点放在特定的自动完成上时,“sendInfo”会使用一个绑定到支持 bean 的参数来执行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-12
      • 2016-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-23
      • 2020-04-07
      相关资源
      最近更新 更多