0

I am able set an individual path name for a model, but if I try to set a path for a model inside a another model it throws me an error. I stuck with this kindly give me a solution and also it would be very generous if u elaborate and explain me on what I am going worng and where is the best place learn more about this.

I would like to share my code to get it solved

THIS IS MY CONTROLLER

@RequestMapping(value="contact", method=RequestMethod.GET)
public String contactability(HttpServletRequest request, HttpServletResponse response, Model model, @ModelAttribute("contactDetails") ContactDetails contactDetails){
    try{
        if(contactDetails==null){
            contactDetails= new ContactDetails();
        }
        model.addAttribute("contactabality", contactDetails);

    }catch(Exception e){
        e.printStackTrace();
    }

    return "contactabality";

}

THIS ARE MY MODELS

I have two models involed

  1. contact details here's the code

    @Entity
    @Table(name="TB_CONTACT_DETAILS")
    public class ContactDetails implements Serializable {
    
    @Id
    @GeneratedValue
    @Column(name="CONTACT_ID")
    private Long contactId;
    
    @Column(name="IS_PERM_COMM_SAME")
    private Integer isPermCommSame;
    
    @OneToMany(fetch=FetchType.EAGER,cascade=CascadeType.ALL, mappedBy="contactDetails")
    private Set<AddressDetails> addressDetails = new HashSet<AddressDetails>();
    
    public ContactDetails() {
        // TODO Auto-generated constructor stub
    }
    
    public Long getContactId() {
        return contactId;
    }
    
    public void setContactId(Long contactId) {
        this.contactId = contactId;
    }
    
    public Integer getIsPermCommSame() {
        return isPermCommSame;
    }
    
    public void setIsPermCommSame(Integer isPermCommSame) {
        this.isPermCommSame = isPermCommSame;
    }
    
    public Set<AddressDetails> getAddressDetails() {
        return addressDetails;
    }
    
    public void setAddressDetails(Set<AddressDetails> addressDetails) {
        this.addressDetails = addressDetails;
    }
    

    }

  2. Is the Address Model, here's the code for it

    @Entity
    @Table(name="TB_ADDRESS_DETAILS")
    public class AddressDetails implements Serializable{
    
    @Id
    @GeneratedValue
    @Column(name="ADDRESS_ID")
    private Long addrId;
    
    @ManyToOne(fetch=FetchType.EAGER, cascade=CascadeType.DETACH)
    @JoinColumn(name="ADDR_TYPE")
    private AddressTypeMaster addressType;
    
    @Column(name="ADDRESS_COL1")
    private String addrCol1;
    
    @Column(name="ADDRESS_COL2")
    private String addrCol2;
    
    @Column(name="ADDRESS_COL3")
    private String addrCol3;
    
    @ManyToOne(fetch=FetchType.EAGER,cascade=CascadeType.DETACH)
    @JoinColumn(name="CITY")
    private CityMaster city;
    
    @Column(name="PINCODE")
    private String pincode;
    
    @ManyToOne(fetch=FetchType.EAGER,cascade=CascadeType.DETACH)
    @JoinColumn(name="STATE")
    private StateMaster state ;
    
    @ManyToOne(fetch=FetchType.EAGER,cascade=CascadeType.ALL)
    @JoinColumn(name="CONTACT_ID")
    private ContactDetails contactDetails;
    
    @Column(name="ADDR_STATUS")
    private String addrStatus;
    
    @OneToOne(fetch=FetchType.EAGER,cascade=CascadeType.ALL,mappedBy="addressDetails")
    private EmployeeDetails employeeDetails;
    
    public AddressDetails() {
        // TODO Auto-generated constructor stub
    }
    
    public Long getAddrId() {
        return addrId;
    }
    
    public void setAddrId(Long addrId) {
        this.addrId = addrId;
    }
    
    public AddressTypeMaster getAddressType() {
        return addressType;
    }
    
    public void setAddressType(AddressTypeMaster addressType) {
        this.addressType = addressType;
    }
    
    
    public String getAddrCol1() {
        return addrCol1;
    }
    
    public void setAddrCol1(String addrCol1) {
        this.addrCol1 = addrCol1;
    }
    
    public String getAddrCol2() {
        return addrCol2;
    }
    
    public void setAddrCol2(String addrCol2) {
        this.addrCol2 = addrCol2;
    }
    
    public String getAddrCol3() {
        return addrCol3;
    }
    
    public void setAddrCol3(String addrCol3) {
        this.addrCol3 = addrCol3;
    }
    
    public CityMaster getCity() {
        return city;
    }
    
    public void setCity(CityMaster city) {
        this.city = city;
    }
    
    public String getPincode() {
        return pincode;
    }
    
    public void setPincode(String pincode) {
        this.pincode = pincode;
    }
    
    public StateMaster getState() {
        return state;
    }
    
    public void setState(StateMaster state) {
        this.state = state;
    }
    
    public ContactDetails getContactDetails() {
        return contactDetails;
    }
    
    public void setContactDetails(ContactDetails contactDetails) {
        this.contactDetails = contactDetails;
    }
    
    public String getAddrStatus() {
        return addrStatus;
    }
    
    public void setAddrStatus(String addrStatus) {
        this.addrStatus = addrStatus;
    }
    
    public EmployeeDetails getEmployeeDetails() {
        return employeeDetails;
    }
    
    public void setEmployeeDetails(EmployeeDetails employeeDetails) {
        this.employeeDetails = employeeDetails;
    }
    

    }

