Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Vetri Thiru

Greenhorn
+ Follow
since Feb 07, 2006
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 Vetri Thiru

Thanks a lot Merrill - That is the problem.

I can't think of a better way to fix it than the one you have suggested (by using html:button with JavaScript instead of html:submit).

Thanks again!
T. Vetri
15 years ago
First of all, thanks much Merrill for helping out.

Here are the code snippets:
1-The relevant portions of your ActionForm

public class MyActionForm extends ActionForm {

// Other beans/EJBs fetch and populate results and bkupResults ArrayList in this form;
//then this form is displayed (upon "success" mapping from there)
private ArrayList results = null, bkupResults = null;

...
public ArrayList getResults() {
return results;
}
public void setResults(ArrayList results) {
this.results = results;
}
public void setResult(int index, MYBean o) {
this.results.set(index, o);
}
public MYBean getResult(int index) {
return (MYBean)this.results.get(index);
}
...
/*
Currently I am not sure how I can unset the checkboxes to the original state - for now I just want to get the checkboxes to work based on user clicks - then I will figure out the contents of this reset method (to make checkbox change from checked to to unchecked). However this is what I have now. If I remove the if check I get a null pointer exception!!
*/
public void reset(ActionMapping mapping, HttpServletRequest request)
{
if (results != null) { //hmmm...why do I need this check?
results = (ArrayList)bkupResults.clone();
logger.severe("Results after reset:"+results);
}
}

}


2-The relevant portions of the javaBean that is in your List

public class MYBean {

...other private fields...
private boolean flag = false;
...
public boolean isFlag() {
return flag;
}
public void setFlag(boolean val) {
this.flag = val;
}
...other setters/getters and toString()
}


3-The relevant portions of the JSP (<html:form tag, and the iterate portion)

<logic:iterate id="result" name="MyActionForm" property="results"
indexId="index" type="MYBean">

<html:form action="/MyAction.do">

<!-- showing other properties here -->
<html:checkbox value="true" property='<%= "result[" + index + "].flag" %>'/>
<!-- showing some other properties here -->

<html:submit property="action">
<bean:message key="delete.submit"/>
</html:submit>

</html:form>
</logic:iterate>

<html:form action="/MyAction.do">
<html:submit property="action">
<!-- In this commit() method I am processing the checkboxes -->
<bean:message key="commit.submit"/>
</html:submit>
...
</html:form>

4-The relevant portion of your struts-config.xml file
<form-bean name="MyActionForm" type="form.MyActionForm"/>

<action path="/MyAction"
name="MyActionForm"
parameter="action"
type="action.MyAction"
input="/mypage_tiledef.jsp"
validate="true">
<!-- Am not yet validating; the form's validate() just returns null -->
<forward name="success" path="/mypage_tiledef.jsp"/>
</action>


Thanks,
T. Vetri
15 years ago
Hi Merrill/Others,

I am facing the exact same problem as the folks above. I am displaying checkboxes using "nested" tags. However each checkbox displays the value that is set from the application; it does not take the values user sets/unsets. I have tried all that has been suggested above (adding a reset method and providing the indexed getter to get an object from the ArrayList). I have even tried to not use the "nested" tags but still the values are not taken from user's inputs (system set boolean values are properly checked in the checkbox). I have put debug statements in the getter/setter methods to see if those are indeed invoked when user clicks on the checkbox; they dont get invoked when user clicks on checkboxes! I am going nuts trying to figure out why

Code structure is just the same as Vidya's (see previous posting above). I have a Form which contains an ArrayList of results; each of the result object in that ArrayList has a boolean member variable and its corresponding setter/getter. (Please let me know if actual code snippets would be needed).

Would be greatful if you could let me know what I might be doing wrong/what I might not be doing.

Thanks,
T. Vetri

[ February 07, 2006: Message edited by: Vetri Thiru ]
[ February 07, 2006: Message edited by: Vetri Thiru ]
15 years ago