错误:无法在bean的布尔属性中将属性值设置为null

时间:2012-03-29 06:06:55

标签: jquery jsf datatable radio-button

我的bean中有一个布尔(原始)变量。我需要将其值设置为true或false,具体取决于用户选择的单选按钮。

我在jsf数据表的同一行的两个不同列中实现JSF单选按钮。 我需要在同一行的两列中使用单选按钮。

现在,我必须确保只为行选择了一个按钮ID。

所以我的方法是,

我使用一个映射到bean的单选按钮,另一个单选按钮作为虚拟按钮。

<h:column>
 <h:selectOneRadio id="mixtas" value="#{bean.mixtas}">
  <f:selectItem itemValue="true"></f:selectItem>
 </h:selectOneRadio>    
</h:column>

<h:column>
 <h:selectOneRadio id="exclusi" >
  <f:selectItem itemValue="true"></f:selectItem>
 </h:selectOneRadio>
</h:column>

我正在使用jquery

处理select一个功能
$('input[id*="mixtas"]').live("click",function(){
    var $index = this.id.split(':')[2]; \\to identify the row index
    var $id = $index+":exclusi:0"; \\generating id for other radio button
    $('table[id$="'+$id+'"]').attr("checked",false); \\ to make the other radio false   
});

$('input[id*="exclusi"]').live("click",function(){
    var $index = this.id.split(':')[2]; \\ to identify the row index
    var $id = $index+":mixtas:0"; \\generating id for other radio button
    $('input[id$="'+$id+'"]').attr("checked",false); \\ to make the other radio false   
});

功能有效。至少一半(我还在继续工作)。

但问题是。

如果我没有选中mixtas单选按钮,我会尝试继续浏览另一页。 它给出错误“属性mixtas不能设置为null ”。

有没有办法为它赋值false而不是null。也许在jquery或通过bean。

请提出任何建议....

提前致谢。

1 个答案:

答案 0 :(得分:0)

根据您之前的问题,我假设您使用的是JSF 2.0。然后,您可以在没有自定义javascript的情况下获得所需的行为:

<h:column>
  <h:selectOneRadio value="#{bean.mixtas}" id="mixtas">
    <f:selectItem itemValue="true"/>
    <f:ajax render="exclusi"/>
  </h:selectOneRadio>
</h:column>

<h:column>
  <h:selectOneRadio value="#{bean.mixtas}" id="exclusi">
     <f:selectItem itemValue="false"/>
     <f:ajax render="mixtas"/>
  </h:selectOneRadio>
</h:column>