[jdom-interest] Persistent forms question

Brad Cox bcox at virtualschool.edu
Sat Mar 20 08:04:35 PST 2004

I've hit a snag in supporting persistent form defaults in 
http://virtualschool.edu/jwaa and http://virtualschool.edu/ale and 
hope someone here can help. Longwinded background follows; 
JDOM-specifics at the end. Here's the outline of where I hit the snag:

   void rewriteRadioAndCheckboxFields(Element element)
     throws JDOMException, ValidationFault
     XPath p = 
     for (Iterator i = p.selectNodes(element).iterator(); i.hasNext(); )
       Object o = i.next();
       Element e = (Element)o;
       String n = e.getName();
       String nameAttr = e.getAttributeValue("name");
       String checkedAttr = e.getAttributeValue("checked");
       if (nameAttr == null)
         throw new ValidationFault(n+" element requres a name attribute");
       if (checkedAttr != null)
       ...now what?...

The problem is the now what section. If this were a text or password 
field, I could do
e.setAttribute("value", "$!form.getValue('foo')"/> and velocity would 
splice in the value at runtime, triggered by the $! prefix. This 
doesn't work with <input name="foo" type="radio"/> (or checkbox), 
which maps to <input name="foo" type="radio" checked/> if foo is 
non-null or minus the checked otherwise. I can't use velocity to 
compute the value because this wouldn't be well-formed XML.

What I'm considering is to replace the entire element (e) with 
several lines like this
	#if ($!form.getValueList('radio').contains('Yes'))
		<input name="radio" value="Yes" type="radio" 
		<input name="radio" value="Yes" type="radio"/>
	#end Yes
but that runs afoul of what I can do inside an iterator (just remove, not add).

Maybe I can rewrite the current element (e) with the long multiline 
replacement shown above, passed in as a single long line of Text? 
Will try that. Meanwhile, better ideas are welcome!
Brad J. Cox, PhD, 703 361 4751, http://virtualschool.edu
        http://virtualschool/ale Action Learning Environment
http://virtualschool.edu/mybank Digital Rights Management System
    http://virtualschool.edu/jco Java Cryptographic Objects (JCO)
   http://virtualschool.edu/jwaa Java Web Application Architecture (JWAA)
  http://virtualschool.edu/java+ Java Preprocessor (Java+)

More information about the jdom-interest mailing list