dgraham 2002/11/11 19:47:42 Modified: src/share/org/apache/struts/taglib/html CancelTag.java SubmitTag.java CheckboxTag.java ResetTag.java ButtonTag.java FormTag.java RadioTag.java HtmlTag.java BaseTag.java MessagesTag.java OptionTag.java ImageTag.java BaseHandlerTag.java ErrorsTag.java JavascriptValidatorTag.java BaseFieldTag.java MultiboxTag.java Log: Added xhtml support with 2 simple helper methods added to BaseHandlerTag. The html taglib now outputs xhtml when nested inside an <html:html xhtml="true"> tag. Revision Changes Path 1.9 +5 -5 jakarta-struts/src/share/org/apache/struts/taglib/html/CancelTag.java Index: CancelTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/CancelTag.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- CancelTag.java 26 Oct 2002 15:08:16 -0000 1.8 +++ CancelTag.java 12 Nov 2002 03:47:42 -0000 1.9 @@ -210,7 +210,7 @@ results.append("\""); results.append(prepareEventHandlers()); results.append(prepareStyles()); - results.append(">"); + results.append(getElementClose(this)); // Render this element to our writer ResponseUtils.write(pageContext, results.toString()); 1.15 +5 -5 jakarta-struts/src/share/org/apache/struts/taglib/html/SubmitTag.java Index: SubmitTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/SubmitTag.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- SubmitTag.java 26 Oct 2002 15:08:16 -0000 1.14 +++ SubmitTag.java 12 Nov 2002 03:47:42 -0000 1.15 @@ -230,7 +230,7 @@ results.append("\""); results.append(prepareEventHandlers()); results.append(prepareStyles()); - results.append(">"); + results.append(getElementClose(this)); // Render this element to our writer ResponseUtils.write(pageContext, results.toString()); 1.16 +5 -5 jakarta-struts/src/share/org/apache/struts/taglib/html/CheckboxTag.java Index: CheckboxTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/CheckboxTag.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- CheckboxTag.java 26 Oct 2002 15:08:16 -0000 1.15 +++ CheckboxTag.java 12 Nov 2002 03:47:42 -0000 1.16 @@ -218,7 +218,7 @@ results.append(" checked=\"checked\""); results.append(prepareEventHandlers()); results.append(prepareStyles()); - results.append(">"); + results.append(getElementClose(this)); // Print this field to our output writer ResponseUtils.write(pageContext, results.toString()); 1.10 +5 -5 jakarta-struts/src/share/org/apache/struts/taglib/html/ResetTag.java Index: ResetTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/ResetTag.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- ResetTag.java 26 Oct 2002 15:08:16 -0000 1.9 +++ ResetTag.java 12 Nov 2002 03:47:42 -0000 1.10 @@ -225,7 +225,7 @@ results.append("\""); results.append(prepareEventHandlers()); results.append(prepareStyles()); - results.append(">"); + results.append(getElementClose(this)); // Render this element to our writer ResponseUtils.write(pageContext, results.toString()); 1.13 +5 -5 jakarta-struts/src/share/org/apache/struts/taglib/html/ButtonTag.java Index: ButtonTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/ButtonTag.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- ButtonTag.java 26 Oct 2002 15:08:16 -0000 1.12 +++ ButtonTag.java 12 Nov 2002 03:47:42 -0000 1.13 @@ -207,7 +207,7 @@ results.append("\""); results.append(prepareEventHandlers()); results.append(prepareStyles()); - results.append(">"); + results.append(getElementClose(this)); // Render this element to our writer ResponseUtils.write(pageContext, results.toString()); 1.32 +11 -11 jakarta-struts/src/share/org/apache/struts/taglib/html/FormTag.java Index: FormTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/FormTag.java,v retrieving revision 1.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- FormTag.java 8 Nov 2002 05:39:24 -0000 1.31 +++ FormTag.java 12 Nov 2002 03:47:42 -0000 1.32 @@ -596,7 +596,7 @@ HttpSession session = pageContext.getSession(); if (session != null) { String token = - (String) session.getAttribute(Action.TRANSACTION_TOKEN_KEY); + (String) session.getAttribute(Globals.TRANSACTION_TOKEN_KEY); if (token != null) { results.append("<input type=\"hidden\" name=\""); results.append(Constants.TOKEN_KEY); @@ -801,7 +801,7 @@ // Use our servlet mapping, if one is specified String servletMapping = (String) - pageContext.getAttribute(Action.SERVLET_KEY, + pageContext.getAttribute(Globals.SERVLET_KEY, PageContext.APPLICATION_SCOPE); if (servletMapping != null) { String queryString = null; @@ -854,12 +854,12 @@ if (moduleConfig == null) { JspException e = new JspException (messages.getMessage("formTag.collections")); - pageContext.setAttribute(Action.EXCEPTION_KEY, e, + pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE); throw e; } servlet = (ActionServlet) - pageContext.getServletContext().getAttribute(Action.ACTION_SERVLET_KEY); + pageContext.getServletContext().getAttribute(Globals.ACTION_SERVLET_KEY); // Look up the action mapping we will be submitting to String mappingName = getActionMappingName(); @@ -867,7 +867,7 @@ if (mapping == null) { JspException e = new JspException (messages.getMessage("formTag.mapping", mappingName)); - pageContext.setAttribute(Action.EXCEPTION_KEY, e, + pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE); throw e; } @@ -877,7 +877,7 @@ if (type == null) { JspException e = new JspException (messages.getMessage("formTag.nameType")); - pageContext.setAttribute(Action.EXCEPTION_KEY, e, + pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE); throw e; } @@ -893,7 +893,7 @@ if (formBeanConfig == null) { JspException e = new JspException (messages.getMessage("formTag.formBean", mapping.getName())); - pageContext.setAttribute(Action.EXCEPTION_KEY, e, + pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE); throw e; } 1.17 +5 -5 jakarta-struts/src/share/org/apache/struts/taglib/html/RadioTag.java Index: RadioTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/RadioTag.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- RadioTag.java 26 Oct 2002 15:08:16 -0000 1.16 +++ RadioTag.java 12 Nov 2002 03:47:42 -0000 1.17 @@ -284,7 +284,7 @@ results.append(" checked=\"checked\""); results.append(prepareEventHandlers()); results.append(prepareStyles()); - results.append(">"); + results.append(getElementClose(this)); // Print this field to our output writer ResponseUtils.write(pageContext, results.toString()); 1.6 +9 -6 jakarta-struts/src/share/org/apache/struts/taglib/html/HtmlTag.java Index: HtmlTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/HtmlTag.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- HtmlTag.java 7 Nov 2002 01:43:34 -0000 1.5 +++ HtmlTag.java 12 Nov 2002 03:47:42 -0000 1.6 @@ -62,10 +62,13 @@ package org.apache.struts.taglib.html; import java.util.Locale; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.TagSupport; + +import org.apache.struts.Globals; import org.apache.struts.action.Action; import org.apache.struts.util.MessageResources; import org.apache.struts.util.ResponseUtils; @@ -204,7 +207,7 @@ return (null); // Return any currently set Locale in our session - Locale current = (Locale) session.getAttribute(Action.LOCALE_KEY); + Locale current = (Locale) session.getAttribute(Globals.LOCALE_KEY); if (current != null) return (current); @@ -213,7 +216,7 @@ return (null); current = pageContext.getRequest().getLocale(); if (current != null) - session.setAttribute(Action.LOCALE_KEY, current); + session.setAttribute(Globals.LOCALE_KEY, current); return (current); } 1.9 +53 -51 jakarta-struts/src/share/org/apache/struts/taglib/html/BaseTag.java Index: BaseTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/BaseTag.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- BaseTag.java 26 Oct 2002 15:08:16 -0000 1.8 +++ BaseTag.java 12 Nov 2002 03:47:42 -0000 1.9 @@ -62,14 +62,15 @@ package org.apache.struts.taglib.html; import java.io.IOException; + import javax.servlet.http.HttpServletRequest; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.PageContext; import javax.servlet.jsp.tagext.TagSupport; -import org.apache.struts.action.Action; -import org.apache.struts.util.MessageResources; +import org.apache.struts.Globals; +import org.apache.struts.util.MessageResources; /** * Renders an HTML <base> element with an href @@ -84,12 +85,12 @@ */ public class BaseTag extends TagSupport { - - /** - * The message resources for this package. - */ - protected static MessageResources messages = - MessageResources.getMessageResources(Constants.Package + ".LocalStrings"); + + /** + * The message resources for this package. + */ + protected static MessageResources messages = + MessageResources.getMessageResources(Constants.Package + ".LocalStrings"); /** * The target window for this base reference. @@ -104,45 +105,46 @@ this.target = target; } - - /** - * Process the start of this tag. - * - * @exception JspException if a JSP exception has occurred - */ - public int doStartTag() throws JspException { - HttpServletRequest request = (HttpServletRequest)pageContext.getRequest(); - StringBuffer buf = new StringBuffer("<base href=\""); - buf.append(request.getScheme()); - buf.append("://"); - buf.append(request.getServerName()); - if ("http".equals(request.getScheme()) && - (80 == request.getServerPort())) { - ; - } else if ("https".equals(request.getScheme()) && - (443 == request.getServerPort())) { - ; - } else { - buf.append(":"); - buf.append(request.getServerPort()); - } - buf.append(request.getRequestURI()); - buf.append("\""); - if (target != null) { - buf.append(" target=\""); - buf.append(target); + /** + * Process the start of this tag. + * + * @exception JspException if a JSP exception has occurred + */ + public int doStartTag() throws JspException { + HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); + StringBuffer buf = new StringBuffer("<base href=\""); + buf.append(request.getScheme()); + buf.append("://"); + buf.append(request.getServerName()); + if ("http".equals(request.getScheme()) && (80 == request.getServerPort())) { + ; + } else if ("https".equals(request.getScheme()) && (443 == request.getServerPort())) { + ; + } else { + buf.append(":"); + buf.append(request.getServerPort()); + } + buf.append(request.getRequestURI()); buf.append("\""); + if (target != null) { + buf.append(" target=\""); + buf.append(target); + buf.append("\""); + } + + if (BaseHandlerTag.isXhtml(this)) { + buf.append("/>"); + } else { + buf.append(">"); + } + + JspWriter out = pageContext.getOut(); + try { + out.write(buf.toString()); + } catch (IOException e) { + pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE); + throw new JspException(messages.getMessage("common.io", e.toString())); + } + return EVAL_BODY_INCLUDE; } - buf.append(">"); - JspWriter out = pageContext.getOut(); - try { - out.write(buf.toString()); - } - catch (IOException e) { - pageContext.setAttribute(Action.EXCEPTION_KEY, e, - PageContext.REQUEST_SCOPE); - throw new JspException(messages.getMessage("common.io", e.toString())); - } - return EVAL_BODY_INCLUDE; - } } 1.6 +17 -14 jakarta-struts/src/share/org/apache/struts/taglib/html/MessagesTag.java Index: MessagesTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/MessagesTag.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- MessagesTag.java 23 Sep 2002 05:13:43 -0000 1.5 +++ MessagesTag.java 12 Nov 2002 03:47:42 -0000 1.6 @@ -62,8 +62,11 @@ package org.apache.struts.taglib.html; import java.util.Iterator; + import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.BodyTagSupport; + +import org.apache.struts.Globals; import org.apache.struts.action.Action; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; @@ -74,9 +77,9 @@ /** * Custom tag that iterates the elements of a message collection. - * It defaults to retrieving the messages from <code>Action.ERROR_KEY</code>, + * It defaults to retrieving the messages from <code>Globals.ERROR_KEY</code>, * but if the message attribute is set to true then the messages will be - * retrieved from <code>Action.MESSAGE_KEY</code>. This is an alternative + * retrieved from <code>Globals.MESSAGE_KEY</code>. This is an alternative * to the default <code>ErrorsTag</code>. * * @author David Winterfeldt @@ -110,17 +113,17 @@ /** * The servlet context attribute key for our resources. */ - protected String bundle = Action.MESSAGES_KEY; + protected String bundle = Globals.MESSAGES_KEY; /** * The session attribute key for our locale. */ - protected String locale = Action.LOCALE_KEY; + protected String locale = Globals.LOCALE_KEY; /** * The request attribute key for our error messages (if any). */ - protected String name = Action.ERROR_KEY; + protected String name = Globals.ERROR_KEY; /** * The name of the property for which error messages should be returned, @@ -139,7 +142,7 @@ protected String footer = null; /** - * If this is set to 'true', then the <code>Action.MESSAGE_KEY</code> will + * If this is set to 'true', then the <code>Globals.MESSAGE_KEY</code> will * be used to retrieve the messages from scope. */ protected String message = null; @@ -223,7 +226,7 @@ ActionMessages messages = null; if (message != null && "true".equalsIgnoreCase(message)) - name = Action.MESSAGE_KEY; + name = Globals.MESSAGE_KEY; try { messages = RequestUtils.getActionMessages(pageContext, name); @@ -325,9 +328,9 @@ iterator = null; processed = false; id = null; - bundle = Action.MESSAGES_KEY; - locale = Action.LOCALE_KEY; - name = Action.ERROR_KEY; + bundle = Globals.MESSAGES_KEY; + locale = Globals.LOCALE_KEY; + name = Globals.ERROR_KEY; property = null; header = null; footer = null; 1.13 +15 -14 jakarta-struts/src/share/org/apache/struts/taglib/html/OptionTag.java Index: OptionTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/OptionTag.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- OptionTag.java 9 Oct 2002 05:09:35 -0000 1.12 +++ OptionTag.java 12 Nov 2002 03:47:42 -0000 1.13 @@ -64,8 +64,11 @@ import java.util.Locale; + import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.BodyTagSupport; + +import org.apache.struts.Globals; import org.apache.struts.action.Action; import org.apache.struts.util.MessageResources; import org.apache.struts.util.RequestUtils; @@ -113,7 +116,7 @@ * The name of the servlet context attribute containing our message * resources. */ - protected String bundle = Action.MESSAGES_KEY; + protected String bundle = Globals.MESSAGES_KEY; public String getBundle() { return (this.bundle); @@ -157,7 +160,7 @@ * The name of the attribute containing the Locale to be used for * looking up internationalized messages. */ - protected String locale = Action.LOCALE_KEY; + protected String locale = Globals.LOCALE_KEY; public String getLocale() { return (this.locale); @@ -337,17 +340,15 @@ * Release any acquired resources. */ public void release() { - - super.release(); - bundle = Action.MESSAGES_KEY; + super.release(); + bundle = Globals.MESSAGES_KEY; disabled = false; key = null; - locale = Action.LOCALE_KEY; - style = null; - styleClass = null; + locale = Globals.LOCALE_KEY; + style = null; + styleClass = null; text = null; - value = null; - + value = null; } 1.24 +5 -5 jakarta-struts/src/share/org/apache/struts/taglib/html/ImageTag.java Index: ImageTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/ImageTag.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- ImageTag.java 8 Nov 2002 05:39:24 -0000 1.23 +++ ImageTag.java 12 Nov 2002 03:47:42 -0000 1.24 @@ -261,7 +261,7 @@ } results.append(prepareEventHandlers()); results.append(prepareStyles()); - results.append(">"); + results.append(getElementClose(this)); // Render this element to our writer ResponseUtils.write(pageContext, results.toString()); 1.18 +74 -53 jakarta-struts/src/share/org/apache/struts/taglib/html/BaseHandlerTag.java Index: BaseHandlerTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/BaseHandlerTag.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- BaseHandlerTag.java 23 Sep 2002 05:13:43 -0000 1.17 +++ BaseHandlerTag.java 12 Nov 2002 03:47:42 -0000 1.18 @@ -62,12 +62,15 @@ package org.apache.struts.taglib.html; import java.util.Locale; + import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.BodyTagSupport; -import org.apache.struts.action.Action; +import javax.servlet.jsp.tagext.Tag; + +import org.apache.struts.Globals; +import org.apache.struts.taglib.logic.IterateTag; import org.apache.struts.util.MessageResources; import org.apache.struts.util.RequestUtils; -import org.apache.struts.taglib.logic.IterateTag; /** * Base class for tags that render form elements capable of including JavaScript @@ -81,39 +84,35 @@ public abstract class BaseHandlerTag extends BodyTagSupport { - // ----------------------------------------------------- Instance Variables - /** * The default Locale for our server. */ protected static final Locale defaultLocale = Locale.getDefault(); - /** * The message resources for this package. */ protected static MessageResources messages = - MessageResources.getMessageResources(Constants.Package + ".LocalStrings"); - + MessageResources.getMessageResources(Constants.Package + ".LocalStrings"); -// Navigation Management + // Navigation Management /** Access key character. */ - protected String accesskey= null; + protected String accesskey = null; /** Tab index value. */ protected String tabindex = null; -// Indexing ability for Iterate + // Indexing ability for Iterate /** Whether to created indexed names for fields * @since Struts 1.1 */ protected boolean indexed = false; -// Mouse Events + // Mouse Events /** Mouse click event. */ private String onclick = null; @@ -136,7 +135,7 @@ /** Mouse released on component event. */ private String onmouseup = null; -// Keyboard Events + // Keyboard Events /** Key down in component event. */ private String onkeydown = null; @@ -147,7 +146,7 @@ /** Key down and up together in component event. */ private String onkeypress = null; -// Text Events + // Text Events /** Text selected in component event. */ private String onselect = null; @@ -155,7 +154,7 @@ /** Content changed after component lost focus event. */ private String onchange = null; -// Focus Events and States + // Focus Events and States /** Component lost focus event. */ private String onblur = null; @@ -169,7 +168,7 @@ /** Component is readonly. */ private boolean readonly = false; -// CSS Style Support + // CSS Style Support /** Style attribute associated with component. */ private String style = null; @@ -180,7 +179,7 @@ /** Identifier associated with component. */ private String styleId = null; -// Other Common Attributes + // Other Common Attributes /** The alternate text of this element. */ private String alt = null; @@ -192,7 +191,7 @@ private String bundle = null; /** The name of the session attribute key for our locale. */ - private String locale = Action.LOCALE_KEY; + private String locale = Globals.LOCALE_KEY; /** The advisory title of this element. */ private String title = null; @@ -200,10 +199,9 @@ /** The message resources key of the advisory title. */ private String titleKey = null; - // ------------------------------------------------------------- Properties -// Navigation Management + // Navigation Management /** Sets the accessKey character. */ public void setAccesskey(String accessKey) { @@ -215,7 +213,6 @@ return (this.accesskey); } - /** Sets the tabIndex value. */ public void setTabindex(String tabIndex) { this.tabindex = tabIndex; @@ -226,7 +223,7 @@ return (this.tabindex); } -// Indexing ability for Iterate [since Struts 1.1] + // Indexing ability for Iterate [since Struts 1.1] /** Sets the indexed value. * @since Struts 1.1 @@ -242,7 +239,7 @@ return (this.indexed); } -// Mouse Events + // Mouse Events /** Sets the onClick event handler. */ public void setOnclick(String onClick) { @@ -314,7 +311,7 @@ return onmouseout; } -// Keyboard Events + // Keyboard Events /** Sets the onKeyDown event handler. */ public void setOnkeydown(String onKeyDown) { @@ -346,7 +343,7 @@ return onkeypress; } -// Text Events + // Text Events /** Sets the onChange event handler. */ public void setOnchange(String onChange) { @@ -368,7 +365,7 @@ return onselect; } -// Focus Events and States + // Focus Events and States /** Sets the onBlur event handler. */ public void setOnblur(String onBlur) { @@ -410,7 +407,7 @@ return readonly; } -// CSS Style Support + // CSS Style Support /** Sets the style attribute. */ public void setStyle(String style) { @@ -442,7 +439,7 @@ return styleId; } -// Other Common Elements + // Other Common Elements /** Returns the alternate text attribute. */ public String getAlt() { @@ -504,10 +501,8 @@ this.titleKey = titleKey; } - // --------------------------------------------------------- Public Methods - /** * Release any acquired resources. */ @@ -519,7 +514,7 @@ altKey = null; bundle = null; indexed = false; - locale = Action.LOCALE_KEY; + locale = Globals.LOCALE_KEY; onclick = null; ondblclick = null; onmouseover = null; @@ -545,10 +540,8 @@ } - // ------------------------------------------------------ Protected Methods - /** * Return the text specified by the literal value or the message resources * key, if any; otherwise return <code>null</code>. @@ -562,8 +555,7 @@ if (literal != null) { if (key != null) { - JspException e = new JspException - (messages.getMessage("common.both")); + JspException e = new JspException(messages.getMessage("common.both")); RequestUtils.saveException(pageContext, e); throw e; } else { @@ -571,8 +563,7 @@ } } else { if (key != null) { - return (RequestUtils.message(pageContext, getBundle(), - getLocale(), key)); + return (RequestUtils.message(pageContext, getBundle(), getLocale(), key)); } else { return null; } @@ -580,30 +571,28 @@ } - /** * Appends bean name with index in brackets for tags with * 'true' value in 'indexed' attribute. * @param handlers The StringBuffer that output will be appended to. * @exception JspException if 'indexed' tag used outside of iterate tag. */ - protected void prepareIndex( StringBuffer handlers, String name ) - throws JspException { + protected void prepareIndex(StringBuffer handlers, String name) throws JspException { // look for outer iterate tag IterateTag iterateTag = (IterateTag) findAncestorWithClass(this, IterateTag.class); if (iterateTag == null) { - // this tag should only be nested in iteratetag, if it's not, throw exception - JspException e = new JspException(messages.getMessage("indexed.noEnclosingIterate")); - RequestUtils.saveException(pageContext, e); - throw e; + // this tag should only be nested in iteratetag, if it's not, throw exception + JspException e = new JspException(messages.getMessage("indexed.noEnclosingIterate")); + RequestUtils.saveException(pageContext, e); + throw e; } - if( name!=null ) - handlers.append( name ); + if (name != null) + handlers.append(name); handlers.append("["); handlers.append(iterateTag.getIndex()); - handlers.append("]"); - if( name!=null ) - handlers.append("."); + handlers.append("]"); + if (name != null) + handlers.append("."); } /** @@ -657,7 +646,6 @@ return handlers.toString(); } - /** * Prepares the mouse event handlers, appending them to the the given * StringBuffer. @@ -782,5 +770,38 @@ } + /** + * Allows HTML tags to find out if they're nested within an %lt;html:html> tag that + * has xhtml set to true. + * @param tag - Tags should pass themselves into the method as a starting point + * for finding the parent html tag. + * @return true if the tag is nested within an html tag with xhtml set to true, false + * otherwise. + * @since Struts 1.1 + */ + protected static boolean isXhtml(Tag tag) { + HtmlTag htmlTag = (HtmlTag) findAncestorWithClass(tag, HtmlTag.class); + if (htmlTag == null) { + return false; + } + + return htmlTag.getXhtml(); + } + + /** + * Returns the closing brace for an input element depending on xhtml status. The tag + * must be nested within an %lt;html:html> tag that has xhtml set to true. + * @param tag - Tags should pass themselves into the method as a starting point + * for finding the parent html tag. + * @return String - > if xhtml is false, /> if xhtml is true + * @since Struts 1.1 + */ + protected String getElementClose(Tag tag) { + if (this.isXhtml(tag)) { + return "/>"; + } else { + return ">"; + } + } } 1.18 +14 -15 jakarta-struts/src/share/org/apache/struts/taglib/html/ErrorsTag.java Index: ErrorsTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/ErrorsTag.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- ErrorsTag.java 23 Sep 2002 05:13:43 -0000 1.17 +++ ErrorsTag.java 12 Nov 2002 03:47:42 -0000 1.18 @@ -65,8 +65,11 @@ import java.util.Iterator; import java.util.Locale; + import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.TagSupport; + +import org.apache.struts.Globals; import org.apache.struts.action.Action; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; @@ -128,7 +131,7 @@ /** * The session attribute key for our locale. */ - protected String locale = Action.LOCALE_KEY; + protected String locale = Globals.LOCALE_KEY; public String getLocale() { return (this.locale); @@ -149,7 +152,7 @@ /** * The request attribute key for our error messages (if any). */ - protected String name = Action.ERROR_KEY; + protected String name = Globals.ERROR_KEY; public String getName() { return (this.name); @@ -194,7 +197,7 @@ RequestUtils.saveException(pageContext, e); throw e; } - if ((errors == null) || errors.empty()) { + if ((errors == null) || errors.isEmpty()) { return (EVAL_BODY_INCLUDE); } @@ -262,19 +265,15 @@ } - /** * Release any acquired resources. */ public void release() { - - super.release(); - bundle = Action.MESSAGES_KEY; - locale = Action.LOCALE_KEY; - name = Action.ERROR_KEY; + super.release(); + bundle = Globals.MESSAGES_KEY; + locale = Globals.LOCALE_KEY; + name = Globals.ERROR_KEY; property = null; - } - } 1.14 +109 -54 jakarta-struts/src/share/org/apache/struts/taglib/html/JavascriptValidatorTag.java Index: JavascriptValidatorTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/JavascriptValidatorTag.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- JavascriptValidatorTag.java 8 Nov 2002 05:45:58 -0000 1.13 +++ JavascriptValidatorTag.java 12 Nov 2002 03:47:42 -0000 1.14 @@ -52,10 +52,8 @@ * <http://www.apache.org/>. */ - package org.apache.struts.taglib.html; - import java.io.IOException; import java.util.ArrayList; import java.util.Collections; @@ -64,6 +62,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; + import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.PageContext; @@ -75,13 +74,13 @@ import org.apache.commons.validator.ValidatorResources; import org.apache.commons.validator.ValidatorUtil; import org.apache.commons.validator.Var; +import org.apache.struts.Globals; import org.apache.struts.action.Action; -import org.apache.struts.validator.ValidatorPlugIn; +import org.apache.struts.config.ModuleConfig; import org.apache.struts.util.MessageResources; -import org.apache.struts.validator.Resources; import org.apache.struts.util.RequestUtils; -import org.apache.struts.config.ModuleConfig; - +import org.apache.struts.validator.Resources; +import org.apache.struts.validator.ValidatorPlugIn; /** * Custom tag that generates JavaScript for client side validation based @@ -94,15 +93,12 @@ */ public class JavascriptValidatorTag extends BodyTagSupport { - // ----------------------------------------------------------- Properties - /** * The servlet context attribute key for our resources. */ - protected String bundle = Action.MESSAGES_KEY; - + protected String bundle = Globals.MESSAGES_KEY; /** * The default locale on our server. @@ -254,18 +250,18 @@ * JavaScript with html comments. If this is set to 'true', which * is the default, the htmlComment will be surround the JavaScript. */ - public String getHtmlComment() { - return htmlComment; - } + public String getHtmlComment() { + return htmlComment; + } - /** - * Sets whether or not to delimit the - * JavaScript with html comments. If this is set to 'true', which - * is the default, the htmlComment will be surround the JavaScript. - */ - public void setHtmlComment(String htmlComment) { - this.htmlComment = htmlComment; - } + /** + * Sets whether or not to delimit the + * JavaScript with html comments. If this is set to 'true', which + * is the default, the htmlComment will be surround the JavaScript. + */ + public void setHtmlComment(String htmlComment) { + this.htmlComment = htmlComment; + } /** * Gets the src attribute's value when defining @@ -293,13 +289,15 @@ StringBuffer results = new StringBuffer(); ModuleConfig config = RequestUtils.getModuleConfig(pageContext); - ValidatorResources resources = (ValidatorResources) - pageContext.getAttribute(ValidatorPlugIn.VALIDATOR_KEY + - config.getPrefix(), PageContext.APPLICATION_SCOPE); + ValidatorResources resources = + (ValidatorResources) pageContext.getAttribute( + ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix(), + PageContext.APPLICATION_SCOPE); Locale locale = null; try { - locale = (Locale) pageContext.getAttribute(Action.LOCALE_KEY, PageContext.SESSION_SCOPE); - } catch (IllegalStateException e) { // Invalidated session + locale = + (Locale) pageContext.getAttribute(Globals.LOCALE_KEY, PageContext.SESSION_SCOPE); + } catch (IllegalStateException e) { // Invalidated session locale = null; } @@ -311,9 +309,10 @@ form = resources.get(locale, formName); if (form != null) { if ("true".equals(dynamicJavascript)) { - MessageResources messages = (MessageResources) - pageContext.getAttribute(bundle + config.getPrefix(), - PageContext.APPLICATION_SCOPE); + MessageResources messages = + (MessageResources) pageContext.getAttribute( + bundle + config.getPrefix(), + PageContext.APPLICATION_SCOPE); List lActions = new ArrayList(); List lActionMethods = new ArrayList(); @@ -349,14 +348,16 @@ ValidatorAction va1 = (ValidatorAction) o1; ValidatorAction va2 = (ValidatorAction) o2; - if ((va1.getDepends() == null || va1.getDepends().length() == 0) && - (va2.getDepends() == null || va2.getDepends().length() == 0)) { + if ((va1.getDepends() == null || va1.getDepends().length() == 0) + && (va2.getDepends() == null || va2.getDepends().length() == 0)) { return 0; - } else if ((va1.getDepends() != null && va1.getDepends().length() > 0) && - (va2.getDepends() == null || va2.getDepends().length() == 0)) { + } else if ( + (va1.getDepends() != null && va1.getDepends().length() > 0) + && (va2.getDepends() == null || va2.getDepends().length() == 0)) { return 1; - } else if ((va1.getDepends() == null || va1.getDepends().length() == 0) && - (va2.getDepends() != null && va2.getDepends().length() > 0)) { + } else if ( + (va1.getDepends() == null || va1.getDepends().length() == 0) + && (va2.getDepends() != null && va2.getDepends().length() > 0)) { return -1; } else { return va1.getDependencies().size() - va2.getDependencies().size(); @@ -394,13 +395,22 @@ // Skip indexed fields for now until there is // a good way to handle error messages (and the length of the list (could retrieve from scope?)) - if (!field.isIndexed() && field.getPage() == page && field.isDependency(va.getName())) { + if (!field.isIndexed() + && field.getPage() == page + && field.isDependency(va.getName())) { String message = Resources.getMessage(messages, locale, va, field); message = (message != null ? message : ""); jscriptVar = getNextVar(jscriptVar); - results.append(" this." + jscriptVar + " = new Array(\"" + field.getKey() + "\", \"" + message + "\", "); + results.append( + " this." + + jscriptVar + + " = new Array(\"" + + field.getKey() + + "\", \"" + + message + + "\", "); results.append("new Function (\"varName\", \""); @@ -413,16 +423,41 @@ String jsType = var.getJsType(); if (Var.JSTYPE_INT.equalsIgnoreCase(jsType)) { - results.append("this." + varKey + "=" + ValidatorUtil.replace(varValue, "\\", "\\\\") + "; "); + results.append( + "this." + + varKey + + "=" + + ValidatorUtil.replace(varValue, "\\", "\\\\") + + "; "); } else if (Var.JSTYPE_REGEXP.equalsIgnoreCase(jsType)) { - results.append("this." + varKey + "=/" + ValidatorUtil.replace(varValue, "\\", "\\\\") + "/; "); + results.append( + "this." + + varKey + + "=/" + + ValidatorUtil.replace(varValue, "\\", "\\\\") + + "/; "); } else if (Var.JSTYPE_STRING.equalsIgnoreCase(jsType)) { - results.append("this." + varKey + "='" + ValidatorUtil.replace(varValue, "\\", "\\\\") + "'; "); + results.append( + "this." + + varKey + + "='" + + ValidatorUtil.replace(varValue, "\\", "\\\\") + + "'; "); // So everyone using the latest format doesn't need to change their xml files immediately. } else if ("mask".equalsIgnoreCase(varKey)) { - results.append("this." + varKey + "=/" + ValidatorUtil.replace(varValue, "\\", "\\\\") + "/; "); + results.append( + "this." + + varKey + + "=/" + + ValidatorUtil.replace(varValue, "\\", "\\\\") + + "/; "); } else { - results.append("this." + varKey + "='" + ValidatorUtil.replace(varValue, "\\", "\\\\") + "'; "); + results.append( + "this." + + varKey + + "='" + + ValidatorUtil.replace(varValue, "\\", "\\\\") + + "'; "); } } @@ -432,16 +467,17 @@ results.append(" } \n\n"); } } else if ("true".equals(staticJavascript)) { - results.append("<script language=\"Javascript1.1\" type=\"text/javascript\">"); + results.append(this.getStartElement()); if ("true".equals(htmlComment)) - results.append(htmlBeginComment); + results.append(htmlBeginComment); } } if ("true".equals(staticJavascript)) { results.append(getJavascriptStaticMethods(resources)); } - if (form != null && ("true".equals(dynamicJavascript) || "true".equals(staticJavascript))) { + if (form != null + && ("true".equals(dynamicJavascript) || "true".equals(staticJavascript))) { results.append(getJavascriptEnd()); } @@ -464,7 +500,7 @@ */ public void release() { super.release(); - bundle = Action.MESSAGES_KEY; + bundle = Globals.MESSAGES_KEY; formName = null; page = 0; methodName = null; @@ -474,12 +510,12 @@ src = null; } - protected String getJavascriptBegin(String methods) { StringBuffer sb = new StringBuffer(); - String name = formName.substring(0, 1).toUpperCase() + formName.substring(1, formName.length()); + String name = + formName.substring(0, 1).toUpperCase() + formName.substring(1, formName.length()); - sb.append("<script language=\"Javascript1.1\" type=\"text/javascript\""); + sb.append(this.getStartElement()); if (src != null) { sb.append(" src=\"" + src + "\"> \n"); @@ -488,13 +524,19 @@ } if ("true".equals(htmlComment)) - sb.append(htmlBeginComment); + sb.append(htmlBeginComment); sb.append("\n var bCancel = false; \n\n"); if (methodName == null || methodName.length() == 0) - sb.append(" function validate" + name + "(form) { \n"); + sb.append( + " function validate" + + name + + "(form) { \n"); else - sb.append(" function " + methodName + "(form) { \n"); + sb.append( + " function " + + methodName + + "(form) { \n"); sb.append(" if (bCancel) \n"); sb.append(" return true; \n"); @@ -535,7 +577,7 @@ sb.append("\n"); if ("true".equals(htmlComment)) - sb.append(htmlEndComment); + sb.append(htmlEndComment); sb.append("</script>\n\n"); return sb.toString(); @@ -589,5 +631,18 @@ } } + /** + * Constructs the beginning <script> element depending on xhtml status. + */ + private String getStartElement() { + StringBuffer start = new StringBuffer("<script type=\"text/javascript\""); + + // there is no language attribute in xhtml + if (!BaseHandlerTag.isXhtml(this)) { + start.append(" language=\"Javascript1.1\""); + } + start.append(">"); + return start.toString(); + } } 1.16 +8 -21 jakarta-struts/src/share/org/apache/struts/taglib/html/BaseFieldTag.java Index: BaseFieldTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/BaseFieldTag.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- BaseFieldTag.java 26 Oct 2002 15:08:16 -0000 1.15 +++ BaseFieldTag.java 12 Nov 2002 03:47:42 -0000 1.16 @@ -59,15 +59,12 @@ * */ - package org.apache.struts.taglib.html; - import javax.servlet.jsp.JspException; import org.apache.struts.util.RequestUtils; import org.apache.struts.util.ResponseUtils; - /** * Convenience base class for the various input tags for text fields. * @@ -77,10 +74,8 @@ public abstract class BaseFieldTag extends BaseInputTag { - // ----------------------------------------------------- Instance Variables - /** * Comma-delimited list of content types that a server processing this form * will handle correctly. This property is defined only for the @@ -97,7 +92,6 @@ this.accept = accept; } - /** * The name of the bean containing our underlying property. */ @@ -111,7 +105,6 @@ this.name = name; } - /** * The "redisplay contents" flag (used only on <code>password</code>). */ @@ -125,17 +118,14 @@ this.redisplay = redisplay; } - /** * The type of input field represented by this tag (text, password, or * hidden). */ protected String type = null; - // --------------------------------------------------------- Public Methods - /** * Generate the required input tag. * <p> @@ -150,8 +140,8 @@ results.append(type); results.append("\" name=\""); // * @since Struts 1.1 - if( indexed ) - prepareIndex( results, name ); + if (indexed) + prepareIndex(results, name); results.append(property); results.append("\""); if (accesskey != null) { @@ -183,8 +173,7 @@ if (value != null) { results.append(ResponseUtils.filter(value)); } else if (redisplay || !"password".equals(type)) { - Object value = RequestUtils.lookup(pageContext, name, property, - null); + Object value = RequestUtils.lookup(pageContext, name, property, null); if (value == null) value = ""; results.append(ResponseUtils.filter(value.toString())); @@ -192,7 +181,7 @@ results.append("\""); results.append(prepareEventHandlers()); results.append(prepareStyles()); - results.append(">"); + results.append(getElementClose(this)); // Print this field to our output writer ResponseUtils.write(pageContext, results.toString()); @@ -202,7 +191,6 @@ } - /** * Release any acquired resources. */ @@ -214,6 +202,5 @@ redisplay = true; } - } 1.16 +66 -92 jakarta-struts/src/share/org/apache/struts/taglib/html/MultiboxTag.java Index: MultiboxTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/MultiboxTag.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- MultiboxTag.java 26 Oct 2002 15:08:16 -0000 1.15 +++ MultiboxTag.java 12 Nov 2002 03:47:42 -0000 1.16 @@ -59,19 +59,18 @@ * */ - package org.apache.struts.taglib.html; - import java.lang.reflect.InvocationTargetException; + import javax.servlet.jsp.JspException; import javax.servlet.jsp.PageContext; + import org.apache.commons.beanutils.BeanUtils; -import org.apache.struts.action.Action; +import org.apache.struts.Globals; import org.apache.struts.util.MessageResources; import org.apache.struts.util.ResponseUtils; - /** * Tag for input fields of type "checkbox". This differs from CheckboxTag * because it assumes that the underlying property is an array getter (of any @@ -86,23 +85,19 @@ public class MultiboxTag extends BaseHandlerTag { - // ----------------------------------------------------- Instance Variables - /** * The constant String value to be returned when this checkbox is * selected and the form is submitted. */ protected String constant = null; - /** * The message resources for this package. */ protected static MessageResources messages = - MessageResources.getMessageResources(Constants.Package + ".LocalStrings"); - + MessageResources.getMessageResources(Constants.Package + ".LocalStrings"); /** * The name of the bean containing our underlying property. @@ -110,40 +105,35 @@ protected String name = Constants.BEAN_KEY; public String getName() { - return (this.name); + return (this.name); } public void setName(String name) { - this.name = name; + this.name = name; } - /** * The property name for this field. */ protected String property = null; - /** * The value which will mark this checkbox as "checked" if present * in the array returned by our property getter. */ protected String value = null; - // ------------------------------------------------------------- Properties - /** * Return the property name. */ public String getProperty() { - return (this.property); + return (this.property); } - /** * Set the property name. * @@ -151,21 +141,19 @@ */ public void setProperty(String property) { - this.property = property; + this.property = property; } - /** * Return the server value. */ public String getValue() { - return (this.value); + return (this.value); } - /** * Set the server value. * @@ -173,14 +161,12 @@ */ public void setValue(String value) { - this.value = value; + this.value = value; } - // --------------------------------------------------------- Public Methods - /** * Process the beginning of this tag. * @@ -188,14 +174,12 @@ */ public int doStartTag() throws JspException { - // Defer processing until the end of this tag is encountered + // Defer processing until the end of this tag is encountered this.constant = null; - return (EVAL_BODY_TAG); + return (EVAL_BODY_TAG); } - - /** * Save the body contents of this tag as the constant that we will * be returning. @@ -212,7 +196,6 @@ } - /** * Render an input element for this tag. * @@ -220,86 +203,77 @@ */ public int doEndTag() throws JspException { - // Create an appropriate "input" element based on our parameters - StringBuffer results = new StringBuffer("<input type=\"checkbox\""); - results.append(" name=\""); - results.append(this.property); - results.append("\""); - if (accesskey != null) { - results.append(" accesskey=\""); - results.append(accesskey); - results.append("\""); - } - if (tabindex != null) { - results.append(" tabindex=\""); - results.append(tabindex); - results.append("\""); - } - results.append(" value=\""); + // Create an appropriate "input" element based on our parameters + StringBuffer results = new StringBuffer("<input type=\"checkbox\""); + results.append(" name=\""); + results.append(this.property); + results.append("\""); + if (accesskey != null) { + results.append(" accesskey=\""); + results.append(accesskey); + results.append("\""); + } + if (tabindex != null) { + results.append(" tabindex=\""); + results.append(tabindex); + results.append("\""); + } + results.append(" value=\""); String value = this.value; if (value == null) value = this.constant; if (value == null) { - JspException e = new JspException - (messages.getMessage("multiboxTag.value")); - pageContext.setAttribute(Action.EXCEPTION_KEY, e, - PageContext.REQUEST_SCOPE); + JspException e = new JspException(messages.getMessage("multiboxTag.value")); + pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE); throw e; } results.append(ResponseUtils.filter(value)); - results.append("\""); - Object bean = pageContext.findAttribute(name); - String values[] = null; - if (bean == null) - throw new JspException - (messages.getMessage("getter.bean", name)); - try { - values = BeanUtils.getArrayProperty(bean, property); - if (values == null) - values = new String[0]; - } catch (IllegalAccessException e) { - throw new JspException - (messages.getMessage("getter.access", property, name)); - } catch (InvocationTargetException e) { - Throwable t = e.getTargetException(); - throw new JspException - (messages.getMessage("getter.result", - property, t.toString())); - } catch (NoSuchMethodException e) { - throw new JspException - (messages.getMessage("getter.method", property, name)); - } - for (int i = 0; i < values.length; i++) { - if (value.equals(values[i])) { - results.append(" checked=\"checked\""); - break; - } - } - results.append(prepareEventHandlers()); - results.append(prepareStyles()); - results.append(">"); + results.append("\""); + Object bean = pageContext.findAttribute(name); + String values[] = null; + if (bean == null) + throw new JspException(messages.getMessage("getter.bean", name)); + try { + values = BeanUtils.getArrayProperty(bean, property); + if (values == null) + values = new String[0]; + } catch (IllegalAccessException e) { + throw new JspException(messages.getMessage("getter.access", property, name)); + } catch (InvocationTargetException e) { + Throwable t = e.getTargetException(); + throw new JspException(messages.getMessage("getter.result", property, t.toString())); + } catch (NoSuchMethodException e) { + throw new JspException(messages.getMessage("getter.method", property, name)); + } + for (int i = 0; i < values.length; i++) { + if (value.equals(values[i])) { + results.append(" checked=\"checked\""); + break; + } + } + results.append(prepareEventHandlers()); + results.append(prepareStyles()); + results.append(getElementClose(this)); // Render this element to our response ResponseUtils.write(pageContext, results.toString()); - // Continue evaluating this page - return (EVAL_PAGE); + // Continue evaluating this page + return (EVAL_PAGE); } - /** * Release any acquired resources. */ public void release() { - super.release(); + super.release(); constant = null; - name = Constants.BEAN_KEY; - property = null; - value = null; + name = Constants.BEAN_KEY; + property = null; + value = null; } - }
-- To unsubscribe, e-mail: <mailto:struts-dev-unsubscribe@;jakarta.apache.org> For additional commands, e-mail: <mailto:struts-dev-help@;jakarta.apache.org>