How to set the value of p:selectOneRadio with Client Side API?

前端 未结 1 1200
天涯浪人
天涯浪人 2021-01-03 08:52

In my JSF view I am using a p:selectOneRadio. Now I have to change the value of this component on client side as side effect. In the Client Side API of this component I have

相关标签:
1条回答
  • 2021-01-03 09:00

    The element that should be passed is the <span> which simulates the radio look and feel, this span has .ui-radiobutton-box as CSS class, the simple call would be:

    PF('selectOneRadioWV').select($('.ui-radiobutton-box').first())
    

    This would select the first radio.

    However the select function would select only, which is not the expected behaviour, the expected one would be unselect the previous selected radio and select the new one.

    Being that said, if you would like to select based on value (which makes more sense) the following approach would work:

    PF('selectOneRadioWV').jq.find('input:radio[value="1"]').parent().next().trigger('click.selectOneRadio');
    

    In there it's selecting the radio input which has the value 1 then navigating to the corresponding .ui-radiobutton-box where it triggers the event defined by the widget. In that way you make sure any ajax related events are called accordingly.

    0 讨论(0)
提交回复
热议问题