Results 1 to 10 of 13

Thread: Another bean object in Command bean of SimpleFormController

Hybrid View

  1. #1
    Join Date
    Oct 2008
    Posts
    11

    Unhappy Another bean object in Command bean of SimpleFormController

    Hi All,

    I have "CustomerGeneral" bean and i am using this as command bean in my SimpleFormController. This bean has some plain properties like firstName, lastName etc...
    I am using these properties in my JSP form as spring binding like this:
    <spring:bind path="customerGeneral.firstName"></spring:bind>
    <spring:bind path="customerGeneral.lastName"></spring:bind>

    Actually all these information like firstName, lastName are in another bean named "Contact".

    Now i want to create an object of "Contact" in my command bean "CustomerGeneral" and create getter and setter methods for that. And use the firstName and lastName properties from this new bean into my JSP form page.

    I have created object property for this new bean with getter and setter methods. I am using these firstName and lastName properties in my JSP form page like this:
    <spring:bind path="customerGeneral.contacts.firstName"></spring:bind>
    <spring:bind path="customerGeneral.contacts.lastName"></spring:bind>

    but while page is loading it is throwing this error:

    ERROR [org.springframework.web.servlet.tags.BindTag] - MESSAGE : Invalid property 'contacts' of bean class [com.izmocars.crm.customer
    .dto.CustomerGeneral]: Value of nested property 'contacts' is null -
    org.springframework.beans.NullValueInNestedPathExc eption: Invalid property 'contacts' of bean class [com.izmocars.crm.customer.dto.CustomerGeneral]: Value of
    nested property 'contacts' is null


    What could be wrong?
    Please help me!!!

  2. #2
    Join Date
    Aug 2008
    Posts
    3

    Default

    Can you post the code of the GeneralContract and cotract. Also the appropriate code from your controller.

  3. #3
    Join Date
    Dec 2006
    Posts
    311

    Default

    You need to initialize the object in the command:

    Contact contacts = new Contacts();

  4. #4
    Join Date
    Oct 2008
    Posts
    11

    Red face

    Thanks Terp,

    I did it like what you said... and it is working for Contact object.

    But now i have got new problem... I have a set of address object in my contact bean. How to access address bean properties. I am getting error while accessing them.

    Here is my code...

    CustomerGeneral.java
    =======================
    public class CustomerGeneral
    {
    private IfwCompanies ifwCompany = new IfwCompanies();
    private IfwCompanies ifwDealer = new IfwCompanies();
    private IfwContacts ifwContacts = new IfwContacts();

    /*
    Setters and getters...
    */

    }


    Contact.java
    =================
    public class Contacts
    {
    private String firstname;
    private String middlename;
    private String lastname;

    private Set<Addresses> addresses = new HashSet<Addresses>(0);

    /*
    Setters and getters
    */

    }


    Address.java
    ================
    public class Addresses
    {
    private String addressName1;
    private String addressName2;
    etc...

    /*
    Getters and setters
    */

    }




    Here is the way i am accessing the objects in my JSP page
    ============================================

    <spring:bind path="customerGeneral.contacts.firstname"> <form:input path="customerGeneral.contacts.firstname" /> </spring:bind>

    <spring:bind path="customerGeneral.contacts.lastname"> <form:input path="customerGeneral.contacts.lastname" /> </spring:bind>

    <spring:bind path="customerGeneral.contacts.middlename"> <form:input path="customerGeneral.contacts.middlename" /> </spring:bind>

    Till here everything is working.
    When i access address object's properties like below

    <spring:bind path="customerGeneral.contacts.addresses.addressNa me1"> <form:input path="customerGeneral.contacts.addresses.addressNa me1" /> </spring:bind>


    I get error like this:

    2008-10-23 09:51:14,909 ERROR [org.springframework.web.servlet.tags.form.InputTag] - MESSAGE : Invalid property 'contacts.addresses.addressName1' of bean
    class [com.ifw.admin.domain.contacts]: Bean property 'contacts.addresses.addressName1' is not readable or has an invalid getter method: Does the return
    type of the getter match the parameter type of the setter? -
    org.springframework.beans.NotReadablePropertyExcep tion: Invalid property 'contacts.addresses.addressName1' of bean class [com.ifw.admin.domain.contacts
    ]: Bean property 'contacts.addresses.addressName1' is not readable or has an invalid getter method: Does the return type of the getter match the parameter
    type of the setter?
    at org.springframework.beans.BeanWrapperImpl.getPrope rtyValue(BeanWrapperImpl.java:534)
    at org.springframework.beans.BeanWrapperImpl.getPrope rtyValue(BeanWrapperImpl.java:526)
    at org.springframework.validation.AbstractPropertyBin dingResult.getActualFieldValue(AbstractPropertyBin dingResult.java:77)
    at org.springframework.validation.AbstractBindingResu lt.getFieldValue(AbstractBindingResult.java:337)
    at org.springframework.web.servlet.support.BindStatus .<init>(BindStatus.java:117)
    at org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.getBindStatus(AbstractData BoundFormElementTag.java:184)
    at org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.getPropertyPath(AbstractDa taBoundFormElementTag.java:204)
    at org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.getName(AbstractDataBoundF ormElementTag.java:158)
    at org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.autogenerateId(AbstractDat aBoundFormElementTag.java:145)
    at org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.writeDefaultAttributes(Abs tractDataBoundFormElementTag.java:135)
    at org.springframework.web.servlet.tags.form.Abstract HtmlElementTag.writeDefaultAttributes(AbstractHtml ElementTag.java:379)
    at org.springframework.web.servlet.tags.form.Abstract HtmlInputElementTag.writeDefaultAttributes(Abstrac tHtmlInputElementTag.java:177)
    at org.springframework.web.servlet.tags.form.InputTag .writeTagContent(InputTag.java:139)
    at org.springframework.web.servlet.tags.form.Abstract FormTag.doStartTagInternal(AbstractFormTag.java:93 )
    at org.springframework.web.servlet.tags.RequestContex tAwareTag.doStartTag(RequestContextAwareTag.java:7 7)
    at org.apache.jsp.WEB_002dINF.jsps.crm.customer.custo merAdd_jsp._jspx_meth_form_005finput_005f5(custome rAdd_jsp.java:2636)
    at org.apache.jsp.WEB_002dINF.jsps.crm.customer.custo merAdd_jsp._jspService(customerAdd_jsp.java:1150)
    at org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
    at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:393)
    at org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:320)
    at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:266)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.inv oke(ApplicationDispatcher.java:654)
    at org.apache.catalina.core.ApplicationDispatcher.pro cessRequest(ApplicationDispatcher.java:445)
    at org.apache.catalina.core.ApplicationDispatcher.doF orward(ApplicationDispatcher.java:379)
    at org.apache.catalina.core.ApplicationDispatcher.for ward(ApplicationDispatcher.java:292)
    at org.springframework.web.servlet.view.InternalResou rceView.renderMergedOutputModel(InternalResourceVi ew.java:142)
    at org.springframework.web.servlet.view.AbstractView. render(AbstractView.java:243)
    at org.springframework.web.servlet.DispatcherServlet. render(DispatcherServlet.java:1141)
    at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:878)
    at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:792)
    at org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:460)
    at org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:415)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:690)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:230)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:104)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:261)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:581)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:595)





    What could be the problem?
    Is there any other way to access properties like address which are of collection type <Set>


    Please help me!!!

  5. #5
    Join Date
    Oct 2006
    Posts
    228

    Default

    You need to specify the index of the object you are accessing within the collection.

    e.g. customerGeneral.contacts.addresses[0].addressName1

    Normally, you would iterate over the collection using JSTL tags to access each element in the collection.

  6. #6
    Join Date
    Oct 2008
    Posts
    11

    Default

    I tried with this approach...

    Now it gives error like this:

    2008-10-23 10:15:36,417 ERROR [org.springframework.web.servlet.tags.form.InputTag] - MESSAGE : Invalid property 'contacts.addresses[0]' of bean class [com
    .izmocars.crm.customer.dto.CustomerGeneral]: Cannot get element with index 0 from Set of size 0, accessed using property path 'addresses[0]' -
    org.springframework.beans.InvalidPropertyException : Invalid property 'contacts.addresses[0]' of bean class [com.izmocars.crm.customer.dto.CustomerGeneral]
    : Cannot get element with index 0 from Set of size 0, accessed using property path 'addresses[0]'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •