Why PostConstruct method is called several times inside an RichFaces 4.3 component with a ViewScoped?

倖福魔咒の 提交于 2019-12-08 13:34:41

问题


I 'm facing a problem with JSF 2.2, richfaces 4.3.2 on Tomcat 7 . My page is annoted ViewScoped. I display a first form. When i change the value and select a specific one , i display by ajax a rich:panel element inside an a4j:outputPanel. Inside this a4j:outputPanel and rich:panel component, i have a h:commandButton who execute the forms. I want to retrieve messages error for the form if the fields are empty for example (or other stuffs)

But when i click h:commandButton, the view is re instancied and @postcontruct method is re executed. It should be executed one time only in the view scope, am i wrong ?

I don't want the view to be reactualised, i want keep the ajaxoutputPanel displayed when i click the h:commandButton inside.(and i want to see the h:messages next to my forms fields...not much asking :-) )

I read about some bug... is there a way to change this behavior without passing to SessionScoped for example.

Thanks dudes.

    <fieldset>

    <h:form>

        <h:panelGrid columns="3">

            <h:outputText value ="Nom de l'étude : "></h:outputText> 
            <h:inputText id="study_name" value="#{analyse.study_name}"   size="20" required="true"  label="Nom de l'étude" />
            <h:message for="study_name" style="color:red" />

            <h:outputText value ="Analyse : "> </h:outputText> 
            <h:selectOneMenu  id = "analyse" value="#{analyse.analyse_type}">
            <f:selectItems value="#{analyse.analyse_type2Value}" />
                  <f:ajax execute="analyse" render=":ajaxOutputPanelAnalyse"  /> 
            </h:selectOneMenu>

         </h:panelGrid>

    </h:form>

</fieldset>

    <a4j:outputPanel id="ajaxOutputPanelAnalyse" layout="block" ajaxRendered="true"  >

    <rich:panel  id="richPanelAnalyse"  rendered="#{analyse.analyse_type == 'NGS' and request.isUserInRole('ROLE_ADMIN_PROFILER_NGS')}" >

        <h:form id ="NGS_form" >

            <h:panelGrid columns="4">

                <h:outputText value ="Run # :"> </h:outputText> 
                <h:inputText id="run_number" value="# {analyse.run_number}" size="20" required="true" label="Run" />
                <h:message for="run_number" style="color:red" />
                <h:outputText></h:outputText>


            </h:panelGrid>



                 <h:commandButton value="Submit" action="#{analyse.addAnalyse}"/>


            </h:form>

    </rich:panel>




  </a4j:outputPanel>

In the bean...

@PostConstruct
public void setFlashParam(){

    System.out.println("POST CONSTRUCT MON POTE");

    FacesContext facesContext = FacesContext.getCurrentInstance();


     return;
}

public String addAnalyse(){


    System.out.println("Kikou");

    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(" - Ajout de l'analyse ?"+" pour le patient ?"+" dans l'étude "+ study_name +" -"));


    return "pretty:home";

}

回答1:


Resolve thanks to this post from BalusC (as always) http://balusc.blogspot.fr/2011/09/communication-in-jsf-20.html#AjaxRenderingOfContentWhichContainsAnotherForm

EDIT : But it's no more working when you try to add an rich:fileupload neither with h:inputFile... It will displayed strange html code in a newly textarea when you click the button....It's weird...

           <rich:fileUpload  id="upload" fileUploadListener="#{analyse.test}"  acceptedTypes="bam,pdf,png" ontyperejected="alert('Seulement les fichiers avec l'extension bam et pdf sont acceptés.');" maxFilesQuantity="3">
                  <a4j:ajax event="uploadcomplete" execute="@none" render="upload" />        
            </rich:fileUpload>


来源:https://stackoverflow.com/questions/19793618/why-postconstruct-method-is-called-several-times-inside-an-richfaces-4-3-compone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!