how to clean the fields of a form in jsf?

0

Hi, I have my form in jsf with primefaces what I want to know is how to clean the data once I fill them and I gave in submit button because if I go back in, it paints me the data that I had already entered, I do not know if it is from the view or if I have to create a method and then as I send it to call in the view?

[! [It's this part of my form] [1]] [1]

<p:fieldset legend="#{datospersonalesmsgs['datospersonales.title']}" toggleable="true" toggleSpeed="500">
                <h:panelGrid columns="5" width="100%" > 
                    <h:panelGrid columns="3" width="100%">
                        <!--CURP-->
                        <h:outputText value="#{datospersonalesmsgs['datospersonales.curp.title']}:*" />
                        <p:inputText id="datospersonales_curp" value="#{DatosPersonalesComponent.datospersonales.curp}" required="true"  label="datospersonales_curp"
                                    readonly="readonly" maxlength="18"  onblur="javascript:this.value = this.value.toUpperCase();"/>
                    </h:panelGrid>
                    <h:panelGrid columns="3" width="100%">
                        <!--NOMBRES-->
                        <h:outputText value="#{datospersonalesmsgs['datospersonales.nombre.title']}:*" />
                        <p:inputText id="datospersonales_nombre" value="#{DatosPersonalesComponent.datospersonales.nombre}" required="true"  label="datospersonales_nombre" 
                                     readonly="readonly" onblur="javascript:this.value = this.value.toUpperCase();"/>
                    </h:panelGrid>
                    <h:panelGrid columns="3" width="100%">
                        <!--Primer Apelldo-->
                        <h:outputText value="#{datospersonalesmsgs['datospersonales.apellido.title']}:*" />
                        <p:inputText id="datospersonales_apellido" value="#{DatosPersonalesComponent.datospersonales.apellido}" required="true" label="datospersonales_apellido"
                                   readonly="readonly"  onblur="javascript:this.value = this.value.toUpperCase();"/>
                    </h:panelGrid>
    
asked by Root93 09.11.2017 в 17:22
source

1 answer

1

You have to do it on the backend side, first you have to add a widgetVar attribute to the <p:fieldset> tag, this you will use to update the tag after doing the submit operation:

<p:fieldset widgetVar="datosPersonalesFieldSet" legend="#{datospersonalesmsgs['datospersonales.title']}" toggleable="true" toggleSpeed="500">

Your submit button should look something like this:

<p:commandButton action="#{datosPersonalesComponent.submitOperation()}" update="datosPersonalesFieldSet"/>

The action attribute must call the function you want to send when the submit is done, and the update parameter must match the widgetVar parameter of the tag that contains the form data, in this case datosPersonalesFieldSet .

And in your component DatosPersonalesComponent you must create a method to clean your fields and call it from the method that you invoke when you click on the button in this case from the method submitOperation ():

public submitOperation(){
   //logica del método
   clearFields():
}

private void clearFields(){
    //limpiar campos necesarios del objeto datospersonales
}
    
answered by 09.11.2017 в 20:38