THIS IS MY JSP

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Generic Tool For Employee</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->

<link rel="stylesheet" href="layout/css/bootstrap.min.css">
<link rel="stylesheet" href="layout/css/validator/screen.css">
<link rel="stylesheet" href="layout/datepicker/css/bootstrap-datepicker3.min.css">
<link rel="stylesheet" href="layout/css/index.css">

  <div class="container-fluid">
        <h2>Contact Details</h2>
        <form:form commandName="contactabality" class="form-horizontal" id="contactDetailsForm" role="form" method="POST" action="persDetails">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 class="panel-title">Address Details</h4>
                </div>
                <div class="panel-body">
                    <div class="col-sm-6">
                <!--COMMUNICATION ADDRESS DETAILS-->
                     <h3 class="page-header">COMMUNICATION ADDRESS DETAILS</h3>
                         <div class="form-group">
                             <label class="col-sm-4 control-label">Address 1<span class="mandatoryRed">*</span></label>
                             <div class="col-sm-8">
                                 <form:input path="addressDetails.addrCol1" type="text" class="form-control" placeholder="Address 1" name="commAddr1" id="commAddr1"/>
                             </div>
                         </div>
         <%--                 <div class="form-group">
                             <label class="col-sm-4 control-label">Address 2</label>
                             <div class="col-sm-8">
                                 <form:input path="addressDetails.addrCol2" type="text" class="form-control" placeholder="Address 2" name="commAddr2" id="commAddr2"/>
                             </div>
                         </div>
                         <div class="form-group">
                             <label class="col-sm-4 control-label">Address 3</label>
                             <div class="col-sm-8">
                                 <form:input path="addressDetails.addrCol3" type="text" class="form-control" placeholder="Address 3" name="commAddr3" id="commAddr3"/>
                             </div>
                         </div>
                         <div class="form-group">
                             <label class="col-sm-4 control-label">City<span class="mandatoryRed">*</span></label>
                             <div class="col-sm-8">
                                 <form:select path="addressDetails.city.cityId" class="form-control" name="commAddrCity" id="commAddrCity">
                                    <form:options items="${cities}"/>
                                 </form:select>
                             </div>
                         </div>
                         <div class="form-group">
                             <label class="col-sm-4 control-label">State<span class="mandatoryRed">*</span></label>
                             <div class="col-sm-8">
                                 <form:select path="addressDetails.state.stateId" class="form-control" name="commAddrState" id="commAddrState">
                                    <form:options items="${states}" />
                                 </form:select>
                             </div>
                         </div>
                         <div class="form-group">
                             <label class="col-sm-4 control-label">Pincode<span class="mandatoryRed">*</span></label>
                             <div class="col-sm-8">
                                 <form:input path="addressDetails.pincode" type="text" class="form-control" placeholder="Pincode" name="commAddrPincode" id="commAddrPincode" maxlength="6"/>
                             </div>
                         </div>
                     </div>
                     <!--PERMANENT ADDRESS DETAILS-->
                    <div class="col-sm-6">
                        <h4 class="page-header">PERMANENT ADDRESS DETAILS</h4>
                        <div class="form-group">
                            <label class="col-sm-9">Is your permanent address same as communication address<span class="mandatoryRed">*</span></label>
                            <div class="col-sm-2">
                                <div class="toggle-switch toggle-switch-success">
                                    <label>
                                        <form:checkbox path="isPermCommSame" id="PermAddrCheck" type="checkbox" value="2"/>
                                        <div class="toggle-switch-inner"></div>
                                        <div class="toggle-switch-switch"><i class="fa fa-check"></i></div>
                                    </label>
                                </div>

                            </div>
                        </div>
                        <div class="row permAddrClss">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">Address 1<span class="mandatoryRed">*</span></label>
                                <div class="col-sm-8">
                                    <form:input path="addressDetails.addrCol1" type="text" class="form-control" placeholder="Address 1" name="PermAddr1" id="PermAddr1"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label">Address 2</label>
                                <div class="col-sm-8">
                                    <form:input  path="addressDetails.addrCol2" type="text" class="form-control" placeholder="Address 2" name="PermAddr2" id="PermAddr2"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label">Address 3</label>
                                <div class="col-sm-8">
                                    <form:input path="addressDetails.addrCol3" type="text" path="addressDetails.addrCol3" class="form-control" placeholder="Address 3" name="PermAddr3" id="PermAddr3"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label">City<span class="mandatoryRed">*</span></label>
                                <div class="col-sm-8">
                                    <form:select path="addressDetails.city.cityId" class="form-control" name="PermAddrCity" id="PermAddrCity">
                                        <form:options items="${cities}"  />
                                    </form:select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label">State<span class="mandatoryRed">*</span></label>
                                <div class="col-sm-8">
                                    <form:select path="addressDetails.state.stateId" class="form-control" name="PermAddrState" id="PermAddrState">
                                        <form:options items="${states}"/>
                                    </form:select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-4 control-label">Pincode<span class="mandatoryRed">*</span></label>
                                <div class="col-sm-8">
                                    <form:input path="addressDetails.pincode" type="text" class="form-control" placeholder="Pincode" name="PermAddrPincode" id="PermAddrPincode" maxlength="6"/>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>--%>
            <p>
                <input class="submit btn btn-default" type="submit" value="Submit">
            </p>
        </form:form> 
    </div>

    <!-- SCRIPTS -->
    <script src="layout/js/vendors/jquery-1.9.1.min.js"></script>
    <script src="layout/js/vendors/jquery.validate.min.js"></script>
    <script src="layout/js/vendors/bootstrap-3.3.5.js"></script>
    <script src="layout/datepicker/js/bootstrap-datepicker.min.js"></script>
    <script src="layout/js/index.js"></script>
    <script src="layout/js/contactabality.js"></script>

