DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUGĀ· RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://issues.apache.org/bugzilla/show_bug.cgi?id=20535>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED ANDĀ· INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=20535 ------- Additional Comments From [EMAIL PROTECTED] 2005-11-30 06:05 ------- Hi guys, I wanted to see if anyone was working on this because I had come up with my own extension and wanted to know if it would be useful. I'm not up with contributing stuff to projects like this so I coded a DynaActionForm2 of my own which extends DynaActionForm. So far I've only used in it in testing, but the principle seems ok. If you guys want the code, go for it. Here's the text: package com.lp.struts.ext.action; import org.apache.struts.action.DynaActionForm; import java.lang.reflect.Array; import java.util.List; /** * This class extends * [EMAIL PROTECTED] org.apache.struts.action.DynaActionForm DynaActionForm} so that we can * fix the issues where array references in the properties are not created and * cause index exceptions to be thrown. The intent is to re-code the set method * so that when an index value is being set, the arrays are extended as * necessary by an automatic process. This should remove the necessity for using * one of a number of messy work-arounds being used by the struts community. * <p> * <b>NOTE</b> after submitting this for comment on java ranch I found out * about a similar thing using the Bean utils lazy forms. However when I tried * to implement it, I ran into all sorts of problems with implementing. Most * notibly they are heavily linked to the use of the Validator which means you * must register all forms with it before you can use the lazy forms. It took me * some time to work this out because the error messages that are generated are * very vague about what the issue is which makes it difficult to sort out. * <p> * I also looked at using the commons collection LazyList to drive it. but the * issue with that is that it requires the class to provide a factory for * generating objects to be stored. This is ok when you know what you are * storing but the idea behind a dynaactionform is that you do not. * <p> * To cut a long story short this code is smaller, requires no implementation, * xml files supporting it or other libraries. * * @author Derek Clarkson */ public class DynaActionForm2 extends DynaActionForm { // @Override public void set(String name, int index, Object value) { // get the array container from the hashmap of properties. This should // return an array object or a list. Object prop = this.dynaValues.get(name); // error trap. if (prop == null) { throw new NullPointerException("No such variable: '" + name + "'"); } Class arrayClass = prop.getClass(); if (arrayClass.isArray()) { // First check that the array is big enough. If not then we need to // expand it and store the expanded one. if (Array.getLength(prop) < index + 1) { Object newArray = Array.newInstance(arrayClass.getComponentType(), index + 1); System.arraycopy(prop, 0, newArray, 0, Array.getLength(prop)); this.dynaValues.put(name, newArray); prop = newArray; } // Now store the value. Array.set(prop, index, value); } else if (prop instanceof List) { // Quick local ref for ease of coding. List list = (List) prop; // Now check the length and expand as necessary. if (list.size() < index + 1) { // I could not see any way of doing this other than this. Basically // because my criteria was // that I did not want to replace the list, only expand it because // then I would not have to deal // with issues of getting the correct type, etc. Alternatives // welcome. for (int i = list.size(); i <= index; i++) { list.add(null); } } // Store the new value. list.set(index, value); } else { throw new IllegalArgumentException(name + " is not an indexed field."); } } } -- Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug, or are watching the assignee. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
