Friday, 15 March 2013

java - Populating drop down with values in bean object Struts -


I'm applying a struts 2 where I'm using a dropdown. I have downgraded this dropdown with Userbeam and UserName with

  Public class dropdown is extended to ActionSupport {Private list arrUserDetails = new ArrayList & lt; Users & gt; (); Public dropdown () {user objUsers = new user (); ObjUsers.setUserId ("101"); ObjUsers.setUserName ("User 1"); ArrUserDetails.add (objUsers); ObjUsers.setUserId ("102"); ObjUsers.setUserName ("User 2"); ArrUserDetails.add (objUsers); ObjUsers.setUserId ("103"); ObjUsers.setUserName ("user3"); ArrUserDetails.add (objUsers); } Public string executed () {Return success; } Public list getArrUserDetails () {return arrUserDetails; } Public Zero SetReuters User Details (List ARUser Details) {this.arrUserDetails = arrUserDetails; }}   

User Bean is given as below

users.java

  public Class users {personal string user id; Private string user name; Public string getUserId () {return userId; } Public Zero SetUserID (String UserID) {this.userId = userId; } Public string getUserName () {return userName; } Public Zero SetUser Name (String Username) {this.userName = userName; }}   

I started typing the code in JSP and writing through the Struts2 tag lib list to populate in the drop down.

  & lt; S: select Label = "UserList" list = "arrUserDetails" name = "yourSearchEngine" />   

But this option is displaying memory space in drop down instead of username.

Expected output

  & lt; Select name = "" & gt; & Lt; Option value = "101" & gt; User 1 & lt; / Options & gt; & Lt; Option value = "102" & gt; User 2 & lt; / Options & gt; & Lt; Option value = "103" & gt; User 3 & lt; / Options & gt; & Lt; / Select & gt;    

I think you'll also list the list and list value for tags need to.

listWalue =

to get title from the property of the list items

Then, in your case, ListKey = "userId" And listValue = "userName"

No comments:

Post a Comment