aspose file tools*
The moose likes Struts and the fly likes Struts 2 Checkbox problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 Checkbox problem" Watch "Struts 2 Checkbox problem" New topic
Author

Struts 2 Checkbox problem

ec hurley
Greenhorn

Joined: Mar 11, 2005
Posts: 21
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Mar 11, 2005
Posts: 21
Nothing is rendered. Log contains "Expression parameter.name is undefined on line 21, column 61 in template/xhtml/checkbox.ftl"
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Mar 11, 2005
Posts: 21
The correct number of checkboxes is rendering. I now need to get the user.fullname to display.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Mar 11, 2005
Posts: 21
Next to the checkbox, as the label
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Try the "label" attribute.

http://struts.apache.org/2.1.6/docs/checkbox.html
ec hurley
Greenhorn

Joined: Mar 11, 2005
Posts: 21
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jan 17, 2002
Posts: 495
I have this code


It displays the checkboxes. Question is how do i retrieve the List of checkBoxes selected
 
 
subject: Struts 2 Checkbox problem