Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在JSF中有条件地要求元素_Jsf_Jsf 2 - Fatal编程技术网

如何在JSF中有条件地要求元素

如何在JSF中有条件地要求元素,jsf,jsf-2,Jsf,Jsf 2,我的表单中有一个简单的输入文本元素 用户在该表单上有两种可能的操作:1)批准表单和2)拒绝表单。因此,表单底部有两个按钮供用户单击 如果用户单击approve,comment输入字段应该是可选的。如果用户单击拒绝,则应需要注释输入字段 以下是表格的简单表示: <h:form> <p:inputText id="comment" required="???" .../> <p:commandButton id="approve" ... />

我的表单中有一个简单的输入文本元素

用户在该表单上有两种可能的操作:1)批准表单和2)拒绝表单。因此,表单底部有两个按钮供用户单击

如果用户单击
approve
comment
输入字段应该是可选的。如果用户单击
拒绝
,则应需要
注释
输入字段

以下是表格的简单表示:

<h:form>
    <p:inputText id="comment" required="???" .../>

    <p:commandButton id="approve" ... />
    <p:commandButton id="reject" ... />
</h:form>

试试这个

<h:form id="forma">
    <p:inputText id="comment" 
                 value="#{userView.firstname}" 
                 title="comment" 
                 required="#{not empty param[reject.clientId]}"/>
    <p:message for="comment"/>

    <p:commandButton id="approve" 
                     binding="#{approve}" 
                     value="approve" 
                     process="@form" 
                     update="@form"/>
    <p:commandButton id="reject" 
                     binding="#{reject}" 
                     value="reject" 
                     process="@form" 
                     update="@form"/>
</h:form>

试试这个

<h:form id="forma">
    <p:inputText id="comment" 
                 value="#{userView.firstname}" 
                 title="comment" 
                 required="#{not empty param[reject.clientId]}"/>
    <p:message for="comment"/>

    <p:commandButton id="approve" 
                     binding="#{approve}" 
                     value="approve" 
                     process="@form" 
                     update="@form"/>
    <p:commandButton id="reject" 
                     binding="#{reject}" 
                     value="reject" 
                     process="@form" 
                     update="@form"/>
</h:form>

您的问题看起来很像

修改
required
属性,如下所示:

<h:form id="form">
    <p:inputText id="comment" required="#{not empty param['form:reject']}" ... />
    <p:commandButton id="approve" ... />
    <p:commandButton id="reject" ... />
</h:form> 

您的问题看起来很像

修改
required
属性,如下所示:

<h:form id="form">
    <p:inputText id="comment" required="#{not empty param['form:reject']}" ... />
    <p:commandButton id="approve" ... />
    <p:commandButton id="reject" ... />
</h:form> 


谢谢@BalusC!我想我没有使用正确的搜索词。谢谢@BalusC!我想我没有使用正确的搜索词。