Creating a Managed Bean
Hi,
I am using JSF, ADF, JDeveloper and Oracle 10g Database.
I have a jsp called login.jsp - this has a form that where the agent enters their username.
<h:form>
<af:inputText id="agentName" label="Agent Name" value="#{loginBean.username}"/>
<af:commandButton action="#{loginBean.login}" text="Login"/>
</h:form>
When the user presses the command button, the loginbean.login( ) method is called.
public String login(){
AgentBean agent =new AgentBean();
AgentService agentService =new AgentService();
System.out.println("UN"+username);
agent = agentService.loginAgent(username);
if(agent ==null){
return"fail";
}
else{
return"success";
}
}
The agent = agentService.loginAgent(username);
gets an instance of the AgentBean which is populated with data retrieved from the database in AgentBeanDAO class.
My question is... Is the way I create the AgentBean correct? When I try to reference it using
FacesContext facesContext = FacesContext.getCurrentInstance();
ValueBinding valueBinding = facesContext.getApplication().createValueBinding("#{agentBean}");
AgentBean agent = (AgentBean) valueBinding.getValue(facesContext);
it is null. I am referencing it in EmployeeBean to get the employee details based on their ID.
My faces-config.xml is...
<managed-bean>
<managed-bean-name>employeeBean</managed-bean-name>
<managed-bean-class>uk.co.rias.bean.EmployeeBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>agentBean</property-name>
<property-class>uk.co.rias.bean.AgentBean</property-class>
<value>#{agentBean}</value>
</managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>agentBean</managed-bean-name>
<managed-bean-class>uk.co.rias.bean.AgentBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>loginBean</managed-bean-name>
<managed-bean-class>uk.co.rias.bean.LoginBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
In conclusion, I suppose my questions are:
1. Do I create the bean in the right place
2. Do I need to create the bean withnew MyBean()
3. Am I referencing the bean correctly in EmployeeBean
Any help would be much appreciated. I have scoured the forum looking for an answer but to no avail.
I think I have included everything necessary for an answer, but if you require any more info, please ask and I'll provide it.
Many Thanks,
John

