使用JQuery隐藏/显示<p:inputText>

JSF*_*ner 2 jquery jsf primefaces

有没有选项将标志设置为true并隐藏<p:inputText id="name" value="#{mybean.value}" />更改?

下面的JSF代码

<h:form>
      <p:selectOneMenu style="width:150px" id="id" onchange="onCall()">
              <f:selectItem itemLabel="Select" itemValue=""></f:selectItem>
              <f:selectItem itemLabel="Other" itemValue="Other"></f:selectItem>
       </p:selectOneMenu>
       <p:selectBooleanCheckbox id="flag"/>
       <p:inputText id="name" value="#{mybean.value}/>
 </h:form>
Run Code Online (Sandbox Code Playgroud)

请给我一个解决我的问题的想法

Hat*_*mam 8

你有两种方法来实现这个,jQuery或Normal JSF.


JSF


private Boolean renderInputText;

public void setRenderInputText(Boolean renderInputText) {
    this.renderInputText = renderInputText
}

public Boolean getRenderInputText() {
   return renderInputText;
}
Run Code Online (Sandbox Code Playgroud)

XHTML

<p:selectBooleanCheckbox id="flag" value="{bean.renderInputText}" >.
   <p:ajax update="inputPanel" />
</p:selectBooleanCheckbox>

<h:panelGroup id="inputPanel">
    <p:inputText rendered="{bean.renderInputText}"/>
</h:panelGroup>
Run Code Online (Sandbox Code Playgroud)

jQuery的


<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:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

<h:head>
    <!-- This can be located either in the facelet or in external js file-->
    <script>
        $(function() {
            PF('selectWV').jq.change(function() {
                if (PF('selectWV').isChecked()) {
                    PF('buttonWV').jq.show();
                } else {
                    PF('buttonWV').jq.hide();
                }
            })
        })
    </script>
</h:head>

<h:body>

    <h:form id="form">
                    Accept Terms: <p:selectBooleanCheckbox
            widgetVar="selectWV" />
        <p:commandButton value="Register" widgetVar="buttonWV"
            style="display: none" />
    </h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)

一个小的工作示例(jQuery版本)可以在github上找到,两个主要文件terms.xhtmlterms.js

和一个在线演示.

希望这可以帮助.