File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts 2 Checkbox problem

 
ec hurley
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create checkboxes by iterating thru an ArrayList. The page comes up blank. Userlist is an array of users. "fullname is an element of user. The JSP code is

<s:form action="adminchg">

<s:iterator value="userlist">

<s:checkbox fieldValue="%{user.fullname}" />

</s:iterator>

<s:submit/>

Can someone please help me? I have not been able to get this working.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the page rendering *anything*? If not, then something else is wrong.

Is there anything in your log file? Is devMode turned on?
 
ec hurley
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing is rendered. Log contains "Expression parameter.name is undefined on line 21, column 61 in template/xhtml/checkbox.ftl"
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah.

Well, your checkbox tag doesn't have a "name" attribute. That's how form parameters are identified--you'll probably want one.
 
ec hurley
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The correct number of checkboxes is rendering. I now need to get the user.fullname to display.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "fieldValue" attribute defines the value the checkbox will send if checked.

Where/how do you want the user name to be displayed?
 
ec hurley
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Next to the checkbox, as the label
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try the "label" attribute.

http://struts.apache.org/2.1.6/docs/checkbox.html
 
ec hurley
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your help. The label rendered when I removed user. prefix. When I look at the source in IE. I see the fieldValue displsayed correctly. I have a better understanding of how to use.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I didn't understand that the "user" was part of the object being iterated over--my fault.

The reason it works now is because it'll call getFullname() on whatever is on top of the stack. To use the "user.fullname" syntax you'd have to do something like this:



Note the "#" in front of user; it creates a value stack context variable (rather than relying on the user object being the top-most stack item).
 
Abiodun Adisa
Ranch Hand
Posts: 495
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this code


It displays the checkboxes. Question is how do i retrieve the List of checkBoxes selected
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic