Need help with setting a Session property
abafna.bafna.amit.gmail.com Feb 11, 2009 1:57 AMHi All,
I am trying to set a property for entire user session. The property is available as a drop down from the top of the web page, giving the user capability to change the property anytime. The drop down values are displayed fine but I am unable to change the property. Here is the code:
components.xml
<framework:entity-query name="sessionLocationsQuery" scope="SESSION" ejbql="select l from Location l" order="l.name"/> <factory name="sessionLocations" value="#{sessionLocationsQuery.resultList}" scope="SESSION"/>
XHTML code
<h:form id="sessionLocationForm"> <s:decorate id="sessionLocationDecoration" template="edit.xhtml" rendered="#{identity.loggedIn}"> <ui:define name="label">Session Location</ui:define> <h:selectOneMenu id="sessionLocationDropDown" value="#{locationSelection.location}"> <s:convertEntity /> <s:selectItems var="location" value="#{sessionLocations}" label="#{location.name}" /> <a4j:support ajaxSingle="true" event="onchange"/> </h:selectOneMenu> </s:decorate> </h:form>
Session Bean
@Stateful @Name("locationSelection") @Scope(ScopeType.SESSION) @Startup public class LocationSelectionBean implements LocationSelectionLocal { @Logger private Log log; @Create public void create() { log.debug("Created"); } @Destroy @Remove public void destroy() { log.debug("Destroyed"); } @In private Identity identity; @In private EntityManager entityManager; @In (create=true) private List<Location> sessionLocations; private Location location; public Location getLocation() { if (location == null) { this.location = sessionLocations.get(0); } return this.client; } public void setLocation(Location location) { this.location = location; } }
When I try to select an alternate location, the value is not updated in the session bean and the log reports following error:
16:38:21,998 INFO [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed. sourceId=sessionClientForm:sessionClientDecoration:sessionClientDropDown[severity=(ERROR 2), summary=(value is not valid), detail=(value is not valid)]
I even tried to change the scope of EntityConverter to SESSION as follows:
<component name="myEntityConverter" class="org.jboss.seam.ui.converter.EntityConverter" scope="SESSION"/>
and changed the XHTML code as follows:
<h:form id="sessionLocationForm"> <s:decorate id="sessionLocationDecoration" template="edit.xhtml" rendered="#{identity.loggedIn}"> <ui:define name="label">Session Location</ui:define> <h:selectOneMenu id="sessionLocationDropDown" value="#{locationSelection.location}"> <f:converter converterId="myEntityConverter"/> <s:selectItems var="location" value="#{sessionLocations}" label="#{location.name}" /> <a4j:support ajaxSingle="true" event="onchange"/> </h:selectOneMenu> </s:decorate> </h:form>
Still got the same error.
What am I missing? Any pointers will be appreciated.
Thanks
Amit