You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ecs-dev@jakarta.apache.org by rd...@apache.org on 2001/04/07 15:15:11 UTC
cvs commit: jakarta-ecs/src/java/org/apache/ecs/html Option.java
rdonkin 01/04/07 06:15:11
Modified: src/java/org/apache/ecs/html Option.java
Log:
Ryan Giles <op...@leia.com> contribution to make option default to having a closing tag
Revision Changes Path
1.4 +149 -16 jakarta-ecs/src/java/org/apache/ecs/html/Option.java
Index: Option.java
===================================================================
RCS file: /home/cvs/jakarta-ecs/src/java/org/apache/ecs/html/Option.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Option.java 1999/10/08 01:38:04 1.3
+++ Option.java 2001/04/07 13:15:10 1.4
@@ -55,12 +55,50 @@
import org.apache.ecs.*;
/**
+<p>
This class creates a <Option> tag.
- The Option tag defaults to not having a closing </Option>
- because it is optional in the spec. This can be
- overridden by setNeedClosingTag(true)
-
- @version $Id: Option.java,v 1.3 1999/10/08 01:38:04 jonbolt Exp $
+</p><p>
+ The Option tag now defaults to having a closing </Option>
+ (as is now required). This can be
+ overridden by setNeedClosingTag(false).
+</p><p>
+ This change means that you should construct select options element in the following manner:
+<code>
+<pre>
+ new org.apache.ecs.html.Select
+ .addElement(new option("value1").addElement("text1"))
+ .addElement(new option("value2").addElement("text2"))
+</pre>
+</code>
+rather than
+<code>
+<pre>
+ new org.apache.ecs.html.Select
+ .addElement(new option("value1").addElement("text1")
+ .addElement(new option("value2").addElement("text2")))
+</pre>
+</code>
+(this change should not break existing code too badly since browsers generally display
+the output from the above correctly).
+</p><p>
+Alternatively, you could use the new option constructor and do something like
+<code>
+<pre>
+ new org.apache.ecs.html.Select
+ .addElement(new option("text1","value1","text1"))
+ .addElement(new option("text2","value2","text2"))
+</pre>
+</code>
+or even
+<code>
+<pre>
+ new org.apache.ecs.html.Select
+ .appendOption("text1","value1","text1")
+ .appendOption("text2","value2","text2")
+</pre>
+</code>
+</p><p>
+ @version $Id: Option.java,v 1.4 2001/04/07 13:15:10 rdonkin Exp $
@author <a href="mailto:snagy@servletapi.com">Stephan Nagy</a>
@author <a href="mailto:jon@clearink.com">Jon S. Stevens</a>
*/
@@ -73,11 +111,12 @@
*/
{
setElementType("option");
- setNeedClosingTag(false);
+ setNeedClosingTag(true);
}
/**
- Basic constructor. Use the set* methods to set the values
+ Basic constructor.
+ Use the set* methods to set the values
of the attributes.
*/
public Option()
@@ -85,8 +124,9 @@
}
/**
- Basic constructor. Use the set* methods to set the values
- of the attributes.
+ Constructor sets the value attribute.
+ Use the set* methods to set the values
+ of the other attributes.
@param value sets the attribute VALUE=""
*/
@@ -96,8 +136,9 @@
}
/**
- Basic constructor. Use the set* methods to set the values
- of the attributes.
+ Constructor sets the value and label attributes.
+ Use the set* methods to set the values
+ of the other attributes.
@param label sets the attribute LABEL=""
@param value sets the attribute VALUE=""
@@ -109,8 +150,9 @@
}
/**
- Basic constructor. Use the set* methods to set the values
- of the attributes.
+ Constructor sets the value and label attributes.
+ Use the set* methods to set the values
+ of the other attributes.
@param label sets the attribute LABEL=""
@param value sets the attribute VALUE=""
@@ -122,8 +164,9 @@
}
/**
- Basic constructor. Use the set* methods to set the values
- of the attributes.
+ Constructor sets the value and label attributes.
+ Use the set* methods to set the values
+ of the other attributes.
@param label sets the attribute LABEL=""
@param value sets the attribute VALUE=""
@@ -135,6 +178,51 @@
}
/**
+ Same as Option(label,value).addElement(text).
+ Use the set* methods to set the values
+ of the other attributes.
+
+ @param label sets the attribute LABEL=""
+ @param value sets the attribute VALUE=""
+ @param text is added as an element
+ */
+ public Option(String label, String value, String text)
+ {
+ this(label,value);
+ addElement(text);
+ }
+
+ /**
+ Same as Option(label,value).addElement(text).
+ Use the set* methods to set the values
+ of the other attributes.
+
+ @param label sets the attribute LABEL=""
+ @param value sets the attribute VALUE=""
+ @param text is added as an element
+ */
+ public Option(String label, int value, String text)
+ {
+ this(label,value);
+ addElement(text);
+ }
+
+ /**
+ Same as Option(label,value).addElement(text).
+ Use the set* methods to set the values
+ of the other attributes.
+
+ @param label sets the attribute LABEL=""
+ @param value sets the attribute VALUE=""
+ @param text is added as an element
+ */
+ public Option(String label, double value, String text)
+ {
+ this(label,value);
+ addElement(text);
+ }
+
+ /**
Sets the LABEL="" attribute
@param label the LABEL="" attribute
*/
@@ -143,6 +231,14 @@
addAttribute("label",label);
return this;
}
+
+ /**
+ Gets the LABEL attribute.
+ */
+ public String getLabel()
+ {
+ return getAttribute("label");
+ }
/**
Sets the VALUE="" attribute
@@ -175,6 +271,14 @@
}
/**
+ Gets the VALUE attribute.
+ */
+ public String getValue()
+ {
+ return getAttribute("value");
+ }
+
+ /**
Sets the selected value
@param selected true or false
*/
@@ -189,6 +293,20 @@
}
/**
+ Gets the SELECTED attribute.
+ Of course, this return true is the attribute exists and false otherwise.
+ */
+ public boolean getSelected()
+ {
+ if ( hasAttribute("selected"))
+ {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
Sets the disabled value
@param disabled true or false
*/
@@ -201,6 +319,20 @@
return(this);
}
+
+ /**
+ Gets the value of the disabled attribute.
+ Of course, this return true is the attribute exists and false otherwise.
+ */
+ public boolean getDisabled()
+ {
+ if ( hasAttribute("disabled"))
+ {
+ return true;
+ } else {
+ return false;
+ }
+ }
/**
Adds an Element to the element.
@@ -257,6 +389,7 @@
}
return(option);
}
+
/**
Removes an Element from the element.
@param hashcode the name of the element to be removed.
@@ -440,4 +573,4 @@
{
addAttribute ( "onKeyUp", script );
}
-}
\ No newline at end of file
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: ecs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: ecs-dev-help@jakarta.apache.org