2012-03-29 24 views
0

我的bean中有一個布爾(原始)變量。根據用戶選擇的單選按鈕,我需要它的值爲true或false。錯誤:無法在bean中的布爾屬性中將屬性值設置爲null

我在一個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

$('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 
}); 

該功能可以運行處理只選擇一個功能。至少有一半(我仍在繼續工作)。

但問題是。

如果我選中了「混合」單選按鈕,並且我嘗試進入另一頁面。 它給出錯誤「屬性不能設置爲null」。

有什麼辦法給它賦值false而不是null。也許在jQuery或通過豆。

請任何建議....

在此先感謝。

+1

是這個錯誤被提出了一個特定的線,是從螢火蟲或服務器端的錯誤? – Daniel 2012-03-29 06:25:00

+0

您使用的是JSF 2.0嗎? – 2012-03-29 06:49:15

+0

這是serverError。它無法在頁面提交中將值null設置爲原始布爾類型。 – 2012-03-29 07:09:14

回答

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> 
+0

嗨。功能正常,但它仍然給出相同的錯誤。不能將值設置爲null。有任何想法嗎。 – 2012-03-29 07:24:33

+0

也有一個需求略有更新。現在我有兩個變量。它沒有必要選擇任何。但是如果選擇了一個,其他的將是錯誤的。 – 2012-03-29 07:26:40

+0

@Karanveer也許你仍然有你的JavaScript干擾。否則,我不會看到值應該爲空。您可以使用布爾對象而不是原始類型。這可以爲null。 – 2012-03-29 07:35:27

相關問題