Tin*_*iny 3 jsf primefaces jsf-2
在视图范围内的托管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 the failure.
}
}
private void reset() {
property1 = null; //Set this property of type String to null.
}
Run Code Online (Sandbox Code Playgroud)
如果reset()省略此方法,则<p:inputText>不会被清除,但如果我按下XHTML中所示的重置按钮,则<p:inputText>应该清除但不会.
在展示例子说明了同样的事情.因此,这种行为似乎有文件记载但我不明白为什么不<p:resetInut>清除值property1,如果reset()方法被省略,在这种情况下?
在<p:resetInput>你错误地似乎都期望不清除的模型值.它只是清除输入组件的状态,在验证错误后它可能是脏的.
它试图解决的具体问题在这个答案中详细描述:如何在验证错误发生后使用PrimeFaces AJAX填充文本字段?
以下用例最能理解这一点:
把<p:resetInput>在"打开对话框"按钮,对话框的形式与目标修复它.
我不确定您的特定案例是否<p:resetInput>是正确的解决方案.您的代码不完整,并且您没有在任何地方说明此代码背后的具体功能要求,但据我所知,没有多个输入/表单需要相互更新.我相信即使你删除你的案子仍然有效<p:resetInput>.因此,在您的上下文中它将是完全超级的,您可以放弃清除模型(或者只是通过同步GET按钮刷新页面,隐式重新创建视图).
| 归档时间: |
|
| 查看次数: |
5612 次 |
| 最近记录: |