Question

First things first-

My Class-

public class StakeHolder{
    private String stakeHolderName;
    private Date startDate;
    private Date endDate;
}

My Controller Request Mapping-

@RequestMapping(value = { "/add" }, method = RequestMethod.GET)
public String addGet(Model model) {
    StakeHolder stakeholderObj = new StakeHolder();

    //To be selected in drop-down for 'stakeHolderName' attribute of StakeHolder
    List<String> organizationList = stakeholderObjService
            .getApplicantOrganizations();

    model.addAttribute("orgList", organizationList);
    model.addAttribute(STAKEHOLDER_OBJ_STRING, stakeholderObj);

    return STAKEHOLDER_ADD_VIEW;
}

My JSP code for drop-down -

<form:select path="stakeHolderName" name="stakeHolderSelect"
                        id="stakeHolderSelect" style="width:220px;" items="${orgList}" >

When i submit the form with any value from drop down I have a server-side validator to verify all the values of attributes. When there is an error in date format it returns to the same page. When the data is correct and submitted again the dropdown value gets binded to my class's 'stakeHolderName' attribute in comma separated format which is not required. its something like

StakeHolder [stakeHolderName=,TestOrg1,TestOrg1,TestOrg1, startDate=null, endDate=null]

The original values keeps getting appended to the name each and every time it get submitted with a preceding comma. How can I get the value "TestOrg1" just once without any comma?

Appreciate the help.

Was it helpful?

Solution 2

Sorry for posting the solution so late. The problem was found elsewhere. It was actually on the jsp. The select option had a prior radio button selection to it and on its click event i had to show a pre-filled input text box with default value for the same path variable. So when i submitted the form, it binded the value to the input text as comma separated values.

I couldn't find a solution for it through spring path variable. So i used normal html input boxes with different names and binded those values through init binder.

OTHER TIPS

try to change your drop down code to this in JSP

<form:select path="stakeHolderName">
    <form:options items="${orgList}" />
</form:select>

thank you

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top