How to reset input components on change of <p:selectOneMenu> after certain validations are violated

ⅰ亾dé卋堺 提交于 2019-12-01 22:39:22

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.

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>

Then this change should do:

<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>

Don't forget to remove the AjaxBehaviorEvent argument from the listener method. It's useless in this particular case anyway.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!