| 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.
|
 |
 |
|
|
subject: relation between backing beans
|
|
|