重置JSF表单字段

问题描述 投票:1回答:1

我知道有关此主题的事情很多,但是所有解决方案都指出要创建一个重置按钮...难道不能只是清除字段并重新填充它们吗?

这是我的代码

<p:commandButton id="basic" value="#{c.machine}" action="#{updateEntry.setMachine(c.machine)}" oncomplete="dlg1.show();" styleClass="ui-Machinebutton"/>

这将在'updateEntry'中设置值'machine',并在完成后启动对话框'dlg1'

对话框

<p:dialog id="Update_Entry" header="Update Entry" widgetVar="dlg1" modal="true" height="250" dynamic="True" resizable="False">  
                    <h:form prependId="false" id="Update_Entry_Form" method="post" autocomplete="off">  

                            <h:panelGrid id="update_grid" columns="2" style="margin-bottom:10px"> 

                                <f:facet name="header">  
                                    <p:messages />  
                                </f:facet> 
                                <h:outputLabel for="machine" value="Machine *" />  
                                <p:inputText id="machine" value="#{updateEntry.machine}" required="true" requiredMessage="Machine is required">
                                    <f:validateLength minimum="5" maximum="5"/>
                                </p:inputText>

表单第一次加载该值很好,但是即使updateEntry.machine被更新,它也总是加载先前的值。我如何自动清除此问题?我正在使用PrimeFaces

forms jsf
1个回答
1
投票

您忘了在打开对话框之前Ajax更新对话框的内容。这就是为什么它总是显示初始内容的原因,就像第一次呈现页面时或最后一次关闭对话框时一样。

相应地这样做:

<p:commandButton ... update=":Update_Entry">
© www.soinside.com 2019 - 2024. All rights reserved.