  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Struts - A MVC web framework | | Tomcat - JSP/Servlet container | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | | JSP - A mailing list about Java Server Pages specification and reference | |
Struts & Hibernate
|
|
|
  | | | Persistent forms question | Persistent forms question 2004-03-20 - By Brad Cox
Back 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 = XPath.newInstance(".//input[@(protected)=radio]|.//input[@(protected)=checkbox]"); 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"); fieldNameList.add(nameAttr); if (checkedAttr != null) continue; ...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" checked="checked"/> #else <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+) __ ____ ____ ____ ____ ____ ____ ____ ____ ____ To control your jdom-interest membership: http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@(protected) .com
|
|
 |