h:selectOneRadio不适用于ajax更改事件 [英] h:selectOneRadio doesn't work with ajax change event

查看:127
本文介绍了h:selectOneRadio不适用于ajax更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个单选按钮,默认情况下没有一个被选中,并且必须选择其中一个,所以这就是我所做的:

i have two radio buttons and no one is selected by default, and it's mandatory to select one of them, so here's what i did:

   <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

the selectedPaymentMethod property is a string and its default value is null

credit_inputs_fragment 是包含div的ui:fragement

and the credit_inputs_fragment is a ui:fragement that contains a div

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

ISSUE: when clicking on a radio buttons the two fragments to be changed are not affected.

请告知,谢谢.

推荐答案

您在描述具体问题上并不十分清楚,但是到目前为止,我在代码中至少看到了两个潜在问题:

You're not entirely clear in describing the concrete problem, but I can see at least two potential problems in the code posted so far:

  1. 对于单选按钮和复选框,<f:ajax event="change">是错误的.它应该是event="click".或者,更好的是,将其完全删除.它默认为正确的一个.另请参见我可以将哪些值传递给f:ajax标记的事件属性?

  1. The <f:ajax event="change"> is wrong in case of radiobuttons and checkboxes. It should be event="click". Or, better, just remove it altogether. It defaults to the right one already. See also What values can I pass to the event attribute of the f:ajax tag?

<f:ajax render>中引用的组件必须是完全有价值的JSF UI组件,并且总是呈现给客户端.如果组件本身从未呈现为HTML,则JavaScript根本找不到它来更新其内容.基本上,您需要在始终渲染的另一个组件中有条件渲染的组件.另请参见为什么需要嵌套带有render ==#{some}"的组件?在另一个组件中,当我想对其进行ajax更新时?

The component referenced in <f:ajax render> must be a fullworthy JSF UI component and always be rendered to the client side. If the component is by itself never rendered to the HTML, then JavaScript simply can't find it to update its content. You basically need the conditionally rendered components in another component which is always rendered. See also Why do I need to nest a component with rendered="#{some}" in another component when I want to ajax-update it?

这篇关于h:selectOneRadio不适用于ajax更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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