2013-05-07 70 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";