Michael Enzo

Greenhorn
+ Follow
since Sep 13, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Michael Enzo

One possibility..

First make sure you have the hashmap is in context (use a tag to put it into page context), or just put it in the session if it will be used over several pages..
Let's assume it's in page context, with the name 'contextHash':

<logic:iterate id="dbHash" name="contextHash" type="java.util.HashMap">
Name:<bean:write name="dbhash" property="name" />
Age:<bean:write name="dbhash" property="age" />
.
.
.
</logic:iterate>


Didn't test it.. hopefully it'll help you out.

There's an example of this in the docs.. here
http://struts.apache.org/userGuide/struts-logic.html#iterate
19 years ago
https://coderanch.com/t/49176/Struts/Struts-Iterate-Index-Checkboxes

I use a vector to prepopulate, and the formbean to snag checkbox values and update the vector.
19 years ago
Heh well, the soln i'm using is ghetto..
I use a .js to iterate over the boxes, forming an int by <<'ing a 0x001 value and adding the value when the box is checked.
The resulting mask can be passed as a string and used to update the vector by iterating through the vector and doing a .get(i), .setCb(true/false), and putting the obj back (.set(i, Object)).

When you revisit the checked page (or just action back to the same page), the checks are updated since it always pulls from the vector (which got updated).

I guess you could argue that passing a string is better than an array anyways, but it would be nice to get the array of boxes back as an array of Objects.. if anyone figures that part out, please post!

Thx --
m
19 years ago
I've read the posts on logic:iterate (and all over google) and have a snag..

I'm iterating over a Vector that contains 'AppPermission' objects.
Each AppPermission object has a boolean property 'cb'.
I use this vector (which is in the session) to prepopulate the checkboxes:

<logic:iterate id="permBoxes" name="<%=AppConstants.UserAPVector%>" indexId="permIndex" type="util.AppPermission">

<html:checkbox indexed="true" name="permBoxes" property="cb" value="true" />
<!-- Struts False Submit -->
<html:hidden indexed="true" name="permBoxes" property="cb" value="false" />

So the checkboxes show up fine, checked as specified in the session's vector. Now, I want to grab any changes to the checks, and update the session vector. To do this, here's my ActionForm code:

// Permissions Checkboxes
private AppPermission [] permBoxes;


public AppPermission [] getPermBoxes() {
return this.permBoxes;
}

public void setPermBoxes(int index, boolean thePerm) {
try {
if (permBoxes == null) {
permBoxes = new AppPermission[100];
}
permBoxes[index].setCb(thePerm);
}
catch (Exception e) {
log("Exception in setPermBoxes: " + e);
}
}


And it doesn't work. The try/catch new AP[100] thing was a suggestion from an earlier post.. might not be needed. The error I'm getting when I try any kind of action from the checkbox page is:

java.lang.NullPointerException
at org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:515)
at org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:428)
at org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:770)
at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:801)


Will it work to use the vector of AppPermissions' cb values to prepopulate the boxes, and then be able to retrieve the array of checkbox values to update the Vector? For more info, here's a snippet of the generated HTML:

...
...
<input type="checkbox" name="permBoxes[2].cb" value="true">
<!-- Struts False Submit -->
<input type="hidden" name="permBoxes[2].cb" value="false">
...
...
19 years ago