0

I'm trying to rest all inputValues for JSF prime faces:

I have some InputFields and some select menus, menus are working ok after hit SAVE button, but input values not cleared

I don't wanna to use spearat button, I want to make it automatic just after hit save then reset all input fields:

HTML code :

    </h:form>       
                        <center>
            <h:form id="form" style="width: 600px; text-align: center;">

            <p:panel id="panel" header="اضافه طالب غائب">
                <p:growl id="msgs" showDetail="true" />
                    <p:panelGrid columns="2">


                       <h:outputLabel value="رقم المعلم:" />
                        <p:inputText label="رقم المعلم" required="true"
                        requiredMessage="Contact Number required!"
                        style="width: 150px; text-align: center;"
                        value="#{pprBean.teacherid}"/>                  





                <h:outputLabel  value="اختر الفصل" />

<p:selectOneMenu id="city20" value="#{pprBean.classname}" style="text-align:center;"> 
                <f:selectItem itemLabel="اختر الفصل" itemValue="" style="text-align:center;" />  
                <f:selectItems value="#{pprBean.clasess}" style="text-align:center;" />     
                <p:ajax update="city21"  
                        listener="#{pprBean.handleclassnameChange}" /> 
            </p:selectOneMenu>          


                        <h:outputLabel  value="اختر الطالب" />
                                    <p:selectOneMenu id="city21" value="#{pprBean.names}" style="width:140px; text-align:center;"> 
                <f:selectItem itemLabel="اسم الطالب" itemValue="" style="text-align:center;" />  
                <f:selectItems value="#{pprBean.studentnames}" style="text-align:center;" />     
                <p:ajax update="" listener="#{pprBean.handlenamesChange}" />  
            </p:selectOneMenu> 


                            <h:outputText value="الفتره من " />
                            <p:calendar value="#{pprBean.from}" showButtonPanel="true"
                                pattern="yyyy-MM-dd" 
                                style="width: 200px; text-align: center;" />

<h:outputLabel  value="الحصة" />
<p:selectOneMenu id="city1" value="#{pprBean.interval}" style="width:140px; text-align:center;">  
                <f:selectItem itemLabel="اختر الحصة" itemValue="" style="width:140px; text-align:center;" />  
                <f:selectItems value="#{pprBean.intervals}" style="width:140px; text-align:center;" />     
                <p:ajax update=""  
                        listener="#{pprBean.handleintervalChange}" />  
            </p:selectOneMenu>  


<h:outputLabel value="الحالة" />
<p:selectOneMenu id="city3" value="#{pprBean.appsent}" style="text-align:left;">  
                <f:selectItem itemLabel="حالة لغياب" itemValue="" style="text-align:left;"/>  
                <f:selectItems value="#{pprBean.apssents}" style="text-align:left;" />     
                <p:ajax update=""  
                        listener="#{pprBean.handleappsentChange}" />  
            </p:selectOneMenu> 

                    </p:panelGrid>
                    </p:panel>
                    <p:commandButton action="#{pprBean.insert}"
                            value="ادخال" update="form"/>


            </h:form>

        <p:ajaxStatus style="width:64px;height:64px;position:fixed;right:5px;bottom:5px">  
    <f:facet name="start">  
        <p:graphicImage value="/css/loading.gif" />  
    </f:facet> 


    <f:facet name="complete" process="@this" type="org.primefaces.examples.view.CleanLocalValuesListener"> 

        <h:outputText value="" />  
    </f:facet>  
</p:ajaxStatus>
            </center>
            <br />  
            <br />  
        </ui:define>
    </ui:composition>
</h:body> 

code :

    public void reset() {  
    RequestContext.getCurrentInstance().reset("form:panel"); 
    teacherid=null;
    classname=null;
    interval=null;
    studentcode=null;
    names=null;
    from=null;
} 
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

1 Answers1

0

Try using the preRenderView event of JSF and call a Bean function :

<f:metadata>
  <f:event type="preRenderView" listener="#{rBean.resetValues}"/>
</f:metadata>

As in the above example the resetValues function of rBean will be called on every page load.And in this function you can reset all your bean variables as following:

public void resetValues()
{

    setName(null);
    setAddress(null);
    .
    .
    .

}
Haseeb Anser
  • 494
  • 1
  • 5
  • 19