<h:form prependId="false" id="parentForm">
...
<h:form prependId="false" id="commentForm">
...
add comment
</h:form>
save
</h:form>不工作..。
在没有内部表单的情况下,当我只想添加注释时,父元素就会得到验证。
"add comment“应该只验证注释,当单击"save”时,父元素应该被验证。
发布于 2011-04-14 23:22:07
嵌套表单在HTML中是非法的,在JSF中也是如此,因为它所做的只是生成HTML。你需要把它们放在一起。
如果您有多个相同表单的按钮,并且您希望跳过某些按钮按下时的某些验证,那么可以向有问题的按钮添加immediate="true"。这样,所有没有 immediate="true"的输入域都将被跳过。
另请参阅:
更新:好的,您希望在一个表单中包含两个物理上分离的表单。如果将“上帝的形式”分成多个形式,每个形式都有自己的责任是不可行的,那么有几种方法可以解决这个问题:
如果您不使用Ajax,并且在输入元素上只有一个required="true",而您实际上希望在按下某个按钮时将其设置为非必需的,那么请执行以下操作:
<h:form>
...
<h:commandButton value="Submit form but but do not validate comment" />
...
<h:inputTextarea id="comment" required="#{not empty param[foo.clientId]}" immediate="true" />
<h:commandButton binding="#{foo}" value="Submit and validate comment" immediate="true" />
</h:form>如果您实际使用Ajax,那么只需在execute属性中指定执行区域即可。
<h:form>
<h:panelGroup id="other">
....
<h:commandButton value="Submit form but but do not validate comment">
<f:ajax execute="other" render="other" />
</h:commandButton>
</h:panelGroup>
<h:panelGroup id="comments">
<h:inputTextarea required="#{not empty param[foo.clientId]}" />
<h:commandButton value="Submit and validate comment by ajax">
<f:ajax execute="comments" render="comments" />
</h:commandButton>
</h:panelGroup>
</h:form>https://stackoverflow.com/questions/5665524
复制相似问题