THE ERROR I GOT IS

4:46:34,916 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/eob-web].[jsp]] (http-localhost/127.0.0.1:8080-5) JBWEB000236: Servlet.service() for servlet jsp threw exception: org.springframework.beans.NotReadablePropertyException: Invalid property 'addressDetails.addrCol1' of bean class [com.rectrix.eob.models.ContactDetails]: Bean property 'addressDetails.addrCol1' is not readable or has an invalid getter method: Does the return type

AND

14:46:34,922 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/eob-web].[jsp]] (http-localhost/127.0.0.1:8080-5) JBWEB000236: Servlet.service() for servlet jsp threw exception: org.apache.tiles.util.TilesIOException: JSPException including path '/WEB-INF/views/jsp/contactabality.jsp'.

Kindly help me to figure this out. Thank you

1 Answer 1

2
private Set<AddressDetails> addressDetails = new HashSet<AddressDetails>(); 

is your problem. I believe you are going to store only two kind of addresses in the above list, i would suggest you to bind Permanent and Communication address details as separate properties instead of binding as list.

some thing like creating two more Transient properties in ContactDetails bean @Transient private AddressDetails commAddressDetails and @Transient private AddressDetails permAddressDetails and corresponding setter/getter.

use these properties in your Jsp for respective fields, prior to persist write your own logic to construct one-to-many relationship. This will work if you have static number of Addresses.

Sign up to request clarification or add additional context in comments.

5 Comments

I appreciate your time for helping me, thank you for that . And my other models also developed in the same fashion, like for example. I have employeeExp model which consist of pastExp attribute in which i have company name. So the name the user is trying to set from employee exp should go inside the pastExp's company name. For that In the jsp of employeeExp I gave a path for the company name as pastExp.companyName. In this case I need it to go this way but I get the same error as shown above. How to resolve this.
How is your view design in that case? -- This answer may help you. stackoverflow.com/questions/33015654/…
Thank you -Lovababu. I think thats what I am trying to do. I need to bind my model with in an model. For that I used to give pastExp.companyName as a path. But i am getting the same error
Is that also a list<PastExp> in employeeExp? If yes, you can't bind if you have dynamic size of list, so i would suggest you todo as detailed in aforementioned link.
Ok Thank you very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.