开发者

problem in passing value from jsp to struts2 action

In my Action Class,

    private int userId;

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

In my JSP page,

<s:select key="sessionLog.userid" id="userId" name="userId"list="userList" listKey="userId" listValue="username" headerKey="0" headerValue="All Users"/>

First, I populate the select box with names of userlist. So, if one user name is selected , I should get the selected userId back i开发者_如何转开发n my Action class. But, whenever I selected one user name, I always get 0. how to map ?

but if I only pass userId from javascript, I can get the value. I think in struts, it should automatically map the value. Anything wrong with coding? I want the value from action class.

Thanks.


Your action class looks fine. I would suggest however slimming down your select tag to the bare essentials and adding a property tag to the page temporarily to see what, if anything is coming back from your action class. For example, your jsp page should look like this:

Selected User ID: <s:property value="userId" />

<s:select name="userId" list="userList" listKey="userId" listValue="username" />

It may not make a difference but I've had this cause problems for me - I noticed there is no space between your name attribute and the list attribute in your select tag.

name="userId"list="userList" // Should be -->  name="userId" list="userList"
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