Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem about checkbox for script generator

 
Rizvan Asgarov
Ranch Hand
Posts: 462
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,
I wish successes to everybody!

My question is such:

When i change the value of the following code (value="0") that is shown in the situation to checked
But when i click the submit button nothing is generated :?: so how to get my page on checked state?

Program side:

List<ClassProperty> mainList = new ArrayList<ClassProperty>();
for (int i = 0; i < classPropertyList.size(); i++) {
ClassProperty classProperty = (ClassProperty) classPropertyList.get(i);
if (classProperty.getSelected() == 1) {
mainList.add(classProperty);
}
}

JSP side:

<logic-el:iterate id="classProperty"
name="<%=AdminConstantKeys.CLASS_PROPERTY_LIST_SESSION_KEY%>"
type="az.fhn.admin.model.ClassProperty" indexId="ctr">

<html-el:hidden property="classPropertyList[${ctr}].propertyName"
styleId="classPropertyList[${ctr}].propertyName"/>
<tr>
<td width="50" align="center">
<html-el:checkbox name="scriptGeneratorForm"
property="classPropertyList[${ctr}].selected"
styleId="classPropertyList[${ctr}].selected" value="0"
tabindex="1"/>

</td>

also generated HTML source code:
................................................................
<td width="50" align="center">
<input type="checkbox" name="classPropertyList[0].selected" tabindex="1" value="0" checked="checked" id="classPropertyList[0].selected">
</td>
.................................................................
<td width="50" align="center">
<input type="checkbox" name="classPropertyList[1].selected" tabindex="1" value="0" checked="checked" id="classPropertyList[1].selected">
</td>
.................................................................
Thanks beforehand!
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since I see html-el tags in your JSP, I'm assuming you're using some version of Struts 1. When you use indexed properties in Struts 1, your ActionForm must have a property containing a collection that matches the name of the property in the JSP. That property must also have indexed getters and setters.

What you've done is place the list in Session scope, which is fine for rendering the checkboxes, but not fine for getting a result back. The solution, then would be to place the list in the ActionForm something like this:

ActionForm



If you want to put the ActionForm in request scope, you will need to provide lazy initialization for your indexed getter. See this entry in our Struts 1 FAQ for more information.
 
Rizvan Asgarov
Ranch Hand
Posts: 462
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Merrill,
Thanks a lot.. you are right!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic