简体   繁体   English

JSF2:有什么方法可以使用 a4j:param 和 rich:select 或 h:selectOneMenu

[英]JSF2: Is there any way to use a4j:param with rich:select or h:selectOneMenu

Is it possible to use with dropdown menus or is it also dependent on the parent object implementing ActionSource as the f:setPropertyActionLister is?是否可以与下拉菜单一起使用,或者它是否也依赖于父 object 实现 ActionSource 作为 f:setPropertyActionLister 是?

Ideally I would have done something like the following:理想情况下,我会执行以下操作:

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

However this does not work because h:selectOneMenu does not implement javax.faces.component.ActionSource.但是这不起作用,因为 h:selectOneMenu 没有实现 javax.faces.component.ActionSource。 The page does not render and it gives me a friendly stack trace to tell me about this dependency.该页面没有呈现,它给了我一个友好的堆栈跟踪来告诉我这种依赖关系。

Not seeing anything in the Richfaces documentation about this constraint, I tried the following:在 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>

This does not blow up, but it also does not set the property.这不会炸毁,但也不会设置属性。 I was wondering if there is a set a (or multiple) properties in a similar fashion.我想知道是否以类似的方式设置了一个(或多个)属性。

a4j:param can only be nested inside an action component such as a4j:commandButon, a4j:commandLink and a4j:jsFunction. a4j:param 只能嵌套在动作组件中,例如 a4j:commandButon、a4j:commandLink 和 a4j:jsFunction。 You can also use it with the standard button/link components.您还可以将它与标准按钮/链接组件一起使用。

I had a similiar problem.我有一个类似的问题。 My page has to transfer information about the autocomplete before the autocomplete request is done.在完成自动完成请求之前,我的页面必须传输有关自动完成的信息。 I achieved this by using jsFunction.我通过使用 jsFunction 实现了这一点。 My autocomplete looks like:我的自动完成看起来像:

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

Depending on conf.label (conf is a forEach variable) different data is fetched by the backing bean in the autocomplete method.根据 conf.label(conf 是一个 forEach 变量),支持 bean 在自动完成方法中获取不同的数据。

The transfer of this information is done by jsFunction (just after the autocomplete declaration):此信息的传输由 jsFunction 完成(就在自动完成声明之后):

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

Just, when the user puts the focus on a specific autocomplete "sendInfo" is executed with one parameter which is bound to the backing bean.只是,当用户将焦点放在特定的自动完成上时,“sendInfo”会使用一个绑定到支持 bean 的参数来执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM