How to reset input components on change of

after certain validations are violated

前端 未结 1 1859
深忆病人
深忆病人 2021-01-20 03:23

I\'m populating from a database which contains a list of zones, when a JSF page loaded.

When a zone in this menu is selected, a

相关标签:
1条回答
  • 2021-01-20 03:48

    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.

    0 讨论(0)
提交回复
热议问题