Hi,
Yes I have a property called Company, I use 'companyId' to assign the
company in the UserFormController... actually hibernate is the one that
manages the relationship...here it is part of my pojo..
What can be the problem??
Thanx
/**
* Returns the company object that a certain user has.
* @return Returns the company.
*
* @hibernate.many-to-one column="company_id" cascade="save-update"
not-null="true"
*/
public Company getCompany() {
return company;
}
/**
* Assigns a company to a certain user.
* @param company The company to set.
*/
public void setCompany(Company company) {
this.company = company;
}
/**
* Returns the companyId.
* @return Returns the companyId.
*/
public Long getCompanyId() {
return companyId;
}
/**
* Assigns the companyId.
* @param companyId The companyId to set.
* @spring.validator type="required"
*/
public void setCompanyId(Long companyId) {
this.companyId = companyId;
}
Michael Horwitz wrote:
>
> Hi,
>
> I assume you are using Hibernate to do the persistence? In which case I
> would recommend you let Hibernate do the hard work. In your user model you
> should have a property called company is of type Company, and Hibernate
> will
> manage the relationship for you?
>
> Mike.
>
>
> On 12/19/06, hquinn <[EMAIL PROTECTED]> wrote:
>>
>>
>> I checked in my userForm.jsp, and I don't think the problem is there... .
>> My
>> User pojo has a property called 'companyId' which is the property I used
>> for my relationship many-to-one (user-company). This part of the jsp
>> shows
>> a
>> 'select' with all the existing companies... and it works... but for some
>> reason I'm getting that 'null' problem during the test-web... any
>> suggestions?
>>
>> <li>
>> <musas:label styleClass="desc" key="user.companyId"/>
>> <spring:bind path="user.companyId">
>> <select name='<c:out
>> value="${status.expression}"/>'
>> id='<c:out
>> value="${status.expression}"/>'>
>> <option value=""><fmt:message key="
>> label.selectOne"/></option>
>> <c:forEach items="${companyList}"
>> var="company">
>> <option value='<c:out value="${
>> company.id}"/>'
>> <c:if test="${
>> company.id == status.value}">selected="selected"</c:if>
>> ><c:out value="${
>> company.name}"/></option>
>> </c:forEach>
>> </select>
>> <span class="fieldError"><c:out value="${
>> status.errorMessage}"/></span>
>> </spring:bind>
>> </li>
>>
>>
>>
>>
>> Michael Horwitz wrote:
>> >
>> > Hi,
>> >
>> > From the exception stack trace you posted I don't think the problem is
>> in
>> > your controller, but rather in the userform itself. Look for any Spring
>> > form
>> > field where the path is of the form "company.x" where x could be any
>> > attribute of the company.
>> >
>> > Mike
>> >
>> >
>> > On 12/18/06, hquinn <[EMAIL PROTECTED]> wrote:
>> >>
>> >>
>> >> Yeah, for some reason I'm getting that 'null' property, but I don't
>> >> understand why...
>> >> Here it is the part of my userformcontroller where I use the
>> >> companyManager.. I can't see where is the problem..
>> >>
>> >>
>> >> public void setCompanyManager(CompanyManager companyManager){
>> >> this.companyManager = companyManager;
>> >> }
>> >>
>> >>
>> >> public ModelAndView onSubmit(HttpServletRequest request,
>> >> HttpServletResponse response, Object
>> >> command,
>> >> BindException errors)
>> >> throws Exception {
>> >> if (log.isDebugEnabled()) {
>> >> log.debug("entering 'onSubmit' method...");
>> >> }
>> >>
>> >> User user = (User) command;
>> >> Locale locale = request.getLocale();
>> >>
>> >> if (request.getParameter("delete") != null) {
>> >> getUserManager().removeUser(user.getId().toString());
>> >> saveMessage(request, getText("user.deleted",
>> user.getFullName
>> >> (),
>> >> locale));
>> >>
>> >> return new ModelAndView(getSuccessView());
>> >> } else {
>> >> Boolean encrypt = (Boolean)
>> >> getConfiguration().get(Constants.ENCRYPT_PASSWORD);
>> >>
>> >> if (StringUtils.equals(request.getParameter("encryptPass"),
>> >> "true")
>> >> && (encrypt != null && encrypt.booleanValue())) {
>> >>
>> >> String algorithm = (String)
>> >> getConfiguration().get(Constants.ENC_ALGORITHM);
>> >>
>> >> if (algorithm == null) { // should only happen for test
>> >> case
>> >>
>> >> if (log.isDebugEnabled()) {
>> >> log.debug("assuming testcase, setting algorithm
>> to
>> >> 'SHA'");
>> >> }
>> >>
>> >> algorithm = "SHA";
>> >> }
>> >>
>> >>
>> >> user.setPassword(StringUtil.encodePassword(user.getPassword(),
>> >> algorithm));
>> >> }
>> >>
>> >> String[] userRoles = request.getParameterValues
>> ("userRoles");
>> >>
>> >> if (userRoles != null) {
>> >> // for some reason, Spring seems to hang on to the
>> roles
>> >> in
>> >> // the User object, even though isSessionForm() ==
>> false
>> >> user.getRoles().clear();
>> >> for (int i = 0; i < userRoles.length; i++) {
>> >> String roleName = userRoles[i];
>> >> user.addRole(roleManager.getRole(roleName));
>> >> }
>> >> }
>> >>
>> >> Integer originalVersion = user.getVersion();
>> >>
>> >> try {
>> >>
>> >> user.setCompany(companyManager.getCompany(user.getCompanyId
>> >> ().toString()));
>> >> getUserManager().saveUser(user);
>> >> } catch (UserExistsException e) {
>> >> log.warn(e.getMessage());
>> >>
>> >> errors.rejectValue("username", "errors.existing.user",
>> >> new Object[] {
>> >> user.getUsername(),
>> user.getEmail
>> ()
>> >> }, "duplicate user");
>> >>
>> >> // redisplay the unencrypted passwords
>> >> user.setPassword(user.getConfirmPassword());
>> >> // reset the version # to what was passed in
>> >> user.setVersion(originalVersion);
>> >>
>> >> return showForm(request, response, errors);
>> >> }
>> >>
>> >> if (!StringUtils.equals(request.getParameter("from"),
>> "list"))
>> >> {
>> >> saveMessage(request, getText("user.saved",
>> >> user.getFullName(), locale));
>> >>
>> >> // return to main Menu
>> >> return new ModelAndView(new
>> >> RedirectView("mainMenu.html"));
>> >> } else {
>> >> if (StringUtils.isBlank(request.getParameter
>> ("version")))
>> >> {
>> >> saveMessage(request, getText("user.added",
>> >> user.getFullName(), locale));
>> >>
>> >> // Send an account information e-mail
>> >> message.setSubject(getText("signup.email.subject",
>> >> locale));
>> >> sendUserMessage(user,
>> getText("newuser.email.message
>> ",
>> >> user.getFullName(), locale),
>> >> RequestUtil.getAppURL(request));
>> >>
>> >> return showNewForm(request, response);
>> >> } else {
>> >> saveMessage(request,
>> getText("user.updated.byAdmin",
>> >> user.getFullName(), locale));
>> >> }
>> >> }
>> >> }
>> >>
>> >> return showForm(request, response, errors);
>> >> }
>> >>
>> >>
>> >> Michael Horwitz wrote:
>> >> >
>> >> > Hi,
>> >> >
>> >> > It would seem you are trying to navigate the relationship between a
>> >> user
>> >> > and
>> >> > a company, but that the company on the specified user is null. So in
>> >> your
>> >> > userform you have a path of the form 'user.company.x' and for this
>> >> > specific
>> >> > user the company attribute is null?
>> >> >
>> >> > Mike
>> >> >
>> >> >
>> >> > On 12/18/06, hquinn <[EMAIL PROTECTED]> wrote:
>> >> >>
>> >> >>
>> >> >> Greetings everyone!
>> >> >> When I'm testing my application I get this error during the
>> test-web.
>> >> Can
>> >> >> someone tell me why? It seems it has to do with a relationship I
>> have
>> >> >> (User-Company), but I'm not sure... any comments??
>> >> >> Thanx
>> >> >>
>> >> >> Testcase:
>> >> testSave(mx.edu.um.musas.webapp.action.UserFormControllerTest
>> >> ):
>> >> >> Caused an ERROR
>> >> >> [junit] Invalid property 'company' of bean class
>> >> >> [mx.edu.um.musas.model.User]: Value of nested property 'company' is
>> >> null
>> >> >> [junit]
>> org.springframework.beans.NullValueInNestedPathException:
>> >> >> Invalid property 'company' of bean class
>> [mx.edu.um.musas.model.User
>> ]:
>> >> >> Value
>> >> >> of nested property 'company' is null
>> >> >> [junit] at
>> >> >> org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper(
>> >> >> BeanWrapperImpl.java:419)
>> >> >> [junit] at
>> >> >>
>> >>
>> org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath
>> >> (
>> >> >> BeanWrapperImpl.java:394)
>> >> >> [junit] at
>> >> >> org.springframework.beans.BeanWrapperImpl.setPropertyValue(
>> >> >> BeanWrapperImpl.java:601)
>> >> >> [junit] at
>> >> >>
>> org.springframework.beans.AbstractPropertyAccessor.setPropertyValue(
>> >> >> AbstractPropertyAccessor.java:49)
>> >> >> [junit] at
>> >> >>
>> org.springframework.beans.AbstractPropertyAccessor.setPropertyValues
>> (
>> >> >> AbstractPropertyAccessor.java:74)
>> >> >> [junit] at
>> >> >> org.springframework.validation.DataBinder.applyPropertyValues(
>> >> >> DataBinder.java:515)
>> >> >> [junit] at
>> >> >> org.springframework.validation.DataBinder.doBind(DataBinder.java
>> :417)
>> >> >> [junit] at
>> >> >>
>> org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java
>> >> :146)
>> >> >> [junit] at
>> >> >> org.springframework.web.bind.ServletRequestDataBinder.bind(
>> >> >> ServletRequestDataBinder.java:108)
>> >> >> [junit] at
>> >> >>
>> >>
>> org.springframework.web.servlet.mvc.BaseCommandController.bindAndValidate(
>> >> >> BaseCommandController.java:369)
>> >> >> [junit] at
>> >> >>
>> >> >>
>> >>
>> org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal
>> >> >> (AbstractFormController.java:248)
>> >> >> [junit] at
>> >> >>
>> org.springframework.web.servlet.mvc.AbstractController.handleRequest
>> (
>> >> >> AbstractController.java:153)
>> >> >> [junit] at
>> >> >> mx.edu.um.musas.webapp.action.UserFormControllerTest.testSave(
>> >> >> UserFormControllerTest.java:57)
>> >> >> [junit] TEST
>> >> >> mx.edu.um.musas.webapp.action.UserFormControllerTestFAILED
>> >> >> [junit] Testsuite:
>> mx.edu.um.musas.webapp.filter.LocaleFilterTest
>> >> >> [junit] Tests run: 4, Failures: 0, Errors: 0, Time elapsed:
>> >> 0.125sec
>> >> >> [junit] [musas] DEBUG [main] StartupListener.contextInitialized
>> (43)
>> >> |
>> >> >> initializing context...
>> >> >> [junit] [musas] DEBUG [main] StartupListener.contextInitialized
>> (94)
>> >> |
>> >> >> Remember Me Enabled? null
>> >> >> [junit] [musas] DEBUG [main] StartupListener.contextInitialized
>> (95)
>> >> |
>> >> >> Encrypt Passwords? false
>> >> >> [junit] [musas] DEBUG [main] StartupListener.contextInitialized
>> (99)
>> >> |
>> >> >> Populating drop-downs...
>> >> >> [junit] [musas] DEBUG [main] LookupDaoHibernate.getRoles(21) |
>> >> >> retrieving all role names...
>> >> >> [junit] [musas] DEBUG [main] StartupListener.setupContext(115) |
>> >> >> Drop-down initialization complete [OK]
>> >> >> [junit] Testsuite:
>> >> mx.edu.um.musas.webapp.listener.StartupListenerTest
>> >> >> [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed:
>> >> 0.828sec
>> >> >> [junit] Tests FAILED
>> >> >> --
>> >> >> View this message in context:
>> >> >> http://www.nabble.com/test-web-fails-tf2841097s2369.html#a7932409
>> >> >> Sent from the AppFuse - User mailing list archive at Nabble.com.
>> >> >>
>> >> >>
>> ---------------------------------------------------------------------
>> >> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> >> >> For additional commands, e-mail: [EMAIL PROTECTED]
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >>
>> >> --
>> >> View this message in context:
>> >> http://www.nabble.com/test-web-fails-tf2841097s2369.html#a7937382
>> >> Sent from the AppFuse - User mailing list archive at Nabble.com.
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> >> For additional commands, e-mail: [EMAIL PROTECTED]
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/test-web-fails-tf2841097s2369.html#a7949925
>> Sent from the AppFuse - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/test-web-fails-tf2841097s2369.html#a7950222
Sent from the AppFuse - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]