Author: mrdon Date: Sat Jun 18 00:00:53 2005 New Revision: 191272 URL: http://svn.apache.org/viewcvs?rev=191272&view=rev Log: * Changing rendering of the form name to use the 'id' attribute when in in XHTML strict mode. If an 'id' is already identified with the 'styleId' attribute, an exception is thrown. * Changed dynamic focus javascript to choose form using 'id' attribute in XHTML mode
PR: 35127 Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FormTag.java struts/taglib/trunk/src/java/org/apache/struts/taglib/html/LocalStrings.properties Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FormTag.java URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FormTag.java?rev=191272&r1=191271&r2=191272&view=diff ============================================================================== --- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FormTag.java (original) +++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FormTag.java Sat Jun 18 00:00:53 2005 @@ -496,14 +496,13 @@ * attributes. * @since Struts 1.1 */ - protected String renderFormStartElement() { + protected String renderFormStartElement() throws JspException { StringBuffer results = new StringBuffer("<form"); // render attributes - if (!this.isXhtml()) { - renderName(results); - } + renderName(results); + renderAttribute(results, "method", getMethod() == null ? "post" : getMethod()); renderAction(results); renderAttribute(results, "accept-charset", getAcceptCharset()); @@ -512,7 +511,6 @@ renderAttribute(results, "onreset", getOnreset()); renderAttribute(results, "onsubmit", getOnsubmit()); renderAttribute(results, "style", getStyle()); - renderAttribute(results, "id", getStyleId()); renderAttribute(results, "target", getTarget()); // Hook for additional attributes @@ -523,12 +521,20 @@ } /** - * Renders the name attribute + * Renders the name of the form. If XHTML is set to true, the name will + * be rendered as an 'id' attribute, otherwise as a 'name' attribute. */ - protected void renderName(StringBuffer results) { - results.append(" name=\""); - results.append(beanName); - results.append("\""); + protected void renderName(StringBuffer results) throws JspException { + if (this.isXhtml()) { + if (getStyleId() == null) { + renderAttribute(results, "id", beanName); + } else { + throw new JspException(messages.getMessage("formTag.ignoredId")); + } + } else { + renderAttribute(results, "name", beanName); + renderAttribute(results, "id", getStyleId()); + } } /** @@ -656,11 +662,19 @@ // Construct the control name that will receive focus. // This does not include any index. - StringBuffer focusControl = new StringBuffer("document.forms[\""); - focusControl.append(beanName); - focusControl.append("\"].elements[\""); - focusControl.append(this.focus); - focusControl.append("\"]"); + StringBuffer focusControl = new StringBuffer(); + if (isXhtml()) { + focusControl.append("document.getElementById(\""); + focusControl.append(beanName); + focusControl.append("\")."); + focusControl.append(this.focus); + } else { + focusControl.append("document.forms[\""); + focusControl.append(beanName); + focusControl.append("\"].elements[\""); + focusControl.append(this.focus); + focusControl.append("\"]"); + } results.append(" var focusControl = "); results.append(focusControl.toString()); Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/LocalStrings.properties URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/LocalStrings.properties?rev=191272&r1=191271&r2=191272&view=diff ============================================================================== --- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/LocalStrings.properties (original) +++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/LocalStrings.properties Sat Jun 18 00:00:53 2005 @@ -4,6 +4,8 @@ formTag.collections=Cannot find ActionMappings or ActionFormBeans collection formTag.create=Exception creating bean of class {0}: {1} formTag.formBean=Cannot retrieve definition for form bean: "{0}" on action: "{1}" +formTag.ignoredId=Cannot specify "styleId" when in XHTML mode as the HTML "id" \ + attribute is already used to store the bean name formTag.mapping=Cannot retrieve mapping for action: "{0}" formTag.name=Form bean not specified on mapping for action: "{0}" formTag.nameType=Must specify type attribute if name is specified --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]