This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSF and the fly likes relation between backing beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "relation between backing beans" Watch "relation between backing beans" New topic
Author

relation between backing beans

Manu dv
Greenhorn

Joined: Jun 30, 2010
Posts: 8
I have form which takes user name and password and populates it into a backing 'LoginBean'


On press of button "Login" another class LoginHandler is supposed to do processing on the instance of LoginBean.
It has a property to accept the 'LoginBean' instance:

How do I populate userInfo in LoginHandler class. Is it via <f:parm> tag in <h:commandButton> in the form or some other way?

soory if it is a noob question, I am just starting out with JSF.


It's better to burn out than to fade away
Shasi Mitra
Ranch Hand

Joined: Nov 27, 2008
Posts: 101

Hi - Is "loginBean" declared as managed bean in faces config? In that case, once you click login button, name and password values are populated in the bean.
Manu dv
Greenhorn

Joined: Jun 30, 2010
Posts: 8
Shasi Mitra wrote:Hi - Is "loginBean" declared as managed bean in faces config? In that case, once you click login button, name and password values are populated in the bean.

Yes, it is. And name & password were getting populated properly. I was not sure what was the standard way to retrive the instance of LoginBean from the session inside LoginHandler.doAuthentication().

I asked around and found that the way to do that is via FacesContext.getCurrentInstance().getExternalContext().
I tried this and it's working now.

Shasi Mitra
Ranch Hand

Joined: Nov 27, 2008
Posts: 101

Use this instead

<managed-bean>
<managed-bean-name>loginHandler </managed-bean-name>
<managed-bean-class>com.LoginHandler</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>loginBean</property-name>
<value>#{loginBean}</value>
</managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>LoginBean</managed-bean-name>
<managed-bean-class>com.LoginBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
Now you put setter for loginbean in your loginhandler and you can access it..When the instance of loginhanlder is created, login bean is injected to the loginhandler.
Manu dv
Greenhorn

Joined: Jun 30, 2010
Posts: 8
thanks Sashi. <managed-property> is the kind of thing I was looking for.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: relation between backing beans
 
Similar Threads
Injecting Beans as Parameters (Injected Bean reference is null)
javax.servlet.jsp.JspException: Not nested in a tag of proper type.
Javascript reset() method and JSF h:form
Run the MethodeBean & display the fields that corresponds to selectMenu
how to add a row dynamically in panel grid by clicking on command button using jsf