admin管理员组文章数量:1316523
In my JSF view I am using a p:selectOneRadio. Now I have to change the value of this ponent on client side as side effect. In the Client Side API of this ponent I have found the following which I think I could use for this if I find the proper way how to use it:
PrimeFaces.widget.SelectOneRadio=PrimeFaces.widget.BaseWidget.extend(
{
// ...
select:function(a){
this.checkedRadio=a;
a.addClass("ui-state-active")
.children(".ui-radiobutton-icon")
.addClass("ui-icon-bullet").removeClass("ui-icon-blank");
a.prev().children(":radio").prop("checked",true)}
});
To me (without having much knowledge about JS) it looks like I have to pass something similar to an instance of the radio-button I want to select. I have tried this in several ways, but none of them works:
<p:selectOneRadio widgetVar="sel" id="id-sel" >
<f:selectItem itemValue="#{false}" itemLabel="n/a" />
<f:selectItem itemValue="#{true}" itemLabel="date" />
</p:selectOneRadio>
<p:mandButton onclick="PF('sel').select(sel.inputs[1]);"/>
<p:mandButton onclick="PF('sel').select(PF('sel').inputs[1]);"/>
<p:mandButton onclick="PF('sel').select( $('input:radio[id*=id-sel\\:1]') );"/>
<p:mandButton
onclick="PF('sel').select(document.getElementById('menuform:id-sel:1'));"/>
However, I also tried to pass the value and/or label directly (this works e.g. for selectOneMenu). Again without success (but not surprising in this case)
<p:mandButton onclick="PF('sel').select('date');"/>
<p:mandButton onclick="PF('sel').select('true');"/>
<p:mandButton onclick="PF('sel').select(1);"/>
<p:mandButton onclick="PF('sel').select(true);"/>
<p:mandButton onclick="PF('sel').select(#{true});"/>
Anybody knows what to do here?
In my JSF view I am using a p:selectOneRadio. Now I have to change the value of this ponent on client side as side effect. In the Client Side API of this ponent I have found the following which I think I could use for this if I find the proper way how to use it:
PrimeFaces.widget.SelectOneRadio=PrimeFaces.widget.BaseWidget.extend(
{
// ...
select:function(a){
this.checkedRadio=a;
a.addClass("ui-state-active")
.children(".ui-radiobutton-icon")
.addClass("ui-icon-bullet").removeClass("ui-icon-blank");
a.prev().children(":radio").prop("checked",true)}
});
To me (without having much knowledge about JS) it looks like I have to pass something similar to an instance of the radio-button I want to select. I have tried this in several ways, but none of them works:
<p:selectOneRadio widgetVar="sel" id="id-sel" >
<f:selectItem itemValue="#{false}" itemLabel="n/a" />
<f:selectItem itemValue="#{true}" itemLabel="date" />
</p:selectOneRadio>
<p:mandButton onclick="PF('sel').select(sel.inputs[1]);"/>
<p:mandButton onclick="PF('sel').select(PF('sel').inputs[1]);"/>
<p:mandButton onclick="PF('sel').select( $('input:radio[id*=id-sel\\:1]') );"/>
<p:mandButton
onclick="PF('sel').select(document.getElementById('menuform:id-sel:1'));"/>
However, I also tried to pass the value and/or label directly (this works e.g. for selectOneMenu). Again without success (but not surprising in this case)
<p:mandButton onclick="PF('sel').select('date');"/>
<p:mandButton onclick="PF('sel').select('true');"/>
<p:mandButton onclick="PF('sel').select(1);"/>
<p:mandButton onclick="PF('sel').select(true);"/>
<p:mandButton onclick="PF('sel').select(#{true});"/>
Anybody knows what to do here?
Share Improve this question asked Jan 22, 2015 at 14:35 stgstg 2,7972 gold badges30 silver badges55 bronze badges1 Answer
Reset to default 10The 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.
本文标签: javascriptHow to set the value of pselectOneRadio with Client Side APIStack Overflow
版权声明:本文标题:javascript - How to set the value of p:selectOneRadio with Client Side API? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742006927a2412145.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论