Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

relation between backing beans

 
Manu dv
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Shasi Mitra
Ranch Hand
Posts: 101
Flex Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 101
Flex Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Sashi. <managed-property> is the kind of thing I was looking for.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic