You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by hu...@apache.org on 2006/02/10 22:01:32 UTC
svn commit: r376841 [4/6] -
/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MessagesTag.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MessagesTag.java?rev=376841&r1=376840&r2=376841&view=diff
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MessagesTag.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MessagesTag.java Fri Feb 10 13:01:28 2006
@@ -1,55 +1,55 @@
/*
- * $Id$
+ * $Id$
*
* Copyright 1999-2005 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
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.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.taglib.TagUtils;
import org.apache.struts.util.MessageResources;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.BodyTagSupport;
+
+import java.util.Iterator;
+
/**
- * Custom tag that iterates the elements of a message collection.
- * 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>Globals.MESSAGE_KEY</code>. This is an alternative
- * to the default <code>ErrorsTag</code>.
+ * Custom tag that iterates the elements of a message collection. 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>Globals.MESSAGE_KEY</code>. This is an alternative to the default
+ * <code>ErrorsTag</code>.
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-11-08 23:50:53 -0500 (Tue, 08 Nov 2005)
+ * $
* @since Struts 1.1
*/
public class MessagesTag extends BodyTagSupport {
-
/**
* The message resources for this package.
*/
protected static MessageResources messageResources =
- MessageResources.getMessageResources(Constants.Package + ".LocalStrings");
+ MessageResources.getMessageResources(Constants.Package
+ + ".LocalStrings");
/**
- * Iterator of the elements of this error collection, while we are actually
- * running.
+ * Iterator of the elements of this error collection, while we are
+ * actually running.
*/
protected Iterator iterator = null;
@@ -95,8 +95,8 @@
protected String footer = null;
/**
- * If this is set to 'true', then the <code>Globals.MESSAGE_KEY</code> will
- * be used to retrieve the messages from scope.
+ * 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;
@@ -165,10 +165,10 @@
}
/**
- * Construct an iterator for the specified collection, and begin
- * looping through the body once per element.
+ * Construct an iterator for the specified collection, and begin looping
+ * through the body once per element.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
// Initialize for a new request.
@@ -180,20 +180,21 @@
// Make a local copy of the name attribute that we can modify.
String name = this.name;
- if (message != null && "true".equalsIgnoreCase(message)) {
+ if ((message != null) && "true".equalsIgnoreCase(message)) {
name = Globals.MESSAGE_KEY;
}
try {
- messages = TagUtils.getInstance().getActionMessages(pageContext, name);
-
+ messages =
+ TagUtils.getInstance().getActionMessages(pageContext, name);
} catch (JspException e) {
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
// Acquire the collection we are going to iterate over
- this.iterator = (property == null) ? messages.get() : messages.get(property);
+ this.iterator =
+ (property == null) ? messages.get() : messages.get(property);
// Store the first value and evaluate, or skip the body if none
if (!this.iterator.hasNext()) {
@@ -201,11 +202,12 @@
}
// process the first message
- processMessage((ActionMessage)iterator.next());
+ processMessage((ActionMessage) iterator.next());
- if (header != null && header.length() > 0) {
+ if ((header != null) && (header.length() > 0)) {
String headerMessage =
- TagUtils.getInstance().message(pageContext, bundle, locale, header);
+ TagUtils.getInstance().message(pageContext, bundle, locale,
+ header);
if (headerMessage != null) {
TagUtils.getInstance().write(pageContext, headerMessage);
@@ -220,93 +222,90 @@
}
/**
- * Make the next collection element available and loop, or
- * finish the iterations if there are no more elements.
+ * Make the next collection element available and loop, or finish the
+ * iterations if there are no more elements.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doAfterBody() throws JspException {
// Render the output from this iteration to the output stream
if (bodyContent != null) {
- TagUtils.getInstance().writePrevious(pageContext, bodyContent.getString());
+ TagUtils.getInstance().writePrevious(pageContext,
+ bodyContent.getString());
bodyContent.clearBody();
}
// Decide whether to iterate or quit
if (iterator.hasNext()) {
- processMessage((ActionMessage)iterator.next());
- return (EVAL_BODY_TAG);
+ processMessage((ActionMessage) iterator.next());
+
+ return (EVAL_BODY_TAG);
} else {
- return (SKIP_BODY);
+ return (SKIP_BODY);
}
-
}
/**
* Process a message.
*/
- private void processMessage(ActionMessage report) throws JspException {
-
+ private void processMessage(ActionMessage report)
+ throws JspException {
String msg = null;
+
if (report.isResource()) {
- msg = TagUtils.getInstance().message(
- pageContext,
- bundle,
- locale,
- report.getKey(),
- report.getValues());
+ msg = TagUtils.getInstance().message(pageContext, bundle, locale,
+ report.getKey(), report.getValues());
+
if (msg == null) {
- String bundleName = bundle == null ? "default" : bundle;
- msg = messageResources.getMessage("messagesTag.notfound",
- report.getKey(), bundleName);
+ String bundleName = (bundle == null) ? "default" : bundle;
+
+ msg = messageResources.getMessage("messagesTag.notfound",
+ report.getKey(), bundleName);
}
} else {
msg = report.getKey();
}
- if (msg == null) {
- pageContext.removeAttribute(id);
- } else {
- pageContext.setAttribute(id, msg);
- }
-
+ if (msg == null) {
+ pageContext.removeAttribute(id);
+ } else {
+ pageContext.setAttribute(id, msg);
+ }
}
/**
* Clean up after processing this enumeration.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doEndTag() throws JspException {
- if (processed && footer != null && footer.length() > 0) {
-
- String footerMessage =
- TagUtils.getInstance().message(pageContext, bundle, locale, footer);
+ if (processed && (footer != null) && (footer.length() > 0)) {
+ String footerMessage =
+ TagUtils.getInstance().message(pageContext, bundle, locale,
+ footer);
- if (footerMessage != null) {
- TagUtils.getInstance().write(pageContext, footerMessage);
- }
- }
+ if (footerMessage != null) {
+ TagUtils.getInstance().write(pageContext, footerMessage);
+ }
+ }
- return EVAL_PAGE;
+ return EVAL_PAGE;
}
-
/**
* Release all allocated resources.
*/
public void release() {
- super.release();
- iterator = null;
- processed = false;
- id = null;
- bundle = null;
- locale = Globals.LOCALE_KEY;
- name = Globals.ERROR_KEY;
- property = null;
- header = null;
- footer = null;
- message = null;
+ super.release();
+ iterator = null;
+ processed = false;
+ id = null;
+ bundle = null;
+ locale = Globals.LOCALE_KEY;
+ name = Globals.ERROR_KEY;
+ property = null;
+ header = null;
+ footer = null;
+ message = null;
}
-
}
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MessagesTei.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MessagesTei.java?rev=376841&r1=376840&r2=376841&view=diff
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MessagesTei.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MessagesTei.java Fri Feb 10 13:01:28 2006
@@ -1,51 +1,40 @@
/*
- * $Id$
+ * $Id$
*
* Copyright 1999,2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.struts.taglib.html;
import javax.servlet.jsp.tagext.TagData;
import javax.servlet.jsp.tagext.TagExtraInfo;
import javax.servlet.jsp.tagext.VariableInfo;
-
/**
- * Implementation of <code>TagExtraInfo</code> for the <b>messages</b>
- * tag, identifying the scripting object(s) to be made visible.
- *
-*/
+ * Implementation of <code>TagExtraInfo</code> for the <b>messages</b> tag,
+ * identifying the scripting object(s) to be made visible.
+ */
public class MessagesTei extends TagExtraInfo {
-
-
/**
* Return information about the scripting variables to be created.
*/
public VariableInfo[] getVariableInfo(TagData data) {
String type = "java.lang.String";
- return new VariableInfo[] {
- new VariableInfo(data.getAttributeString("id"),
- type,
- true,
- VariableInfo.NESTED)
- };
-
+ return new VariableInfo[] {
+ new VariableInfo(data.getAttributeString("id"), type, true,
+ VariableInfo.NESTED)
+ };
}
-
-
}
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MultiboxTag.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MultiboxTag.java?rev=376841&r1=376840&r2=376841&view=diff
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MultiboxTag.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/MultiboxTag.java Fri Feb 10 13:01:28 2006
@@ -1,33 +1,32 @@
/*
- * $Id$
+ * $Id$
*
* Copyright 2001-2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
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.Globals;
import org.apache.struts.taglib.TagUtils;
import org.apache.struts.util.MessageResources;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.PageContext;
+
+import java.lang.reflect.InvocationTargetException;
+
/**
* Tag for input fields of type "checkbox". This differs from CheckboxTag
* because it assumes that the underlying property is an array getter (of any
@@ -35,58 +34,56 @@
* "checked" if the value listed for the "value" attribute is present in the
* values returned by the property getter.
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
+ * $
*/
-
public class MultiboxTag extends BaseHandlerTag {
+ /**
+ * The message resources for this package.
+ */
+ protected static MessageResources messages =
+ MessageResources.getMessageResources(Constants.Package
+ + ".LocalStrings");
// ----------------------------------------------------- Instance Variables
/**
- * The constant String value to be returned when this checkbox is
- * selected and the form is submitted.
+ * 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");
-
- /**
* The name of the bean containing our underlying property.
*/
protected String name = Constants.BEAN_KEY;
- public String getName() {
- return (this.name);
- }
-
- public void setName(String 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.
+ * The value which will mark this checkbox as "checked" if present in the
+ * array returned by our property getter.
*/
protected String value = null;
+ public String getName() {
+ return (this.name);
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
// ------------------------------------------------------------- Properties
/**
* Return the property name.
*/
public String getProperty() {
-
return (this.property);
-
}
/**
@@ -95,18 +92,14 @@
* @param property The new property name
*/
public void setProperty(String property) {
-
this.property = property;
-
}
/**
* Return the server value.
*/
public String getValue() {
-
return (this.value);
-
}
/**
@@ -115,9 +108,7 @@
* @param value The new server value
*/
public void setValue(String value) {
-
this.value = value;
-
}
// --------------------------------------------------------- Public Methods
@@ -125,49 +116,48 @@
/**
* Process the beginning of this tag.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
-
// 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.
+ * Save the body contents of this tag as the constant that we will be
+ * returning.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doAfterBody() throws JspException {
-
if (bodyContent != null) {
this.constant = bodyContent.getString().trim();
}
-
+
if ("".equals(this.constant)) {
this.constant = null;
}
-
+
return SKIP_BODY;
}
/**
* Render an input element for this tag.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doEndTag() throws JspException {
-
// Create an appropriate "input" element based on our parameters
StringBuffer results = new StringBuffer("<input type=\"checkbox\"");
prepareAttribute(results, "name", prepareName());
prepareAttribute(results, "accesskey", getAccesskey());
prepareAttribute(results, "tabindex", getTabindex());
+
String value = prepareValue(results);
+
prepareChecked(results, value);
results.append(prepareEventHandlers());
results.append(prepareStyles());
@@ -179,85 +169,89 @@
return EVAL_PAGE;
}
-
/**
* Prepare the name element
+ *
* @return The element name.
*/
- protected String prepareName() throws JspException {
-
+ protected String prepareName()
+ throws JspException {
return property;
-
}
/**
* Render the value element
+ *
* @param results The StringBuffer that output will be appended to.
*/
- protected String prepareValue(StringBuffer results) throws JspException {
-
+ protected String prepareValue(StringBuffer results)
+ throws JspException {
String value = (this.value == null) ? this.constant : this.value;
+
if (value == null) {
- JspException e = new JspException(messages.getMessage("multiboxTag.value"));
- pageContext.setAttribute(Globals.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;
}
prepareAttribute(results, "value", TagUtils.getInstance().filter(value));
return value;
-
}
/**
* Render the checked element
+ *
* @param results The StringBuffer that output will be appended to.
*/
- protected void prepareChecked(StringBuffer results, String value) throws JspException {
-
+ protected void prepareChecked(StringBuffer results, String value)
+ throws JspException {
Object bean = TagUtils.getInstance().lookup(pageContext, name, null);
- String values[] = null;
-
+ 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));
+ 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()));
+
+ throw new JspException(messages.getMessage("getter.result",
+ property, t.toString()));
} catch (NoSuchMethodException e) {
- throw new JspException(messages.getMessage("getter.method", property, name));
+ 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;
}
}
-
}
-
/**
* Release any acquired resources.
*/
public void release() {
-
super.release();
constant = null;
name = Constants.BEAN_KEY;
property = null;
value = null;
-
}
-
}
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/OptionTag.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/OptionTag.java?rev=376841&r1=376840&r2=376841&view=diff
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/OptionTag.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/OptionTag.java Fri Feb 10 13:01:28 2006
@@ -1,48 +1,46 @@
/*
- * $Id$
+ * $Id$
*
* Copyright 1999-2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
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.Globals;
import org.apache.struts.taglib.TagUtils;
import org.apache.struts.util.MessageResources;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.BodyTagSupport;
+
/**
- * Tag for select options. The body of this tag is presented to the user
- * in the option list, while the value attribute is the value returned to
- * the server if this option is selected.
+ * Tag for select options. The body of this tag is presented to the user in
+ * the option list, while the value attribute is the value returned to the
+ * server if this option is selected.
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-08-21 19:08:45 -0400 (Sun, 21 Aug 2005)
+ * $
*/
public class OptionTag extends BodyTagSupport {
-
// ----------------------------------------------------- Instance Variables
/**
* The message resources for this package.
*/
protected static MessageResources messages =
- MessageResources.getMessageResources(Constants.Package + ".LocalStrings");
+ MessageResources.getMessageResources(Constants.Package
+ + ".LocalStrings");
/**
* The message text to be displayed to the user for this tag (if any)
@@ -57,6 +55,45 @@
*/
protected String bundle = Globals.MESSAGES_KEY;
+ /**
+ * Is this option disabled?
+ */
+ protected boolean disabled = false;
+
+ /**
+ * The key used to look up the text displayed to the user for this option,
+ * if any.
+ */
+ protected String key = null;
+
+ /**
+ * The name of the attribute containing the Locale to be used for looking
+ * up internationalized messages.
+ */
+ protected String locale = Globals.LOCALE_KEY;
+
+ /**
+ * The style associated with this tag.
+ */
+ private String style = null;
+
+ /**
+ * The named style class associated with this tag.
+ */
+ private String styleClass = null;
+
+ /**
+ * The identifier associated with this tag.
+ */
+ protected String styleId = null;
+
+ /**
+ * The server value for this option, also used to match against the
+ * current property value to determine whether this option should be
+ * marked as selected.
+ */
+ protected String value = null;
+
public String getBundle() {
return (this.bundle);
}
@@ -65,11 +102,6 @@
this.bundle = bundle;
}
- /**
- * Is this option disabled?
- */
- protected boolean disabled = false;
-
public boolean getDisabled() {
return (this.disabled);
}
@@ -78,12 +110,6 @@
this.disabled = disabled;
}
- /**
- * The key used to look up the text displayed to the user for this
- * option, if any.
- */
- protected String key = null;
-
public String getKey() {
return (this.key);
}
@@ -92,12 +118,6 @@
this.key = key;
}
- /**
- * The name of the attribute containing the Locale to be used for
- * looking up internationalized messages.
- */
- protected String locale = Globals.LOCALE_KEY;
-
public String getLocale() {
return (this.locale);
}
@@ -106,11 +126,6 @@
this.locale = locale;
}
- /**
- * The style associated with this tag.
- */
- private String style = null;
-
public String getStyle() {
return style;
}
@@ -119,11 +134,6 @@
this.style = style;
}
- /**
- * The named style class associated with this tag.
- */
- private String styleClass = null;
-
public String getStyleClass() {
return styleClass;
}
@@ -133,17 +143,10 @@
}
/**
- * The identifier associated with this tag.
- */
- protected String styleId = null;
-
- /**
* Return the style identifier for this tag.
*/
public String getStyleId() {
-
return (this.styleId);
-
}
/**
@@ -152,18 +155,9 @@
* @param styleId The new style identifier
*/
public void setStyleId(String styleId) {
-
this.styleId = styleId;
-
}
- /**
- * The server value for this option, also used to match against the
- * current property value to determine whether this option should be
- * marked as selected.
- */
- protected String value = null;
-
public String getValue() {
return (this.value);
}
@@ -177,45 +171,43 @@
/**
* Process the start of this tag.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
-
// Initialize the placeholder for our body content
this.text = null;
// Do nothing until doEndTag() is called
return (EVAL_BODY_TAG);
-
}
/**
* Process the body text of this tag (if any).
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doAfterBody() throws JspException {
-
if (bodyContent != null) {
String text = bodyContent.getString();
+
if (text != null) {
text = text.trim();
+
if (text.length() > 0) {
this.text = text;
}
}
}
- return (SKIP_BODY);
+ return (SKIP_BODY);
}
/**
* Process the end of this tag.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doEndTag() throws JspException {
-
TagUtils.getInstance().write(pageContext, this.renderOptionElement());
return (EVAL_PAGE);
@@ -223,59 +215,70 @@
/**
* Generate an HTML %lt;option> element.
+ *
* @throws JspException
* @since Struts 1.1
*/
- protected String renderOptionElement() throws JspException {
+ protected String renderOptionElement()
+ throws JspException {
StringBuffer results = new StringBuffer("<option value=\"");
-
+
results.append(this.value);
results.append("\"");
+
if (disabled) {
results.append(" disabled=\"disabled\"");
}
+
if (this.selectTag().isMatched(this.value)) {
results.append(" selected=\"selected\"");
}
+
if (style != null) {
results.append(" style=\"");
results.append(style);
results.append("\"");
}
+
if (styleId != null) {
results.append(" id=\"");
results.append(styleId);
results.append("\"");
}
+
if (styleClass != null) {
results.append(" class=\"");
results.append(styleClass);
results.append("\"");
}
+
results.append(">");
results.append(text());
-
+
results.append("</option>");
+
return results.toString();
}
/**
* Acquire the select tag we are associated with.
+ *
* @throws JspException
*/
- private SelectTag selectTag() throws JspException {
+ private SelectTag selectTag()
+ throws JspException {
SelectTag selectTag =
(SelectTag) pageContext.getAttribute(Constants.SELECT_KEY);
-
+
if (selectTag == null) {
JspException e =
new JspException(messages.getMessage("optionTag.select"));
-
+
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
-
+
return selectTag;
}
@@ -299,7 +302,7 @@
/**
* Return the text to be displayed to the user for this option (if any).
*
- * @exception JspException if an error occurs
+ * @throws JspException if an error occurs
*/
protected String text() throws JspException {
String optionText = this.text;
@@ -311,10 +314,9 @@
// no body text and no key to lookup so display the value
if (optionText == null) {
- optionText = this.value;
+ optionText = this.value;
}
return optionText;
}
-
}
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/OptionsCollectionTag.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/OptionsCollectionTag.java?rev=376841&r1=376840&r2=376841&view=diff
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/OptionsCollectionTag.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/OptionsCollectionTag.java Fri Feb 10 13:01:28 2006
@@ -1,62 +1,60 @@
/*
- * $Id$
+ * $Id$
*
* Copyright 2002-2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.struts.taglib.html;
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.struts.taglib.TagUtils;
+import org.apache.struts.util.IteratorAdapter;
+import org.apache.struts.util.MessageResources;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.TagSupport;
+
import java.lang.reflect.InvocationTargetException;
+
import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
-import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.tagext.TagSupport;
-
-import org.apache.commons.beanutils.PropertyUtils;
-import org.apache.struts.util.IteratorAdapter;
-import org.apache.struts.taglib.TagUtils;
-import org.apache.struts.util.MessageResources;
-
/**
* Tag for creating multiple <select> options from a collection. The
- * collection may be part of the enclosing form, or may be independent of
- * the form. Each element of the collection must expose a 'label' and a
- * 'value', the property names of which are configurable by attributes of
- * this tag.
- * <p>
- * The collection may be an array of objects, a Collection, an Enumeration,
- * an Iterator, or a Map.
- * <p>
- * <b>NOTE</b> - This tag requires a Java2 (JDK 1.2 or later) platform.
+ * collection may be part of the enclosing form, or may be independent of the
+ * form. Each element of the collection must expose a 'label' and a 'value',
+ * the property names of which are configurable by attributes of this tag. <p>
+ * The collection may be an array of objects, a Collection, an Enumeration, an
+ * Iterator, or a Map. <p> <b>NOTE</b> - This tag requires a Java2 (JDK 1.2 or
+ * later) platform.
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2004-11-03 14:20:47 -0500 (Wed, 03 Nov 2004)
+ * $
* @since Struts 1.1
*/
public class OptionsCollectionTag extends TagSupport {
-
// ----------------------------------------------------- Instance Variables
/**
* The message resources for this package.
*/
protected static MessageResources messages =
- MessageResources.getMessageResources(Constants.Package + ".LocalStrings");
+ MessageResources.getMessageResources(Constants.Package
+ + ".LocalStrings");
// ------------------------------------------------------------- Properties
@@ -65,6 +63,36 @@
*/
protected boolean filter = true;
+ /**
+ * The name of the bean property containing the label.
+ */
+ protected String label = "label";
+
+ /**
+ * The name of the bean containing the values collection.
+ */
+ protected String name = Constants.BEAN_KEY;
+
+ /**
+ * The name of the property to use to build the values collection.
+ */
+ protected String property = null;
+
+ /**
+ * The style associated with this tag.
+ */
+ private String style = null;
+
+ /**
+ * The named style class associated with this tag.
+ */
+ private String styleClass = null;
+
+ /**
+ * The name of the bean property containing the value.
+ */
+ protected String value = "value";
+
public boolean getFilter() {
return filter;
}
@@ -73,11 +101,6 @@
this.filter = filter;
}
- /**
- * The name of the bean property containing the label.
- */
- protected String label = "label";
-
public String getLabel() {
return label;
}
@@ -86,11 +109,6 @@
this.label = label;
}
- /**
- * The name of the bean containing the values collection.
- */
- protected String name = Constants.BEAN_KEY;
-
public String getName() {
return name;
}
@@ -99,11 +117,6 @@
this.name = name;
}
- /**
- * The name of the property to use to build the values collection.
- */
- protected String property = null;
-
public String getProperty() {
return property;
}
@@ -112,11 +125,6 @@
this.property = property;
}
- /**
- * The style associated with this tag.
- */
- private String style = null;
-
public String getStyle() {
return style;
}
@@ -125,11 +133,6 @@
this.style = style;
}
- /**
- * The named style class associated with this tag.
- */
- private String styleClass = null;
-
public String getStyleClass() {
return styleClass;
}
@@ -138,11 +141,6 @@
this.styleClass = styleClass;
}
- /**
- * The name of the bean property containing the value.
- */
- protected String value = "value";
-
public String getValue() {
return value;
}
@@ -156,25 +154,31 @@
/**
* Process the start of this tag.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
-
// Acquire the select tag we are associated with
- SelectTag selectTag = (SelectTag) pageContext.getAttribute(Constants.SELECT_KEY);
+ SelectTag selectTag =
+ (SelectTag) pageContext.getAttribute(Constants.SELECT_KEY);
if (selectTag == null) {
- JspException e = new JspException(messages.getMessage("optionsCollectionTag.select"));
+ JspException e =
+ new JspException(messages.getMessage(
+ "optionsCollectionTag.select"));
+
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
// Acquire the collection containing our options
- Object collection = TagUtils.getInstance().lookup(pageContext, name, property, null);
+ Object collection =
+ TagUtils.getInstance().lookup(pageContext, name, property, null);
if (collection == null) {
JspException e =
- new JspException(messages.getMessage("optionsCollectionTag.collection"));
+ new JspException(messages.getMessage(
+ "optionsCollectionTag.collection"));
+
TagUtils.getInstance().saveException(pageContext, e);
throw e;
}
@@ -186,7 +190,6 @@
// Render the options
while (iter.hasNext()) {
-
Object bean = iter.next();
Object beanLabel = null;
Object beanValue = null;
@@ -194,23 +197,30 @@
// Get the label for this option
try {
beanLabel = PropertyUtils.getProperty(bean, label);
+
if (beanLabel == null) {
beanLabel = "";
}
} catch (IllegalAccessException e) {
JspException jspe =
- new JspException(messages.getMessage("getter.access", label, bean));
+ new JspException(messages.getMessage("getter.access",
+ label, bean));
+
TagUtils.getInstance().saveException(pageContext, jspe);
throw jspe;
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
JspException jspe =
- new JspException(messages.getMessage("getter.result", label, t.toString()));
+ new JspException(messages.getMessage("getter.result",
+ label, t.toString()));
+
TagUtils.getInstance().saveException(pageContext, jspe);
throw jspe;
} catch (NoSuchMethodException e) {
JspException jspe =
- new JspException(messages.getMessage("getter.method", label, bean));
+ new JspException(messages.getMessage("getter.method",
+ label, bean));
+
TagUtils.getInstance().saveException(pageContext, jspe);
throw jspe;
}
@@ -218,23 +228,30 @@
// Get the value for this option
try {
beanValue = PropertyUtils.getProperty(bean, value);
+
if (beanValue == null) {
beanValue = "";
}
} catch (IllegalAccessException e) {
JspException jspe =
- new JspException(messages.getMessage("getter.access", value, bean));
+ new JspException(messages.getMessage("getter.access",
+ value, bean));
+
TagUtils.getInstance().saveException(pageContext, jspe);
throw jspe;
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
JspException jspe =
- new JspException(messages.getMessage("getter.result", value, t.toString()));
+ new JspException(messages.getMessage("getter.result",
+ value, t.toString()));
+
TagUtils.getInstance().saveException(pageContext, jspe);
throw jspe;
} catch (NoSuchMethodException e) {
JspException jspe =
- new JspException(messages.getMessage("getter.method", value, bean));
+ new JspException(messages.getMessage("getter.method",
+ value, bean));
+
TagUtils.getInstance().saveException(pageContext, jspe);
throw jspe;
}
@@ -243,7 +260,8 @@
String stringValue = beanValue.toString();
// Render this option
- addOption(sb, stringLabel, stringValue, selectTag.isMatched(stringValue));
+ addOption(sb, stringLabel, stringValue,
+ selectTag.isMatched(stringValue));
}
TagUtils.getInstance().write(pageContext, sb.toString());
@@ -269,86 +287,83 @@
/**
* Add an option element to the specified StringBuffer based on the
- * specified parameters.
- *<p>
- * Note that this tag specifically does not support the
- * <code>styleId</code> tag attribute, which causes the HTML
+ * specified parameters. <p> Note that this tag specifically does not
+ * support the <code>styleId</code> tag attribute, which causes the HTML
* <code>id</code> attribute to be emitted. This is because the HTML
* specification states that all "id" attributes in a document have to be
- * unique. This tag will likely generate more than one <code>option</code>
- * element element, but it cannot use the same <code>id</code> value. It's
- * conceivable some sort of mechanism to supply an array of <code>id</code>
- * values could be devised, but that doesn't seem to be worth the trouble.
+ * unique. This tag will likely generate more than one
+ * <code>option</code> element element, but it cannot use the same
+ * <code>id</code> value. It's conceivable some sort of mechanism to
+ * supply an array of <code>id</code> values could be devised, but that
+ * doesn't seem to be worth the trouble.
*
- * @param sb StringBuffer accumulating our results
- * @param value Value to be returned to the server for this option
- * @param label Value to be shown to the user for this option
+ * @param sb StringBuffer accumulating our results
+ * @param value Value to be returned to the server for this option
+ * @param label Value to be shown to the user for this option
* @param matched Should this value be marked as selected?
*/
- protected void addOption(StringBuffer sb, String label, String value, boolean matched) {
-
+ protected void addOption(StringBuffer sb, String label, String value,
+ boolean matched) {
sb.append("<option value=\"");
+
if (filter) {
sb.append(TagUtils.getInstance().filter(value));
} else {
sb.append(value);
}
+
sb.append("\"");
+
if (matched) {
sb.append(" selected=\"selected\"");
}
+
if (style != null) {
sb.append(" style=\"");
sb.append(style);
sb.append("\"");
}
+
if (styleClass != null) {
sb.append(" class=\"");
sb.append(styleClass);
sb.append("\"");
}
-
+
sb.append(">");
-
+
if (filter) {
sb.append(TagUtils.getInstance().filter(label));
} else {
sb.append(label);
}
-
- sb.append("</option>\r\n");
+ sb.append("</option>\r\n");
}
/**
* Return an iterator for the options collection.
*
* @param collection Collection to be iterated over
- *
- * @exception JspException if an error occurs
+ * @throws JspException if an error occurs
*/
- protected Iterator getIterator(Object collection) throws JspException {
-
+ protected Iterator getIterator(Object collection)
+ throws JspException {
if (collection.getClass().isArray()) {
collection = Arrays.asList((Object[]) collection);
}
if (collection instanceof Collection) {
return (((Collection) collection).iterator());
-
} else if (collection instanceof Iterator) {
return ((Iterator) collection);
-
} else if (collection instanceof Map) {
return (((Map) collection).entrySet().iterator());
-
} else if (collection instanceof Enumeration) {
return new IteratorAdapter((Enumeration) collection);
-
} else {
- throw new JspException(
- messages.getMessage("optionsCollectionTag.iterator", collection.toString()));
+ throw new JspException(messages.getMessage(
+ "optionsCollectionTag.iterator", collection.toString()));
}
}
-
}
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/OptionsTag.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/OptionsTag.java?rev=376841&r1=376840&r2=376841&view=diff
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/OptionsTag.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/OptionsTag.java Fri Feb 10 13:01:28 2006
@@ -1,55 +1,53 @@
/*
- * $Id$
+ * $Id$
*
* Copyright 1999-2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.struts.taglib.html;
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.struts.taglib.TagUtils;
+import org.apache.struts.util.IteratorAdapter;
+import org.apache.struts.util.MessageResources;
+
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.tagext.TagSupport;
+
import java.lang.reflect.InvocationTargetException;
+
import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
-import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.tagext.TagSupport;
-
-import org.apache.commons.beanutils.PropertyUtils;
-import org.apache.struts.util.IteratorAdapter;
-import org.apache.struts.taglib.TagUtils;
-import org.apache.struts.util.MessageResources;
-
/**
* Tag for creating multiple <select> options from a collection. The
* associated values displayed to the user may optionally be specified by a
* second collection, or will be the same as the values themselves. Each
- * collection may be an array of objects, a Collection, an Enumeration,
- * an Iterator, or a Map.
- * <b>NOTE</b> - This tag requires a Java2 (JDK 1.2 or later) platform.
- *
+ * collection may be an array of objects, a Collection, an Enumeration, an
+ * Iterator, or a Map. <b>NOTE</b> - This tag requires a Java2 (JDK 1.2 or
+ * later) platform.
*/
-
public class OptionsTag extends TagSupport {
-
/**
* The message resources for this package.
*/
protected static MessageResources messages =
- MessageResources.getMessageResources(Constants.Package + ".LocalStrings");
+ MessageResources.getMessageResources(Constants.Package
+ + ".LocalStrings");
/**
* The name of the collection containing beans that have properties to
@@ -58,6 +56,41 @@
*/
protected String collection = null;
+ /**
+ * Should the label values be filtered for HTML sensitive characters?
+ */
+ protected boolean filter = true;
+
+ /**
+ * The name of the bean containing the labels collection.
+ */
+ protected String labelName = null;
+
+ /**
+ * The bean property containing the labels collection.
+ */
+ protected String labelProperty = null;
+
+ /**
+ * The name of the bean containing the values collection.
+ */
+ protected String name = null;
+
+ /**
+ * The name of the property to use to build the values collection.
+ */
+ protected String property = null;
+
+ /**
+ * The style associated with this tag.
+ */
+ private String style = null;
+
+ /**
+ * The named style class associated with this tag.
+ */
+ private String styleClass = null;
+
public String getCollection() {
return (this.collection);
}
@@ -66,11 +99,6 @@
this.collection = collection;
}
- /**
- * Should the label values be filtered for HTML sensitive characters?
- */
- protected boolean filter = true;
-
public boolean getFilter() {
return filter;
}
@@ -79,11 +107,6 @@
this.filter = filter;
}
- /**
- * The name of the bean containing the labels collection.
- */
- protected String labelName = null;
-
public String getLabelName() {
return labelName;
}
@@ -92,11 +115,6 @@
this.labelName = labelName;
}
- /**
- * The bean property containing the labels collection.
- */
- protected String labelProperty = null;
-
public String getLabelProperty() {
return labelProperty;
}
@@ -105,11 +123,6 @@
this.labelProperty = labelProperty;
}
- /**
- * The name of the bean containing the values collection.
- */
- protected String name = null;
-
public String getName() {
return name;
}
@@ -118,11 +131,6 @@
this.name = name;
}
- /**
- * The name of the property to use to build the values collection.
- */
- protected String property = null;
-
public String getProperty() {
return property;
}
@@ -131,11 +139,6 @@
this.property = property;
}
- /**
- * The style associated with this tag.
- */
- private String style = null;
-
public String getStyle() {
return style;
}
@@ -144,11 +147,6 @@
this.style = style;
}
- /**
- * The named style class associated with this tag.
- */
- private String styleClass = null;
-
public String getStyleClass() {
return styleClass;
}
@@ -160,9 +158,8 @@
/**
* Process the start of this tag.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
-
public int doStartTag() throws JspException {
return SKIP_BODY;
}
@@ -170,41 +167,45 @@
/**
* Process the end of this tag.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doEndTag() throws JspException {
-
// Acquire the select tag we are associated with
- SelectTag selectTag = (SelectTag) pageContext.getAttribute(Constants.SELECT_KEY);
+ SelectTag selectTag =
+ (SelectTag) pageContext.getAttribute(Constants.SELECT_KEY);
+
if (selectTag == null) {
throw new JspException(messages.getMessage("optionsTag.select"));
}
+
StringBuffer sb = new StringBuffer();
// If a collection was specified, use that mode to render options
if (collection != null) {
Iterator collIterator = getIterator(collection, null);
- while (collIterator.hasNext()) {
+ while (collIterator.hasNext()) {
Object bean = collIterator.next();
Object value = null;
Object label = null;
try {
value = PropertyUtils.getProperty(bean, property);
+
if (value == null) {
value = "";
}
} catch (IllegalAccessException e) {
- throw new JspException(
- messages.getMessage("getter.access", property, collection));
+ throw new JspException(messages.getMessage(
+ "getter.access", property, collection));
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
- throw new JspException(
- messages.getMessage("getter.result", property, t.toString()));
+
+ throw new JspException(messages.getMessage(
+ "getter.result", property, t.toString()));
} catch (NoSuchMethodException e) {
- throw new JspException(
- messages.getMessage("getter.method", property, collection));
+ throw new JspException(messages.getMessage(
+ "getter.method", property, collection));
}
try {
@@ -218,30 +219,30 @@
label = "";
}
} catch (IllegalAccessException e) {
- throw new JspException(
- messages.getMessage("getter.access", labelProperty, collection));
+ throw new JspException(messages.getMessage(
+ "getter.access", labelProperty, collection));
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
- throw new JspException(
- messages.getMessage("getter.result", labelProperty, t.toString()));
+
+ throw new JspException(messages.getMessage(
+ "getter.result", labelProperty, t.toString()));
} catch (NoSuchMethodException e) {
- throw new JspException(
- messages.getMessage("getter.method", labelProperty, collection));
+ throw new JspException(messages.getMessage(
+ "getter.method", labelProperty, collection));
}
String stringValue = value.toString();
- addOption(sb, stringValue, label.toString(), selectTag.isMatched(stringValue));
+ addOption(sb, stringValue, label.toString(),
+ selectTag.isMatched(stringValue));
}
-
}
-
// Otherwise, use the separate iterators mode to render options
else {
-
// Construct iterators for the values and labels collections
Iterator valuesIterator = getIterator(name, property);
Iterator labelsIterator = null;
+
if ((labelName != null) || (labelProperty != null)) {
labelsIterator = getIterator(labelName, labelProperty);
}
@@ -249,18 +250,24 @@
// Render the options tags for each element of the values coll.
while (valuesIterator.hasNext()) {
Object valueObject = valuesIterator.next();
+
if (valueObject == null) {
valueObject = "";
}
+
String value = valueObject.toString();
String label = value;
+
if ((labelsIterator != null) && labelsIterator.hasNext()) {
Object labelObject = labelsIterator.next();
+
if (labelObject == null) {
labelObject = "";
}
+
label = labelObject.toString();
}
+
addOption(sb, value, label, selectTag.isMatched(value));
}
}
@@ -268,14 +275,12 @@
TagUtils.getInstance().write(pageContext, sb.toString());
return EVAL_PAGE;
-
}
/**
* Release any acquired resources.
*/
public void release() {
-
super.release();
collection = null;
filter = true;
@@ -291,95 +296,106 @@
/**
* Add an option element to the specified StringBuffer based on the
- * specified parameters.
- *<p>
- * Note that this tag specifically does not support the
- * <code>styleId</code> tag attribute, which causes the HTML
+ * specified parameters. <p> Note that this tag specifically does not
+ * support the <code>styleId</code> tag attribute, which causes the HTML
* <code>id</code> attribute to be emitted. This is because the HTML
* specification states that all "id" attributes in a document have to be
- * unique. This tag will likely generate more than one <code>option</code>
- * element element, but it cannot use the same <code>id</code> value. It's
- * conceivable some sort of mechanism to supply an array of <code>id</code>
- * values could be devised, but that doesn't seem to be worth the trouble.
+ * unique. This tag will likely generate more than one
+ * <code>option</code> element element, but it cannot use the same
+ * <code>id</code> value. It's conceivable some sort of mechanism to
+ * supply an array of <code>id</code> values could be devised, but that
+ * doesn't seem to be worth the trouble.
*
- * @param sb StringBuffer accumulating our results
- * @param value Value to be returned to the server for this option
- * @param label Value to be shown to the user for this option
+ * @param sb StringBuffer accumulating our results
+ * @param value Value to be returned to the server for this option
+ * @param label Value to be shown to the user for this option
* @param matched Should this value be marked as selected?
*/
- protected void addOption(StringBuffer sb, String value, String label, boolean matched) {
-
+ protected void addOption(StringBuffer sb, String value, String label,
+ boolean matched) {
sb.append("<option value=\"");
+
if (filter) {
sb.append(TagUtils.getInstance().filter(value));
} else {
sb.append(value);
}
+
sb.append("\"");
+
if (matched) {
sb.append(" selected=\"selected\"");
}
+
if (style != null) {
sb.append(" style=\"");
sb.append(style);
sb.append("\"");
}
+
if (styleClass != null) {
sb.append(" class=\"");
sb.append(styleClass);
sb.append("\"");
}
-
+
sb.append(">");
-
+
if (filter) {
sb.append(TagUtils.getInstance().filter(label));
} else {
sb.append(label);
}
-
- sb.append("</option>\r\n");
+ sb.append("</option>\r\n");
}
/**
* Return an iterator for the option labels or values, based on our
* configured properties.
*
- * @param name Name of the bean attribute (if any)
+ * @param name Name of the bean attribute (if any)
* @param property Name of the bean property (if any)
- *
- * @exception JspException if an error occurs
+ * @throws JspException if an error occurs
*/
- protected Iterator getIterator(String name, String property) throws JspException {
-
+ protected Iterator getIterator(String name, String property)
+ throws JspException {
// Identify the bean containing our collection
String beanName = name;
+
if (beanName == null) {
beanName = Constants.BEAN_KEY;
}
- Object bean = TagUtils.getInstance().lookup(pageContext, beanName, null);
+ Object bean =
+ TagUtils.getInstance().lookup(pageContext, beanName, null);
+
if (bean == null) {
throw new JspException(messages.getMessage("getter.bean", beanName));
}
// Identify the collection itself
Object collection = bean;
+
if (property != null) {
try {
collection = PropertyUtils.getProperty(bean, property);
+
if (collection == null) {
- throw new JspException(messages.getMessage("getter.property", property));
+ throw new JspException(messages.getMessage(
+ "getter.property", property));
}
} catch (IllegalAccessException e) {
- throw new JspException(messages.getMessage("getter.access", property, name));
+ 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()));
+
+ throw new JspException(messages.getMessage("getter.result",
+ property, t.toString()));
} catch (NoSuchMethodException e) {
- throw new JspException(messages.getMessage("getter.method", property, name));
+ throw new JspException(messages.getMessage("getter.method",
+ property, name));
}
}
@@ -390,20 +406,15 @@
if (collection instanceof Collection) {
return (((Collection) collection).iterator());
-
} else if (collection instanceof Iterator) {
return ((Iterator) collection);
-
} else if (collection instanceof Map) {
return (((Map) collection).entrySet().iterator());
-
} else if (collection instanceof Enumeration) {
return new IteratorAdapter((Enumeration) collection);
-
} else {
- throw new JspException(
- messages.getMessage("optionsTag.iterator", collection.toString()));
+ throw new JspException(messages.getMessage("optionsTag.iterator",
+ collection.toString()));
}
}
-
}
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/PasswordTag.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/PasswordTag.java?rev=376841&r1=376840&r2=376841&view=diff
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/PasswordTag.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/PasswordTag.java Fri Feb 10 13:01:28 2006
@@ -1,30 +1,30 @@
/*
- * $Id$
+ * $Id$
*
* Copyright 1999-2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.struts.taglib.html;
+
/**
* Custom tag for input fields of type "password".
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-04-06 02:37:00 -0400 (Wed, 06 Apr 2005)
+ * $
*/
public class PasswordTag extends BaseFieldTag {
-
/**
* Construct a new instance of this tag.
*/
@@ -33,5 +33,4 @@
this.type = "password";
doReadonly = true;
}
-
}
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/RadioTag.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/RadioTag.java?rev=376841&r1=376840&r2=376841&view=diff
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/RadioTag.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/RadioTag.java Fri Feb 10 13:01:28 2006
@@ -1,101 +1,88 @@
/*
- * $Id$
+ * $Id$
*
* Copyright 1999-2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.struts.taglib.html;
-import javax.servlet.jsp.JspException;
-
import org.apache.struts.taglib.TagUtils;
import org.apache.struts.util.MessageResources;
+import javax.servlet.jsp.JspException;
+
/**
* Tag for input fields of type "radio".
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-06-14 14:26:17 -0400 (Tue, 14 Jun 2005)
+ * $
*/
public class RadioTag extends BaseHandlerTag {
-
-
// ----------------------------------------------------- Instance Variables
-
/**
* 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.
*/
protected String name = Constants.BEAN_KEY;
- public String getName() {
- return (this.name);
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
-
/**
* The property name for this field.
*/
protected String property = null;
-
/**
* The body content of this tag (if any).
*/
protected String text = null;
-
/**
* The server value for this option.
*/
protected String value = null;
-
/**
- * Name of the bean (in some scope) that will return the
- * value of the radio tag.
- * <p>
- * If an iterator is used to render a series of radio tags,
- * this field may be used to specify the name of the bean
- * exposed by the iterator. In this case, the value attribute is
- * used as the name of a property on the <code>idName</code> bean
- * that returns the value of the radio tag in this iteration.
+ * Name of the bean (in some scope) that will return the value of the
+ * radio tag. <p> If an iterator is used to render a series of radio tags,
+ * this field may be used to specify the name of the bean exposed by the
+ * iterator. In this case, the value attribute is used as the name of a
+ * property on the <code>idName</code> bean that returns the value of the
+ * radio tag in this iteration.
*/
protected String idName = null;
+ public String getName() {
+ return (this.name);
+ }
- // ------------------------------------------------------------- Properties
+ public void setName(String name) {
+ this.name = name;
+ }
+ // ------------------------------------------------------------- Properties
/**
* Return the property name.
*/
public String getProperty() {
-
return (this.property);
-
}
/**
@@ -104,18 +91,14 @@
* @param property The new property name
*/
public void setProperty(String property) {
-
this.property = property;
-
}
/**
* Return the server value.
*/
public String getValue() {
-
return (this.value);
-
}
/**
@@ -124,179 +107,176 @@
* @param value The new server value
*/
public void setValue(String value) {
-
this.value = value;
-
}
/**
* Return the idName.
+ *
* @since Struts 1.1
*/
public String getIdName() {
-
return (this.idName);
-
}
/**
* Set the idName.
- * @since Struts 1.1
*
* @param idName The new idName
+ * @since Struts 1.1
*/
public void setIdName(String idName) {
-
- this.idName=idName;
-
+ this.idName = idName;
}
-
// --------------------------------------------------------- Public Methods
-
/**
- * Generate the required input tag.
- * [Indexed property since Struts 1.1]
+ * Generate the required input tag. [Indexed property since Struts 1.1]
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
-
String radioTag = renderRadioElement(serverValue(), currentValue());
TagUtils.getInstance().write(pageContext, radioTag);
this.text = null;
+
return (EVAL_BODY_TAG);
}
/**
- * Return the String to be used in the radio tag's <code>value</code> attribute
- * that gets sent to the server on form submission.
+ * Return the String to be used in the radio tag's <code>value</code>
+ * attribute that gets sent to the server on form submission.
+ *
* @throws JspException
*/
- private String serverValue() throws JspException {
-
+ private String serverValue()
+ throws JspException {
// Not using indexed radio buttons
if (this.idName == null) {
return this.value;
}
-
+
String serverValue = this.lookupProperty(this.idName, this.value);
-
+
return (serverValue == null) ? "" : serverValue;
}
/**
- * Acquire the current value of the bean specified by the <code>name</code>
- * attribute and the property specified by the <code>property</code> attribute.
- * This radio button with this value will be checked.
+ * Acquire the current value of the bean specified by the
+ * <code>name</code> attribute and the property specified by the
+ * <code>property</code> attribute. This radio button with this value will
+ * be checked.
+ *
* @throws JspException
*/
- private String currentValue() throws JspException {
+ private String currentValue()
+ throws JspException {
String current = this.lookupProperty(this.name, this.property);
-
+
return (current == null) ? "" : current;
}
-
+
/**
* Renders an HTML <input type="radio"> element.
- * @param serverValue The data to be used in the tag's <code>value</code>
- * attribute and sent to the server when the form is submitted.
- * @param checkedValue If the serverValue equals this value the radio button
- * will be checked.
+ *
+ * @param serverValue The data to be used in the tag's <code>value</code>
+ * attribute and sent to the server when the form is
+ * submitted.
+ * @param checkedValue If the serverValue equals this value the radio
+ * button will be checked.
* @return A radio input element.
* @throws JspException
* @since Struts 1.1
*/
protected String renderRadioElement(String serverValue, String checkedValue)
throws JspException {
-
StringBuffer results = new StringBuffer("<input type=\"radio\"");
prepareAttribute(results, "name", prepareName());
prepareAttribute(results, "accesskey", getAccesskey());
prepareAttribute(results, "tabindex", getTabindex());
- prepareAttribute(results, "value", TagUtils.getInstance().filter(serverValue));
+ prepareAttribute(results, "value",
+ TagUtils.getInstance().filter(serverValue));
+
if (serverValue.equals(checkedValue)) {
results.append(" checked=\"checked\"");
}
+
results.append(prepareEventHandlers());
results.append(prepareStyles());
prepareOtherAttributes(results);
results.append(getElementClose());
+
return results.toString();
}
/**
* Save the associated label from the body content.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doAfterBody() throws JspException {
-
if (this.bodyContent != null) {
String value = this.bodyContent.getString().trim();
+
if (value.length() > 0) {
this.text = value;
}
}
-
+
return (SKIP_BODY);
}
/**
* Optionally render the associated label from the body content.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doEndTag() throws JspException {
-
// Render any description for this radio button
if (this.text != null) {
TagUtils.getInstance().write(pageContext, text);
}
-
- return (EVAL_PAGE);
+ return (EVAL_PAGE);
}
-
/**
* Prepare the name element
+ *
* @return The element name.
*/
- protected String prepareName() throws JspException {
-
+ protected String prepareName()
+ throws JspException {
if (property == null) {
return null;
}
// * @since Struts 1.1
- if(indexed) {
+ if (indexed) {
StringBuffer results = new StringBuffer();
+
prepareIndex(results, name);
results.append(property);
+
return results.toString();
}
return property;
-
}
/**
* Release any acquired resources.
*/
public void release() {
-
super.release();
idName = null;
name = Constants.BEAN_KEY;
property = null;
text = null;
value = null;
-
}
-
}
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ResetTag.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ResetTag.java?rev=376841&r1=376840&r2=376841&view=diff
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ResetTag.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ResetTag.java Fri Feb 10 13:01:28 2006
@@ -1,21 +1,20 @@
/*
- * $Id$
+ * $Id$
*
* Copyright 1999-2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.struts.taglib.html;
import javax.servlet.jsp.JspException;
@@ -23,10 +22,10 @@
/**
* Tag for input fields of type "reset".
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2004-10-17 02:40:12 -0400 (Sun, 17 Oct 2004)
+ * $
*/
public class ResetTag extends SubmitTag {
-
/**
* Render the opening element.
*
@@ -38,9 +37,11 @@
/**
* Prepare the name element
+ *
* @return The element name.
*/
- protected String prepareName() throws JspException {
+ protected String prepareName()
+ throws JspException {
return property;
}
@@ -52,5 +53,4 @@
protected String getDefaultValue() {
return "Reset";
}
-
}
Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/RewriteTag.java
URL: http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/RewriteTag.java?rev=376841&r1=376840&r2=376841&view=diff
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/RewriteTag.java (original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/RewriteTag.java Fri Feb 10 13:01:28 2006
@@ -1,95 +1,76 @@
/*
- * $Id$
+ * $Id$
*
* Copyright 1999-2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.struts.taglib.html;
-import java.net.MalformedURLException;
-import java.util.Map;
+import org.apache.struts.taglib.TagUtils;
import javax.servlet.jsp.JspException;
-import org.apache.struts.taglib.TagUtils;
+import java.net.MalformedURLException;
+
+import java.util.Map;
/**
* Generate a URL-encoded URI as a string.
*
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
+ * $
*/
public class RewriteTag extends LinkTag {
-
-
// --------------------------------------------------------- Public Methods
-
/**
* Render the appropriately encoded URI.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException {
-
// Generate the hyperlink URL
- Map params = TagUtils.getInstance().computeParameters
- (pageContext, paramId, paramName, paramProperty, paramScope,
- name, property, scope, transaction);
-
+ Map params =
+ TagUtils.getInstance().computeParameters(pageContext, paramId,
+ paramName, paramProperty, paramScope, name, property, scope,
+ transaction);
+
String url = null;
+
try {
// Note that we're encoding the & character to & in XHTML mode only,
// otherwise the & is written as is to work in javascripts.
- url =
- TagUtils.getInstance().computeURLWithCharEncoding(
- pageContext,
- forward,
- href,
- page,
- action,
- module,
- params,
- anchor,
- false,
- this.isXhtml(),
- useLocalEncoding);
-
+ url = TagUtils.getInstance().computeURLWithCharEncoding(pageContext,
+ forward, href, page, action, module, params, anchor, false,
+ this.isXhtml(), useLocalEncoding);
} catch (MalformedURLException e) {
TagUtils.getInstance().saveException(pageContext, e);
- throw new JspException
- (messages.getMessage("rewrite.url", e.toString()));
+ throw new JspException(messages.getMessage("rewrite.url",
+ e.toString()));
}
TagUtils.getInstance().write(pageContext, url);
return (SKIP_BODY);
-
}
-
-
/**
* Ignore the end of this tag.
*
- * @exception JspException if a JSP exception has occurred
+ * @throws JspException if a JSP exception has occurred
*/
public int doEndTag() throws JspException {
-
return (EVAL_PAGE);
-
}
-
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org