craigmcc 01/03/10 15:27:32 Modified: src/doc struts-html.xml src/share/org/apache/struts/taglib/html CheckboxTag.java Log: Modify the <html:checkbox> tag to conform to it's documentation: the value specified by the "value" attribute is submitted to the server if this checkbox is checked at submit time. In addition, if no value attribute is specified, the value "on" will be returned, because value is required on the underlying HTML <input> tag on a checkbox. Submitted by: [EMAIL PROTECTED] PR: Bugzilla #818 Revision Changes Path 1.22 +2 -1 jakarta-struts/src/doc/struts-html.xml Index: struts-html.xml =================================================================== RCS file: /home/cvs/jakarta-struts/src/doc/struts-html.xml,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- struts-html.xml 2001/03/09 14:39:05 1.21 +++ struts-html.xml 2001/03/10 23:27:30 1.22 @@ -685,7 +685,8 @@ <rtexprvalue>true</rtexprvalue> <info> The value to be transmitted if this checkbox is - checked when the form is submitted. + checked when the form is submitted. If not specified, + the value "on" will be returned. </info> </attribute> </tag> 1.3 +42 -52 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.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CheckboxTag.java 2001/01/08 21:36:05 1.2 +++ CheckboxTag.java 2001/03/10 23:27:31 1.3 @@ -1,13 +1,13 @@ /* - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/CheckboxTag.java,v 1.2 2001/01/08 21:36:05 craigmcc Exp $ - * $Revision: 1.2 $ - * $Date: 2001/01/08 21:36:05 $ + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/CheckboxTag.java,v 1.3 2001/03/10 23:27:31 craigmcc Exp $ + * $Revision: 1.3 $ + * $Date: 2001/03/10 23:27:31 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,7 +29,7 @@ * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * - * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * 4. The names "The Jakarta Project", "Struts", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] @@ -64,19 +64,19 @@ import java.io.IOException; -import java.lang.reflect.InvocationTargetException; import javax.servlet.jsp.JspException; import javax.servlet.jsp.PageContext; import javax.servlet.jsp.JspWriter; -import org.apache.struts.util.BeanUtils; import org.apache.struts.util.MessageResources; +import org.apache.struts.util.RequestUtils; +import org.apache.struts.util.ResponseUtils; /** * Tag for input fields of type "checkbox". * * @author Craig R. McClanahan - * @version $Revision: 1.2 $ $Date: 2001/01/08 21:36:05 $ + * @version $Revision: 1.3 $ $Date: 2001/03/10 23:27:31 $ */ public class CheckboxTag extends BaseHandlerTag { @@ -190,44 +190,29 @@ results.append(tabindex); results.append("\""); } - String value = this.value; - if (value == null) { - Object bean = pageContext.findAttribute(name); - if (bean == null) - throw new JspException - (messages.getMessage("getter.bean", name)); - try { - value = BeanUtils.getProperty(bean, property); - if (value == null) - value = ""; - } 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)); - } - } - if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes") - || value.equalsIgnoreCase("on")) + results.append(" value=\""); + if (value == null) + results.append("on"); + else + results.append(value); + results.append("\""); + Object result = RequestUtils.lookup(pageContext, name, + property, null); + if (result == null) + result = ""; + if (!(result instanceof String)) + result = result.toString(); + String checked = (String) result; + if (checked.equalsIgnoreCase("true") + || checked.equalsIgnoreCase("yes") + || checked.equalsIgnoreCase("on")) results.append(" checked"); results.append(prepareEventHandlers()); results.append(prepareStyles()); results.append(">"); // Print this field to our output writer - JspWriter writer = pageContext.getOut(); - try { - writer.print(results.toString()); - } catch (IOException e) { - throw new JspException - (messages.getMessage("common.io", e.toString())); - } + ResponseUtils.write(pageContext, results.toString()); // Continue processing this page return (EVAL_BODY_TAG); @@ -241,21 +226,26 @@ * * @exception JspException if a JSP exception has occurred */ - public int doEndTag() throws JspException { + public int doAfterBody() throws JspException { - if (bodyContent == null) - return (EVAL_PAGE); + if (bodyContent != null) { + String value = bodyContent.getString().trim(); + if (value.length() > 0) + ResponseUtils.write(pageContext, value); + } + return (SKIP_BODY); - JspWriter writer = pageContext.getOut(); - try { - writer.println(bodyContent.getString().trim()); - } catch (IOException e) { - throw new JspException - (messages.getMessage("common.io", e.toString())); - } + } + + + /** + * Process the remainder of this page normally. + * + * @exception JspException if a JSP exception has occurred + */ + public int doEndTag() throws JspException { - // Continue evaluating this page - return (EVAL_PAGE); + return (EVAL_PAGE); }