简体   繁体   English

selectOneMenu中的JSF侦听器

[英]JSF listeners in selectOneMenu

I have a selectOneMenu item with some products. 我有一些产品的selectOneMenu项目。 Some of them are unavailable so after you click on it the button "Add" should be disabled and some message should appear that "Sorry the product you chose is currently unavailable". 其中一些不可用,因此单击它后,应禁用“添加”按钮,并应显示一些消息,“抱歉,您选择的产品当前不可用”。 I have no idea how to achieve that. 我不知道如何实现这一目标。 Tried listeners, ajax and still nothing. 试听者,ajax仍然没有。

This is one of many versions of my JSF Page: 这是我的JSF页面的许多版本之一:

<h:form>
            <h:selectOneMenu value="#{productBean.productName}">
                <f:selectItems id ="other" value="#{productBean.other}" var="other" itemValue="#{ordersBean.productName}" itemLabel="#{other.name}" />
                <f:ajax listener="#{productBean.valueChanged}" />
            </h:selectOneMenu>
            <h:commandButton value ="Dodaj do zamówienia" rendered="#{productBean.available}"/>
                    <h:outputLabel id="orderSummary"/>
        </h:form>

Beans are rather standard. 豆是相当标准的。 I just need a clue how to do that and probably I will be able to do it myself. 我只需要一个提示如何做到这一点,也许我自己就能做到。

Thanks in advance. 提前致谢。

Here's one of the ways: 这是方法之一:

  1. In your AJAX listener you could check if a product is available and set up bean field accordingly, or add a message for a component. 在您的AJAX侦听器中,您可以检查产品是否可用,并相应地设置bean字段,或为组件添加消息。
  2. Introduce a component in your view that'll hold the message to the user, for example with the #{bean.available ? '' : 'Sorry, out of stock'} 在您的视图中引入一个组件,该组件会将消息保留给用户,例如,使用#{bean.available ? '' : 'Sorry, out of stock'} #{bean.available ? '' : 'Sorry, out of stock'} value, or enclose it within a <h:panelGroup> and let that component have a rendered attribute, or attach <h:message> / <h:messages> somewhere in your view. #{bean.available ? '' : 'Sorry, out of stock'}值,或将其包含在<h:panelGroup>并让该组件具有rendered属性,或在视图中的某个位置附加<h:message> / <h:messages>
  3. Specify id of the message holder to be rendered within render attribute of <f:ajax> tag. <f:ajax>标记的render属性中指定要呈现的消息持有者的ID。

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

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