开发者

list of string not displayed

开发者 https://www.devze.com 2023-02-16 19:46 出处:网络
I use spring 3. I\'m trying to display a value of an object in a jsp. public class UserForm implements Serializable {

I use spring 3. I'm trying to display a value of an object in a jsp.

public class UserForm implements Serializable {

    private List<String> values;
    private String date;
    ...
}

Here is my controller:

@Controller
@RequestMapping("/user.htm")
public class UserController {

    @Autowired
    private IUserService userService;

    @RequestMapping(method = RequestMethod.GET)
    public String userStat(Model model) {

        UserForm stat = userService.populateStatistique();
        stat.setDate("today");
        model.addAttribute("statistiqueForm", stat);
        return "userStat";
    }
}

Here is my jsp:

<form:form commandName="userForm" name="userForm">
    Date: <form:input path="date"></form:input>
    <br/>
    Expediteur: 
    <form:select path="values" items="${values}" />
    <br/>
    <input type="submit" value="create" />
</form:form>

In开发者_运维知识库 the jsp I can see the today value for the date field, but the listbox is empty.

any idea?

thanks


Well, use addAttribute("values", list) if you want it accessible in the jsp. You are currently not setting it and so it is empty.

If that list is contained in the statistiqueForm object, then use items="${statistiqueForm.values}".


You're correctly passing the form object to the jsp page. In that page you have a list box, which has a list of potential values and a list of selected values. The object form contains the list of selected values, but you should also setup the list with all potential values. In fact you reference ${values} in the jsp, but you don't pass it to the jsp. You should add this code to your controller:

model.addAttribute("values", potentialValueList);

I also suggest you to change the name of that list to avoid confusion, so it will be easy to understand the difference from selected values to potential values.

0

精彩评论

暂无评论...
验证码 换一张
取 消