Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf h:selectOneRadio不';无法使用ajax更改事件_Jsf_Jsf 2 - Fatal编程技术网

Jsf h:selectOneRadio不';无法使用ajax更改事件

Jsf h:selectOneRadio不';无法使用ajax更改事件,jsf,jsf-2,Jsf,Jsf 2,我有两个单选按钮,默认情况下没有选择任何一个,并且必须选择其中一个,因此我做了如下操作: <div id="payment_method"> <h:message for="sel_payment_method" style="Color:red;"/> <h:selectOneRadio id="sel_payment_method" required="true" requiredMessage="Please select a pay

我有两个单选按钮,默认情况下没有选择任何一个,并且必须选择其中一个,因此我做了如下操作:

   <div id="payment_method">
     <h:message for="sel_payment_method" style="Color:red;"/>
     <h:selectOneRadio id="sel_payment_method" required="true" requiredMessage="Please select a payment method" value="#{myBean.selectedPaymentMethod}">  
       <f:selectItem itemLabel="Debit or Credit Card" itemValue="credit" />  
       <f:selectItem itemLabel="Checking Account" itemValue="checking" />
       <f:ajax event="change" render="credit_inputs_fragment checking_inputs_fragements" />             
     </h:selectOneRadio>
    </div>

selectedPaymentMethod
属性是一个字符串,其默认值为null

credit\u inputs\u片段是一个包含div的ui:fragement

问题:单击单选按钮时,要更改的两个片段不受影响


请告知,谢谢。

我遵循了以下链接中的示例代码,它解决了我的问题:


您在描述具体问题时并不完全清楚,但我可以在目前发布的代码中看到至少两个潜在问题:

  • 在单选按钮和复选框的情况下,
    是错误的。它应该是
    event=“click”
    。或者,更好的办法是,干脆把它全部去掉。它已经默认为正确的。另见

  • 中引用的组件必须是完整的JSF UI组件,并且始终呈现给客户端。如果组件本身从未呈现到HTML中,那么JavaScript就无法找到它来更新其内容。基本上,您需要在另一个始终呈现的组件中有条件地呈现组件。另见