0

I am using a <h:selectOneMenu> to send a state value to the backing bean. When I click on the <h:commandLink> the value is being picked up in the bean correctly (in the log.debug message). However, when the page reloads, the selected State is lost and the one at the top (NY) appears in the UI. Shouldn't the value of the one selected be retained? Any suggestions much appreciated.

I am using JSF 1.2.

JSP:

<h:selectOneMenu id="state" value="#{stateBean.stateName}"> 
    <f:selectItem itemValue="NY" itemLabel="New York" />
    <f:selectItem itemValue="CA" itemLabel="California" />
    <f:selectItem itemValue="NE" itemLabel="Nebraska" />
    <f:selectItem itemValue="AK" itemLabel="Alaska" />
</h:selectOneMenu>

<h:commandLink action="#{stateBean.sendStateAction}">

Managed Bean:

private String stateName;

log.debug("state name: " + stateName);

public String getStateName() {
    return stateName;
}
public void setStateName(String name) {
    this.stateName = name;
}
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
ChrisF
  • 25
  • 7

1 Answers1

1

Probably your managed bean is configured to be as request scope. If you change it to session scope the bean will be available while the user session is still alive. Since JSF 1.2 doesn't have a view scope, you could try to save the data in session and recover it in the constructor of your bean or use a third party library that handles this. More info: JSF 1.2: How to keep request scoped managed bean alive across postbacks on same view? I have used RichFaces @KeepAlive and worked for my work.

Community
  • 1
  • 1
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • Thanks Luiggi. Do you happen to have an example of how I would set the selected value in a session variable, recover it in the constructor of my bean, and display that in my h:selectOneMenu? Thanks! – ChrisF Jun 23 '13 at 23:06
  • @ChristopherFrankland refer to http://stackoverflow.com/q/772541/1065197 to access to the HttpSession inside a JSF managed bean. – Luiggi Mendoza Jun 23 '13 at 23:50