在JSF 2中,h:button和之间有什么区别h:commandButton?
我在一个字段上有一个带验证器的表单.我有两个h:commandButtons:Ok和Cancel.当我输入错误的数据并单击取消时,我会收到验证消息.当我点击取消时,我必须做什么验证器不运行?
在一个表单中,我有一些带有两个commandButton的inputText,一个用于accept,一个用于cancel.如何仅对取消按钮禁用验证?
<h:form id="detailsForm">
<p:inputText id="editUsername" value="#{userController.editUser.usrUsername}" />
<p:inputText id="editFirstName" value="#{userController.editUser.usrFirstName}" />
<p:inputText id="editLastName" value="#{userController.editUser.usrLastName}" />
<p:commandButton value="Accept" update=":detailsForm" actionListener="#{userController.onDetailsEditAccept}" />
<p:commandButton value="Cancel" update=":detailsForm" actionListener="#{userController.onDetailsEditCancel}" />
</h:form>
Run Code Online (Sandbox Code Playgroud)
我已经尝试required="false"在字段上插入但它没有用.我也尝试<f:validateBean disabled="true" />在字段上插入但它没有用.
在视图范围内的托管bean中,我<p:resetInput>用来清除相应的manged bean中属性所持有的值,比如
<p:commandButton value="Reset" update="panel" process="@this">
<p:resetInput target="panel" />
</p:commandButton>
Run Code Online (Sandbox Code Playgroud)
这很好用.
我有一个提交按钮<p:commandButton>,按下该按钮会导致提交的值插入到数据库中,如果验证成功.
<p:remoteCommand name="updateTable" update="dataTable"/>
<p:panel id="panel" header="New">
<p:outputLabel for="property1" value="property1"/>
<p:inputText id="property1" value="#{bean.property1}" required="true">
<f:validateLength minimum="2" maximum="100"/>
</p:inputText>
<p:message for="property1" showSummary="false"/>
<p:commandButton id="btnSubmit"
update="panel messages"
oncomplete="if(!args.validationFailed) {updateTable();}"
actionListener="#{bean.insert}"
value="Save"/>
<p:commandButton value="Reset" update="panel" process="@this">
<p:resetInput target="panel" />
</p:commandButton>
</p:panel>
Run Code Online (Sandbox Code Playgroud)
命令按钮调用insert()托管bean中的方法,该方法定义如下.
public void insert() {
if (service.insert(property1)) {
//...Popup a success message.
reset(); //Invoke the following private method.
} else {
//...Show the cause of …Run Code Online (Sandbox Code Playgroud)