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

problem about checkbox for script generator

Rizvan Asgarov
Ranch Hand

Joined: Jan 07, 2009
Posts: 451

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!


"Half of the science is to ask question"
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
Rizvan Asgarov
Ranch Hand

Joined: Jan 07, 2009
Posts: 451

Dear Merrill,
Thanks a lot.. you are right!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem about checkbox for script generator