“Select” not populated from List<String> in struts

不想你离开。 提交于 2019-12-01 21:26:22
<s:select list = "categories" 
           key = "product.search.category" />

You are listing a List<String> and trying to access, through OGNL . (dot notation), fields that do not exist.

In OGNL

product.search.category 

is the equivalent of Java

getProduct().getSearch().getCategory()

Since you are listing Strings, just omit key attribute, because both your key and value will be the String itself.

It seems that you are confusing key with name too: key is the key of the <option> element, while name is the Action's attribute that will receive the chosen value through its Setter.

<s:select list = "categories" 
          name = "chosenCategory" />

EDIT: for a succesful living, implement Preparable Interface and load there your "static" data:

public class ProductSearchAction extends ActionSupport implements Preparable {
    private List<String> categories;
    private String chosenCategory;

    @override
    public void prepare() throws Exception {      
        categories = new ArrayList<String>();
        categories.add("Eins");
        categories.add("Zwei");
        categories.add("Drei");
    }

    @Override
    public String execute() throws Exception {
        return SUCCESS;
    }

    /* GETTERS AND SETTERS */
}

And you must specify fully qualified class names for each tag in struts.xml...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!