• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Struts 2 Checkbox problem

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Next to the checkbox, as the label
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try the "label" attribute.

http://struts.apache.org/2.1.6/docs/checkbox.html
 
ec hurley
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this code


It displays the checkboxes. Question is how do i retrieve the List of checkBoxes selected
 
So there I was, trapped in the jungle. And at the last minute, I was saved by this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic