如何根据jsf中的单选按钮值隐藏或显示文本框

时间:2014-11-07 07:59:53

标签: jsf jsf-2 primefaces

我有一个评论框,需要显示和隐藏评论框,具体取决于上面的单选按钮选择。我不想使用jquery,我不知道这是jsf primeface的新手

我的代码如下:

<h:outputText value="Action :" class="alignment"/>

<p:selectOneRadio id="console" 
                  value="#{examinationFormBean.action}" 
                  required="true" label="Action">
    <f:selectItem itemLabel="Ok" itemValue="ok" />
    <f:selectItem itemLabel="Have Issued" 
                  itemValue="haveissue" />
</p:selectOneRadio>

<h:outputLabel value="Comment:"></h:outputLabel>
<h:inputText id="compid"    
             value="#{examinationFormBean.comment}"/>

<p:commandButton  value="Proceed to Zonal Electrical Inspector>>"
                  action="#{examinationFormBean.saveFormStatusByOfficeAssistent()}"  
                  update="messageid"  
                  process="data"  
                  oncomplete="if (args &amp;&amp; !args.validationFailed) PF('test').hide()" >

    <f:ajax  update="datatable"/>
</p:commandButton>

请帮我解决一下。提前谢谢

1 个答案:

答案 0 :(得分:1)

您可以使用JSF EL实现。

XHTML

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>hide some component</title>
    </h:head>

    <h:body>
        <h:form>
            <p:selectOneRadio id="console" 
                              value="#{examinationFormBean.radioVal}" 
                              required="true" label="Action">
                <f:selectItem itemLabel="Ok" itemValue="ok" />
                <f:selectItem itemLabel="Have Issued" 
                              itemValue="haveissue" />
                <p:ajax process="console" 
                        update="@form" />
            </p:selectOneRadio>

            <h:outputLabel value="Comment:" 
                           rendered="#{examinationFormBean.radioVal eq 'haveissue'}">
            </h:outputLabel>
            <h:inputText id="compid"    
                         value="#{examinationFormBean.comment}"
                         rendered="#{examinationFormBean.radioVal eq 'haveissue'}"/>
        </h:form>
    </h:body>

</html>

managedbean

@ViewScoped
@ManagedBean(name="examinationFormBean")
public class ExaminationFormBean implements Serializable{
    private String comment;
    private String radioVal;

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public String getRadioVal() {
        return radioVal;
    }

    public void setRadioVal(String radioVal) {
        this.radioVal = radioVal;
    }

}