0

i have the object of this structure

public class Cleanse {

private Contacts contact;
private List<Contacts> dnb360;
private String operation;   

public String getOperation() {
    return operation;
}
public void setOperation(String operation) {
    this.operation = operation;
}
public Contacts getContact() {
    return contact;
}
public void setContact(Contacts contact) {
    this.contact = contact;
}
public List<Contacts> getDnb360() {
    return dnb360;
}
public void setDnb360(List<Contacts> dnb360) {
    this.dnb360 = dnb360;
}

In jsp i am getting the list of cleanse objects

can anyone tell me how to bind this list and get the submitted value in contoller

1 Answers1

1

Binding in the jsp is not that difficult. If you're using core jstl tags (which you should), you only have to iterate over the lists entries and do with them what ever you want:

<c:forEach items="${dnb360}" var="s">
      <b>${s}</b> 
</c:forEach>

Since you're talking about 'submitting', I guess you#re trying to set up a form here, which makes it even easier (use spring's form tag here) <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>:

<form:checkboxes items="${dnb360}" path="dnb360" />

For retrieving such a bound value and convert back to your object, I'd suggest using the @InitBinder annotation. You annotate a method with that and define how to bind a String value back to your object when retrieving this String through a method which has @ModelAttribute("dnb360") dnb360,...

@InitBinder
public void initBinder(WebDataBinder binder) {
    //custom editor to bind Institution by name
    binder.registerCustomEditor(Contacts.class, new PropertyEditorSupport() {

        @Override
        public void setAsText(String text) throws IllegalArgumentException {
            setValue(xxx); //most likely obtained through database call
        }

    });
}

If you need more help, please feel free to ask.

chzbrgla
  • 5,158
  • 7
  • 39
  • 56
  • if youre not making it database call and its a post to the controller how do you handle that? Your setAsText function doesnt handle list items. Can you show me how you would handle a list of items. You can see my question here http://stackoverflow.com/questions/15730760/springmvc-how-to-bind-multi-select-options – devdar Mar 31 '13 at 16:25