Reset the value of an input text

UI Components for JSF
Post Reply
cloud4288
Posts: 24
Joined: 16 Jun 2011, 11:10

17 Jun 2011, 04:10

Hi guys, I have a dialog box that accepts input, but the value of the textfield does not reset after closing the dialog box, once the dialog box is shown again the previous value is shown.

Here's the code:

Code: Select all

            <h:form>
                <p:commandButton onclick="dialog.show()"
                                 value="Show Dialog"/>
            </h:form>

            <h:form>
                <p:dialog visible="false"
                          widgetVar="dialog">
                    <h:panelGrid columns="1">
                        <p:inputText value="#{user.name}"/>
                        <p:commandButton update="output"
                                         value="Greet me!"/>
                    </h:panelGrid>
                    <h:outputText id="output" value="Hello #{user.name}!"/>
                </p:dialog>
            </h:form>

Code: Select all

import javax.faces.bean.ManagedBean;

@ManagedBean
public class User {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
Netbeans 6.9.1 | PrimeFaces 2.2.1 | Oracle Glassfish 3.1

Regards,
Philip

cloud4288
Posts: 24
Joined: 16 Jun 2011, 11:10

22 Jun 2011, 07:21

Hi guys, I searched the forum and found the solution.

http://primefaces.prime.com.tr/forum/vi ... f=3&t=5737

I just needed to update the form by referencing the panelGrid and the form.

Code: Select all

           <h:form>
                <p:commandButton onclick="dialog.show()"
                                 update="dialogForm:panelData"
                                 value="Show Dialog"/>
            </h:form>

            <h:form id="dialogForm">
                <p:dialog visible="false"
                          widgetVar="dialog">
                    <h:panelGrid id="panelData"
                                 columns="1">
                        <p:inputText value="#{user.name}"/>
                        <p:commandButton update="output"
                                         value="Greet me!"/>
                    </h:panelGrid>
                    <h:outputText id="output" value="Hello #{user.name}!"/>
                </p:dialog>
            </h:form>
Fixed my problem. :D

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 45 guests