I have  a class that looks like this:

public class UserBean extends BaseBean { 
 private String username;
  private Long userId;
  private Center center;
  private String phone;
  private Contractor contractor;
  private String project;
  private boolean userContractor;
  private String contractNumber;
   
   ... getter/setter methods and business methods...

and a corresponding User class that looks pretty much the same as the
UserBean class.

The UserBean's properties are all saved into an actual User object by a
saveAction method.

I'd like to be able to set the UserBean's center.centerId property so that
when the properties are copied the center object is copied as well.

In my JSP I have:

        <h:selectOneMenu id="center" value="#{userBean.center.centerId}">
          <f:selectItems value="#{applicationBean.centerSelectItems}"/>
        </h:selectOneMenu>

However it seems that center is always null so I am getting an error, what
is the proper way to ensure that center has been instantiated before the
page is rendered?

I have tried: 
  private Center center = new Center();

but this produces the error:

net.sf.hibernate.PropertyValueException: not-null property references a null
or transient value:
gov.nasa.msfc.repository.submittal.model.businessobject.User.center
showing me that center is still null.

Here is UserBean's saveAction method:

  public String saveAction ()
  {
    String result = "fail";
    try
    {
      User user = UserBuilder.createUser ( this );
      this.serviceLocator.getUserService ().save ( user );
      result = "success";
    }
    catch ( UserException ex )
    {
      String msg = "Could not save/udpate user";
      FacesUtils.addErrorMessage ( msg + ":Internal Error" );
    }
    return result;
  }

// UserBuilder.createUser is simply a static method that copies properites
from this bean to a new instance of User.

Thanks,
-Mark



Reply via email to