2013-07-30 23 views
1

我知道很多人一直在討論這個話題,但所有的解決方案都指出要創建一個重置按鈕......是不是有辦法清除這些字段並重新填充它們?重置JSF表單域

這裏是我的代碼

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

這臺價值 '機' 在 'updateEntry',一旦完成啓動對話框 '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

+0

清除在託管bean值。 –

+0

更新對話框後,更新對話框中的對話框樹update =「:update_grid」,如果你不想讓他們看到更新的值,你可以隨時將bean的作用域更改爲requestScope –

回答

1

您在打開之前忘記了ajax-更新對話框的內容。這就是爲什麼它始終顯示初始內容的原因,就像第一次渲染頁面或最後一次關閉對話框時一樣。

這樣做相應:

<p:commandButton ... update=":Update_Entry"> 
+0

謝謝!雖然ajax更新需要在中完成...> –

+0

對不起,我在輸入答案時並沒有使用我的大腦。修復。 – BalusC