跳过验证但仍保留提交的值
Skip validation but still keeps submitted values
我有这个屏幕攻略。客户和联系人是一对多关系。当用户点击 "Create contact person" 时,我想跳过 (A) 的验证,在 "Save" 联系人之后,应保留 (A) 中的输入值。
例如:
- 输入客户姓名"John"
- 点击"Create contact person",输入联系人
- "Save"。 "John" 应该再次显示
"Create" 按钮:
<h:commandLink class="btn"
action="#{contactPersonController.add()}"
styleClass="btn pull-right plusButton">
<i class="icon-plus"></i> #{msg.add}
<f:setPropertyActionListener target="#{contactPersonController.itemEditable}" value="#{addable}"></f:setPropertyActionListener>
</h:commandLink>
我试过了"immediate=true"。它跳过验证但不保留之前在 (A) 中提交的值。
有人说"f:ajax"但是我不知道怎么申请
解决方法是使用
<h:inputText id="customerName" styleClass=""
value="#{customerCreationController.customerDto.customerName}"
label="#{msg.customerName}" readonly="#{!customerCreationController.update and !customerCreationController.create}">
<f:validateRequired disabled="#{param.skipValidation}"/>
<f:validateLength maximum="#{shortStrLen}" disabled="#{param.skipValidation}"/>
</h:inputText>
<h:commandLink class="btn"
action="#{contactPersonController.add()}"
styleClass="btn pull-right plusButton">
<i class="icon-plus"></i> #{msg.add}
<f:param name="skipValidation" value="true"/>
<f:setPropertyActionListener target="#{contactPersonController.itemEditable}" value="#{addable}"></f:setPropertyActionListener>
</h:commandLink>
参考:Skip validation conditionally JSF
我有这个屏幕攻略。客户和联系人是一对多关系。当用户点击 "Create contact person" 时,我想跳过 (A) 的验证,在 "Save" 联系人之后,应保留 (A) 中的输入值。
例如:
- 输入客户姓名"John"
- 点击"Create contact person",输入联系人
- "Save"。 "John" 应该再次显示
"Create" 按钮:
<h:commandLink class="btn"
action="#{contactPersonController.add()}"
styleClass="btn pull-right plusButton">
<i class="icon-plus"></i> #{msg.add}
<f:setPropertyActionListener target="#{contactPersonController.itemEditable}" value="#{addable}"></f:setPropertyActionListener>
</h:commandLink>
我试过了"immediate=true"。它跳过验证但不保留之前在 (A) 中提交的值。
有人说"f:ajax"但是我不知道怎么申请
解决方法是使用
<h:inputText id="customerName" styleClass=""
value="#{customerCreationController.customerDto.customerName}"
label="#{msg.customerName}" readonly="#{!customerCreationController.update and !customerCreationController.create}">
<f:validateRequired disabled="#{param.skipValidation}"/>
<f:validateLength maximum="#{shortStrLen}" disabled="#{param.skipValidation}"/>
</h:inputText>
<h:commandLink class="btn"
action="#{contactPersonController.add()}"
styleClass="btn pull-right plusButton">
<i class="icon-plus"></i> #{msg.add}
<f:param name="skipValidation" value="true"/>
<f:setPropertyActionListener target="#{contactPersonController.itemEditable}" value="#{addable}"></f:setPropertyActionListener>
</h:commandLink>
参考:Skip validation conditionally JSF