Postback and statefule sessionbean instances
bcdtech Mar 5, 2008 5:12 PMI have the following classes:
// package and imports removed @Local public interface StationLocal { public void destroy(); public void setLookupString(String lookupString); public String getLookupString(); public String save(); public void setStation(Station station); public Station getStation(); public String find(); }
and
// package and imports removed @Stateful @Scope(ScopeType.SESSION) @Name("stationManager") @Restrict("#{identity.loggedIn}") public class StationBean implements StationLocal { @PersistenceContext(type = PersistenceContextType.EXTENDED) private EntityManager em; private String lookupString; @In(required = false) @Out(required = false) private Station station; public String find() { if (getLookupString() != null) { try { Query q = em.createNamedQuery("Station.findByStationName"); q.setParameter("stationName", getLookupString()); station = (Station) q.getSingleResult(); } catch (Exception e) { station = new Station(); } } else { station = new Station(); } return "/station.xhtml"; } public String save() { System.out.println(station.getId()); System.out.println(station.getStationName()); //em.merge(station); station = new Station(); setLookupString(""); return "/station.xhtml"; } public void setLookupString(String lookupString) { this.lookupString = lookupString; } public String getLookupString() { return lookupString; } public void setStation(Station station) { this.station = station; } public Station getStation() { return station; } @Remove public void destroy() { } }
then I have the following xhtml file:
<ui:define name="body"> <h:messages globalOnly="true" styleClass="message"/> <h:form id="station"> <rich:panel> <f:facet name="header">Station Edit</f:facet> <ui:define name="label">Station Name</ui:define> <h:inputText id="lookupString" required="true" value="#{stationManager.lookupString}"/> <a:commandButton id="findStation" value="Lookup Station" action="#{stationManager.find}"/> <hr/> <table> <tr> <td> <h:outputText value="Channel" /> </td> <td> <h:inputText value="#{station.channel}" /> </td> </tr> <tr> <td> <h:outputText value="PI Cost" /> </td> <td> <h:inputText value="#{station.piCost}" /> </td> </tr> </table> </rich:panel> </h:form> </ui:define>
What I want to do is have the user lookup a station (radio or tv) by typing 'FOX', 'ABC' or other code, clicking the lookup button (this works) and then only showing the Channel and Advertising Cost (PI Cost) fields on the view. These are the only 2 fields they should be modifying.
With my current setup/code the values for station.id and station.stationName are null after the user clicks save, yet I have defined the station entity bean in session scope.
What am I missing?
Thanks
Brent