4

I meet a strange behavior with JSF 2.4 on Mojarra. I'm using flash parameters to pass from a page to another. Each time i arrive on a new page, i retrieve my flash parameters in Postconstruct annoted method. Then if the page is refreshed, the user is redirect to another page. (because the flash parameters are erased after refresh).

FOr the same code , i meet this error i if i populated my selectItems from different data (hard coded or database query) :

JSF1095: The response was already committed by the time we tried to set the outgoing cookie for the flash. Any values stored to the flash will not be available on the next request.

I d'like to get ride of this, maybe something to do with :

facesContext.responseComplete();
facesContext.renderResponse()

I don't understand how to use them.

I read about 2 :

<h:selectOneMenu id ="loc" value="#{participantController.localisation}"  
    validatorMessage="Vous devez renseigner la localisation."  >
     <f:selectItems value="#{participantController.locFeaturesList}"  
        var="locFeature"    itemLabel="#{locFeature.locName}" 
        itemValue="#{locFeature.locName}"  />
</h:selectOneMenu> 

My list object :

public static class LocFeatures{

    public String locName;
    public String codeName;

    public LocFeatures(String locName, String codeName){
        this.locName = locName;
        this.codeName = codeName;
    }

    public String getLocName(){
        return locName;
    }

    public String getCodeName(){
        return codeName;
    }

}

Put data in my list object :

    public LocFeatures[] loadLocalisationpAdicapCodeAssociativeMenu() {


        List <Static> loc2Code = staticBo.get(STATIC_CATEGORY_PARTICIPANT_LOCALISATION_CODE);

        locFeaturesList    = new LocFeatures[loc2Code.size()+1];



                     // if I populate my list with only some values no errors will be thrown but it doesn't work when i populate it by a big database request
                    //locFeaturesList    = new LocFeatures[1];

        locFeaturesList[0] = new LocFeatures("-----",null); // Associations Classe - Name 

        int indice = 1;
        for (Static assocation : loc2Code) {

            locFeaturesList[indice] = new LocFeatures(assocation.getKey(),assocation.getValue()); // Associations Classe - Name 

            indice ++;   
        }

        return locFeaturesList;
    }

My @PostConstruct method :

    @PostConstruct
    public void setFlashParam() {

        //locFeaturesList = loadLocalisationpAdicapCodeAssociativeMenu();


        FacesContext facesContext = FacesContext.getCurrentInstance();

        String studyNameFlashed = (String) facesContext.getExternalContext().getFlash().get("study_name");


        // Gere un refresh qui ferait disparaitre le type de l'étude.
        if (studyNameFlashed == null)  { 

            try {   ExternalContext ec = facesContext.getExternalContext(); ec.redirect(ec.getRequestContextPath() + "/Accueil"); } catch (IOException e) {e.printStackTrace();}
            return;
        }

         return;
    }
Community
  • 1
  • 1
ZheFrench
  • 1,164
  • 3
  • 22
  • 46

1 Answers1

2

Try always to go with Mojarra latest versions to work with flash. In your case, try to update it to 2.2.6. As stated in several posts around here, there have been a lot of issues with flash scope in Mojarra implementations. However, it seems they've fixed the problem. See this answer (which BTW explains how to use the context properly).

See also:

Community
  • 1
  • 1
Aritz
  • 30,971
  • 16
  • 136
  • 217
  • I moved to 2.2.6 today. Still the same warning. I knowned Flash Scope was buggy...but i had hope :) Most of my lastest erros disappeared with the news release since 2.2.4, 2.2.1 was a nightmare for flash now it seems to be of for me, except the warning i reported.Thanks – ZheFrench Mar 23 '14 at 11:31
  • The warning basically is telling you won't be available to use flash in the next request. So it completelly breaks its functionality :-( Try clearing your browser cookies or using another browser to see if problem persists. – Aritz Mar 23 '14 at 11:39
  • Same problem with Mozilla FireFox and Chrome. Not Tried with IE but you know what i mean ^^ Well BTW i'am on TOmcat 7. I remember to have read somewhere about bufferSize limited to 2kb i don't know if there is a link. Because the warning comes when there is an heavy load. For one value populated in the list preload in method @PostConstruct no warning are throws. I can do the query without populating my list variable and the is no error. It's only when i put values retrieved from db in the list used by the selectOneMenu. Strange. – ZheFrench Mar 23 '14 at 11:55
  • 1
    Are you interacting with flash scope in any getter/setter method that is referenced from the view? That could cause the problem. You need to deal with the scope either in `@PostConstruct` or `preRenderView` methods. Using it in getter/setters might be too late... – Aritz Mar 23 '14 at 12:01
  • What do you suggest ? I'm not sure to follow. I m calling in a PostConstruct Method locFeaturesList = loadLocalisationpAdicapCodeAssociativeMenu(); to get the values to be displayed in I call the getter for locFeaturesList from the view in selectItems yeah , is that wrong? – ZheFrench Mar 23 '14 at 12:08
  • I suggest you testing the code given in the answer's quoted post. Try it in your project and see if you've got the same issue. Apart from that, your provided code isn't testable by me, so I can't reproduce the situation. Try to post it in a SSCCE form. – Aritz Mar 23 '14 at 14:44