Jsf 2 如何重置primefaces commandButton重置类型上的下拉列表

Jsf 2 如何重置primefaces commandButton重置类型上的下拉列表,jsf-2,primefaces,Jsf 2,Primefaces,如何在键入reset时按p:commandButton重置p:selectOneMenu的值。我的代码如下 <h:form id="form"> <p:panelGrid columns="2" cellspacing="10" > <f:facet name="header">Login</f:facet> <p:outputLabel value="Username" /> <p:inputT

如何在键入reset时按p:commandButton重置p:selectOneMenu的值。我的代码如下

<h:form id="form">

    <p:panelGrid columns="2" cellspacing="10" >
    <f:facet name="header">Login</f:facet>
    <p:outputLabel value="Username" />
    <p:inputText value="#{user.username}" />
    <p:outputLabel value="Password" />
    <p:password value="#{user.password}"></p:password>

    <p:outputLabel value="Locale" />
    <p:selectOneMenu >
    <f:selectItem itemValue="Select Country" itemLabel="Select Country" />
    <f:selectItem itemValue="Poland" itemLabel="Poland"/>
    </p:selectOneMenu>
    <p:commandButton value="Submit"></p:commandButton>
    <p:commandButton type="reset" value="Clear" update="form"></p:commandButton>
    </p:panelGrid>

</h:form>

登录

执行此操作时,用户名和密码将被清除,但选择国家/地区的下拉列表不会重置。

首先,您只是在
p:selectOneMenu
中显示值,但不分配这些值,
value
属性可以将当前选定的值从客户端分配到支持bean值中,所以,

<p:selectOneMenu id="myMenu" value="#{bean.selectedCountry}">
    <f:selectItem itemValue="Select Country" itemLabel="Select Country" />
    <f:selectItem itemValue="Poland" itemLabel="Poland"/>
</p:selectOneMenu>
和js函数:

function resetter() {
    document.getElementById('form:myMenu_label').innerHTML = 'Select Country';
}
function resetter() {
    document.getElementById('form:myMenu_label').innerHTML = 'Select Country';
}