2013-05-07 72 views

回答

0

您可以使用tag的valueChangeListener屬性。

 <h:selectManyCheckbox id="" value="#{bean.selectedItems}" valueChangeListener="#{bean.renderTextBox}"> 
     <f:selectItems value="#{bean.checkBoxList}"/> 
     </h:selectManyCheckbox> 
<h:inputText value="" rendered="#{bean.render}"/> 

在你的bean中有屬性叫render。 在valuechange方法即renderTextBox寫下面的代碼

public void renderTextBox(event) 
{ 

if(isInvokeApplicationPhase(event)) 
{ 
//change the value of render property to true or false depending on checkbox is checked or not 
} 

} 
public boolean isInvokeApplicationPhase(FacesEvent event){  
    if(event.getPhaseId() != PhaseId.INVOKE_APPLICATION){ 
     event.setPhaseId(PhaseId.INVOKE_APPLICATION); 
     event.queue(); 
     return false; 
    }  
    return true; 
} 

,並從數據庫中寫入獲取複選框列表下面的方法

public List getcheckBoxList() 
{ 
public List checkBoxList = null 
// retrieve list of checkbox from your db(write query here and assign returned list to checkBoxList variable and return that varaible) 
} 

getcheckBoxList()是一個getter方法。我必然的CheckBoxList變量<f:selectItems>標籤

+0

感謝您的解決方案。它的工作:)但是,當我添加兩個這樣的複選框列表,其行爲是一樣的。 FacecEvent總是被設置爲true。並取消選中複選框,文本框必須消失,這是沒有發生。試圖尋找更多關於這個,但沒有成功。 – 2013-05-08 14:51:44

+0

如果在複選框列表中有任何選中的複選框,即使您未選中其中一個,也會顯示文本框。那是你想要的儀式? – Archana 2013-05-09 03:56:25

0

您可以使用JavaScript來隱藏和顯示輸入框

var checkbox=document.getElementById("ID"); 

     if(checkbox.value== 'null') 
      checkbox.style.display = "none"; 
     else 
      checkbox.style.display = "inline";