如何在更改< p:selectOneMenu>时重置输入组件.在违反某些验证之后 [英] How to reset input components on change of <p:selectOneMenu> after certain validations are violated
问题描述
当加载JSF页面时,我正在从包含区域列表的数据库中填充<p:selectOneMenu>
.
I'm populating <p:selectOneMenu>
from a database which contains a list of zones, when a JSF page loaded.
当在该菜单中的区域被选择时,一组
When a zone in this menu is selected, a set of <p:inputText>
is displayed in which a user can insert charge that corresponds to product weight which is to be transferred by a transporter to the selected zone in the menu. This can be shown in the following snap shot.
可以看出,当用户输入非数字值时,如果按下给定的保存按钮<p:commandButton>
(每个文本字段顶部显示的数字与重量对应),就会发生验证冲突.
As can be seen, when non numeric values are entered by a user, validation violations occurs, when the given save button <p:commandButton>
is pressed (the numbers displayed on top of each text field correspond to weight).
如果用户现在在菜单(第一个面板)中更改区域,而没有按下重置按钮,则仅当重置按钮为按跟随(由于违反验证).
If a user now change the zone in the menu - the first panel without pressing the reset button, the data corresponds to that newly selected zone is loaded in these text fields only when the reset button is pressed as follows (because of validation violation)..
那么,如果在菜单中更改了项目(区域),那么在先前的验证冲突之后如何加载数据?
So, how to load data after previous validation violation, if an item (zone) is changed in the menu?
<p:selectOneMenu>
的change事件,在这种情况下,应该执行<p:resetInput>
完成的功能.
The change event of <p:selectOneMenu>
, in this case should do the function something like which is done by <p:resetInput>
.
希望您将能够理解我的意思:).
Hope you will be able to understand what I mean :).
推荐答案
基本上,您需要<p:selectOneMenu>
的<p:ajax>
内部的<p:resetInput>
提供的功能.这确实是不可能的,因为<p:resetInput>
需要放置在实现 UICommand
组件.
Basically, you need the functionality provided by <p:resetInput>
inside <p:ajax>
of a <p:selectOneMenu>
. This is indeed not possible as <p:resetInput>
requires being placed in a component implementing ActionSource
such as UICommand
components.
您最好的选择是让<p:remoteCommand>
接管<p:ajax>
更改侦听器作业.您可以在其中放置<p:resetInput>
.
Your best bet is to let <p:remoteCommand>
take over the <p:ajax>
change listener job. Therein you can put a <p:resetInput>
.
想象一下您当前有一个:
Imagine that you currently have a:
<h:form>
<p:selectOneMenu id="zone">
<f:selectItems ... />
<p:ajax listener="#{bean.changeZone}" update="data" />
</p:selectOneMenu>
<p:panel id="data">
...
</p:panel>
</h:form>
然后此更改应该执行:
<h:form>
<p:selectOneMenu id="zone" onchange="changeZone()">
<f:selectItems ... />
</p:selectOneMenu>
<p:remoteCommand name="changeZone" process="@this zone" action="#{bean.changeZone}" update="data">
<p:resetInput target="data" />
</p:remoteCommand>
<p:panel id="data">
...
</p:panel>
</h:form>
请不要忘记从侦听器方法中删除AjaxBehaviorEvent
参数.无论如何在这种情况下是没有用的.
Don't forget to remove the AjaxBehaviorEvent
argument from the listener method. It's useless in this particular case anyway.
这篇关于如何在更改< p:selectOneMenu>时重置输入组件.在违反某些验证之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!