Problem with managed bean creation
rvaneperen Oct 5, 2010 8:03 PMI have been using Seam for a while, and this should be really easy, but I can't figure out what's going on. I begin on a page with a data table containing links in each row. That bean is Conversation scoped and the pages.xml contains
<page xmlns="http://jboss.com/products/seam/pages"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.1.xsd"
login-required="true">
<begin-conversation join="true"
flush-mode="MANUAL" />
<action execute="#{userRoleAdmin.init}"
on-postback="false" />
</page>I click this link (below), and proceed to the new view.
<s:link view="/UserRoleEdit.xhtml"
value="#{messages.global_edit}"
propagation="none"
id="userEdit" >
<f:param name="userRoleId"
value="#{userRole.id}" />
</s:link>Here is the pages.xml for the new view
<page xmlns="http://jboss.com/products/seam/pages"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.1.xsd"
no-conversation-view-id="/userList.xhtml"
login-required="true">
<begin-conversation join="true"
flush-mode="MANUAL" />
<action execute="#{userRoleEdit.init}"
on-postback="false" />
<navigation from-action="#{userRoleAdmin.storeUserRole}">
<rule if-outcome="added">
<redirect view-id="/UserRoleEdit.xhtml" />
</rule>
<rule if-outcome="updated">
<redirect view-id="/UserRoleEdit.xhtml" />
</rule>
<rule if-outcome="removed">
<redirect view-id="/UserRoleAdmin.xhtml" />
</rule>
</navigation>
</page>The init method is called which sets two properties on the bean - it fetches the UserRole from the Id parameter and initializes a list of options for the view. See below that userRole and availableAuths are populated (not null) as are Seam injected objects. I noticed in the debugger, that the object being managed at the point the init method completes is as follows (notice the id of the UserRoleEditBean)
this UserRoleEditBean (id=259) availableAuths ArrayList<E> (id=274) entityManager EntityManagerProxy (id=264) facesMessages FacesMessages (id=265) selectedAuths null userAuthNameConverter UserAuthorizationNameEnumConverter (id=266) userRole UserRole (id=271) userRoleId "251" (id=267) userRoleQuery UserRoleQuery_$$_javassist_seam_7 (id=268)
The next breakpoint is in the getter for the availableAuths list. When I hit that (which appears to be in the RenderView phase), both the userRole and availableAuths objects are null. And notice below that I now have a new object (a proxy)
this UserRoleEditBean_$$_javassist_seam_6 (id=302) availableAuths null entityManager null facesMessages null handler JavaBeanInterceptor (id=303) selectedAuths null userAuthNameConverter UserAuthorizationNameEnumConverter (id=304) userRole null userRoleId null userRoleQuery null
So why the new object, and why is everything null after being initialized in a Conversation scoped bean?
Here is the backing bean (I'd be glad to supply any more code you might need):
@Name( "userRoleAdmin" )
@Scope( ScopeType.CONVERSATION )
@AutoCreate
public class UserRoleAdminBean implements Serializable
{
/**
* For serialization.
*/
private static final long serialVersionUID = 2400901393261379751L;
/**
* Used to perform the search based on the role name.
*/
@In
private UserRoleSearchService userRoleSearchService;
/**
* The list of users as a result of searching.
*/
@DataModel
private List<UserRole> userRoles;
/**
* Used to search for authorizations.
*/
private String roleName;
/**
* Used to indicate whether the search should be exact or approximate.
*/
private boolean searchExact;
/**
* Tracks the current page for pagination of the authSearchResult table.
*/
private int roleSearchResultPage = 1;
/**
* Initializes the bean once upon creation.
*/
public void init()
{
this.roleName = "";
this.searchExact = false;
this.userRoles = new ArrayList<UserRole>();
}
/**
* Performs a search for User Roles based on the search criteria selected by the user.
*/
public void searchRoles()
{
this.userRoles = this.userRoleSearchService.searchUserRoles( this.roleName, this.searchExact );
}
/**
* Resets the authorization name used in the search.
*/
public void resetRoles()
{
this.roleName = "";
}
public List<UserRole> getUserRoles()
{
return this.userRoles;
}
public String getRoleName()
{
return this.roleName;
}
public void setRoleName( final String pRoleName )
{
this.roleName = pRoleName;
}
public final int getRoleSearchResultPage()
{
return this.roleSearchResultPage;
}
public final void setRoleSearchResultPage( final int pRoleSearchResultPage )
{
this.roleSearchResultPage = pRoleSearchResultPage;
}
public final boolean isSearchExact()
{
return this.searchExact;
}
public final void setSearchExact( final boolean pSearchExact )
{
this.searchExact = pSearchExact;
}
}