表格中的表格:跳过对父表格的验证

|
<h:form prependId=\"false\" id=\"parentForm\">
    ...
    <h:form prependId=\"false\" id=\"commentForm\">
        ...
        add comment
    </h:form>
    save
</h:form>
不起作用... 如果没有内部表单,当我只想添加评论时,父元素会被验证。 \“添加注释\”应该只验证注释,而单击\“保存\”则应该验证父对象。     
已邀请:
嵌套表单在HTML中是非法的,在JSF中也是如此,因为它所做的只是生成HTML。您需要将它们彼此相邻。 如果您有多个具有相同形式的按钮,而您希望在某些按钮按下时跳过某些验证,请在有问题的按钮上添加“ 1”。这样,所有不具有“ 1”的输入字段都将被跳过。 也可以看看:
immediate
属性有什么用? 更新:好的,您希望在一个表单中包含两个物理上分开的表单。如果不能以各自的责任将“上帝形式”分成多种形式,那么有几种解决方法: 如果您不使用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>
    

要回复问题请先登录注册