Primefaces 滑块不会重置为 0
Primefaces slider won't reset to 0
我有一个带有滑块和重置按钮的 JSF 表单 :
<div class="field">
<p:outputLabel for="amount" value="Amount" />
<h:panelGrid columns="1" style="margin-bottom: 10px" id="amount">
<p:inputText id="slider" value="#{myBean.myBo.amount}" />
<p:slider for="slider" maxValue="20" />
</h:panelGrid>
</div>
<h:commandButton value="Reset" type="reset" action="#{myBean.reset}" update="form" process="@this" class="button"></h:commandButton>
重置函数如下所示:
public void reset() {
RequestContext.getCurrentInstance().reset("form:form");
this.registrationFormBo.clear();
}
重置滑块时,其输出如下所示:
p:inputText
具有正确的值,而在此示例中滑块本身具有值 9。
问题
滑块不会重置,而值会重置。
解决方案
我使用 Primefaces p:resetInput
解决了这个问题。重置按钮的最终 html 如下所示:
<p:commandButton value="Reset" update="registrationForm" process="@this" >
<p:resetInput target="registrationForm" />
</p:commandButton>
这会正确重置滑块和表单中的所有其他元素。
我有一个带有滑块和重置按钮的 JSF 表单 :
<div class="field">
<p:outputLabel for="amount" value="Amount" />
<h:panelGrid columns="1" style="margin-bottom: 10px" id="amount">
<p:inputText id="slider" value="#{myBean.myBo.amount}" />
<p:slider for="slider" maxValue="20" />
</h:panelGrid>
</div>
<h:commandButton value="Reset" type="reset" action="#{myBean.reset}" update="form" process="@this" class="button"></h:commandButton>
重置函数如下所示:
public void reset() {
RequestContext.getCurrentInstance().reset("form:form");
this.registrationFormBo.clear();
}
重置滑块时,其输出如下所示:
p:inputText
具有正确的值,而在此示例中滑块本身具有值 9。
问题
滑块不会重置,而值会重置。
解决方案
我使用 Primefaces p:resetInput
解决了这个问题。重置按钮的最终 html 如下所示:
<p:commandButton value="Reset" update="registrationForm" process="@this" >
<p:resetInput target="registrationForm" />
</p:commandButton>
这会正确重置滑块和表单中的所有其他元素。