Can't get data from entity bean.
samwun9988 Feb 26, 2011 4:44 AMHello,
With JBOSS 6.0, JDK 1.6 and FreeBSD,
I have a single selected datatable list. When I click on it, my managed bean gets the entity " role", but the dialog is unable to get the value from the entity bean..
Here is my code for illustration:
Controller :
[quote]@ManagedBean(name="roleController")
//@SessionScoped
//@ViewScoped
public class RoleController //implements Serializable
{
@EJB
private RoleManager roleManager;
private Role selectedRole;
private String roleName;
private final static Logger logger = Logger.getLogger(RoleController.class.getName());
private ArrayList<Role> roleList;
public RoleController() {
logger.info("Invoke roleController contructor.");
roleList = null;
}
public void createRole() {
logger.info("Creating role "+getRoleName());
roleManager.createRoleFromName(getRoleName());
}
public Role getSelectedRole() {
return selectedRole;
}
[b]public void setSelectedRole(Role selectedRole) {
logger.info(" === selectedRole: " + selectedRole.getRoleId());
this.selectedRole = selectedRole;[/b]
}[/quote]
In the managed bean(controller) as shown above, whenever I click on a row, the setSelectedRole() method is get called, and the value of getRoleId() is returned correctly.
[quote]
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui">
<p:panel id="panel-edit" header="Edit Role" style="margin-bottom:10px;"
>
<h:panelGrid columns="5" cellpadding="4">
<h:outputText value="Role ID: " />
[b] <h:outputText value="#{roleController.selectedRole.roleId}" />[/b]
</h:panelGrid>
</p:panel>
</html>
[/quote]
In the above role_add.xhtml file, the roleId is always empty.
If I changed the line of outputText to the one shown as below:
<h:outputText value="#{roleController.selectedRole}" />
the role_edit.xhtml prints the address of the Role object:
au.com.houseware.wsdl.ix.generated.Role@cf2e58
Can anyone tell me what have the code missing or misconfigured?
Thanks
Sam