Author: dolander
Date: Tue Feb 15 21:25:34 2005
New Revision: 153995
URL: http://svn.apache.org/viewcvs?view=rev&rev=153995
Log:
Partial work on Jira #256.
The basic change is to use an enum for the repeating stages. In addition
I added isXxxxStage methods to the container.metadata representation so to
simplify the JSTL used around the selectOptions.
I added repeatingOrder property which will evenutally be used to change the
default order of the select options.
I added the start of a test case which will change the order.
I also checked in a repo for Jira 299. This is another issue currently under
investigation.
Added:
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/bugs/j299/
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/bugs/j299/index.jsp
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/selectOrder/
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/selectOrder/Controller.jpf
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/selectOrder/Results.jsp
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/selectOrder/index.jsp
Modified:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Select.java
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/SelectOption.java
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/Bundle.java
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/repeatSelect/index.jsp
Modified:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Select.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Select.java?view=diff&r1=153994&r2=153995
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Select.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Select.java
Tue Feb 15 21:25:34 2005
@@ -28,7 +28,6 @@
import org.apache.beehive.netui.tags.rendering.*;
import org.apache.beehive.netui.util.Bundle;
import org.apache.beehive.netui.util.iterator.IteratorFactory;
-import org.apache.beehive.netui.util.iterator.IteratorFactoryException;
import org.apache.beehive.netui.util.logging.Logger;
import javax.servlet.ServletRequest;
@@ -175,6 +174,25 @@
private InputHiddenTag.State _hiddenState = new InputHiddenTag.State();
private boolean _formatterError = false;
+ public enum RepeatingStages
+ {
+ BEFORE (0),
+ OPTION (1),
+ DEFAULT (2),
+ DATASOURCE (3),
+ DATA (4),
+ NULL (5),
+ DONE (6);
+
+ public int value;
+
+ RepeatingStages(int val)
+ {
+ value = val;
+ }
+ }
+
+
/**
* Default value of the options <code>value</code> attribute.
*/
@@ -235,7 +253,7 @@
// IDataAccessProvider support
private int _repIdx = 0; // The current index for repeating
over the optionsDataSource
- private int _repCurStage = 0; // The current stage defined by the
stage constants above
+ private RepeatingStages _repCurStage = RepeatingStages.BEFORE; // The
current stage defined by the stage constants above
private boolean _repeater; // Boolean flag indicating if this is
a repeater or not
private Object _repCurItem; // The current item access by the
IDataAccessProvider
private Object _dynamicOptions; // The interator (or map) for the
options data source, repeating this is current var
@@ -427,6 +445,19 @@
}
/**
+ * This method will set the order of the options generated in the select.
It must contain a
+ * common separated string of the options which match the
<code>repeatingType</code> value.
+ * These values are "Option", "Default", "DataSource", "Data", and "Null".
The default order is
+ * @param order - comma separated ordering of items when there is a
repeating select.
+ * @netui:attribute required="false" rtexprvalue="true"
+ * description="Define the order of options for a repeating Select"
+ */
+ public void setRepeatingOrder(String order)
+ {
+
+ }
+
+ /**
* Set whether a null option is desired.
* @param nullable - the nullable value
* @jsptagref.attributedescription Boolean.
@@ -497,21 +528,9 @@
return val;
Iterator options = null;
- try {
- // This shouldn't return null, but we will handle it
- // if it does
- options = IteratorFactory.makeIterator(val);
- if (options == null)
- options = IteratorFactory.EMPTY_ITERATOR;
-
- }
- catch (IteratorFactoryException ife) {
- // we were not able to get an iterator on the options data source.
- // This is an error.
- String s = Bundle.getString("Tags_Iteration_Error", new
Object[]{ife.getTypeName()});
- registerTagError(s, ife);
- return null;
- }
+ options = IteratorFactory.createIterator(val);
+ if (options == null)
+ options = IteratorFactory.EMPTY_ITERATOR;
return options;
}
@@ -607,26 +626,24 @@
return (IDataAccessProvider) findAncestorWithClass(this,
IDataAccessProvider.class);
}
- /**
- * This method indicates that the expression of the repeater is bound into
a
- * client based context.
- * @return <code>true</code> if the expression of this is bound on the
client.
- */
- public boolean isBindingOnClient()
- {
- // @todo: need to really implement this
- return false;
+ public RepeatingStages getRepeatingStage() {
+ return _repCurStage;
}
- /**
- * This method will return the current stage being process when the select
is acting as a repeater.
- * Integer constants are defined for the return values,
<code>STAGE_OPTION, STAGE_DATASOURCE, STAGE_DEFAULT,
- * STAGE_NULL</code>
- * @return an integer indicating the current repeating stage.
- */
- public int getRepeatingStage()
- {
- return _repCurStage;
+ public boolean isOptionStage() {
+ return _repCurStage == RepeatingStages.OPTION;
+ }
+ public boolean isDefaultStage() {
+ return _repCurStage == RepeatingStages.DEFAULT;
+ }
+ public boolean isDataSourceStage() {
+ return _repCurStage == RepeatingStages.DATASOURCE;
+ }
+ public boolean isDataStage() {
+ return _repCurStage == RepeatingStages.DATA;
+ }
+ public boolean isNullStage() {
+ return _repCurStage == RepeatingStages.NULL;
}
/**
@@ -661,12 +678,12 @@
}
Iterator it = (Iterator) _dynamicOptions;
if (!it.hasNext()) {
- _repCurStage = STAGE_NULL;
+ _repCurStage = RepeatingStages.NULL;
return SKIP_BODY;
}
_repCurItem = it.next();
- _repCurStage = STAGE_OPTION;
+ _repCurStage = RepeatingStages.OPTION;
DataAccessProviderStack.addDataAccessProvider(this, pageContext);
}
@@ -838,7 +855,7 @@
_repIdx = 0;
_repeater = false;
_repCurItem = null;
- _repCurStage = 0;
+ _repCurStage = RepeatingStages.BEFORE;
_dynamicOptions = null;
_formatterError = false;
_optRb = null;
@@ -884,7 +901,7 @@
private boolean doRepeaterAfterBody()
{
_repIdx++;
- if (_repCurStage == STAGE_OPTION) {
+ if (isOptionStage()) {
assert (_dynamicOptions instanceof Iterator);
while (((Iterator) _dynamicOptions).hasNext()) {
_repCurItem = ((Iterator) _dynamicOptions).next();
@@ -896,13 +913,13 @@
}
// initialize for the next stage which must follow this stage in
the code: (Basically a fall through)
- _repCurStage = STAGE_DATASOURCE;
+ _repCurStage = RepeatingStages.DATASOURCE;
if (_match != null) {
_dynamicOptions = Arrays.asList(_match).iterator();
}
}
- if (_repCurStage == STAGE_DATASOURCE) {
+ if (isDataSourceStage()) {
if (_dynamicOptions != null) {
assert (_dynamicOptions instanceof Iterator);
while (((Iterator) _dynamicOptions).hasNext()) {
@@ -915,13 +932,13 @@
}
// initialize for the next stage which must follow this stage in
the code
- _repCurStage = STAGE_DEFAULT;
+ _repCurStage = RepeatingStages.DEFAULT;
if (_defaultSelections != null) {
_dynamicOptions = _defaultSelections.iterator();
}
}
- if (_repCurStage == STAGE_DEFAULT) {
+ if (isDefaultStage()) {
if (_dynamicOptions != null) {
assert (_dynamicOptions instanceof Iterator);
while (((Iterator) _dynamicOptions).hasNext()) {
@@ -935,7 +952,7 @@
// initialize for the next stage which must follow this stage in
the code
_repCurItem = null;
if (_nullable) {
- _repCurStage = STAGE_NULL;
+ _repCurStage = RepeatingStages.NULL;
return true;
}
}
@@ -945,10 +962,8 @@
/**
* This method builds the list of selected items so that they can be
marked as selected.
* @param val The <code>dataSource</code>
- * @throws JspException if there is an error
*/
private void buildMatch(Object val)
- throws JspException
{
// create the match data
if (val != null) {
@@ -978,19 +993,10 @@
}
else {
Iterator matchIterator = null;
- try {
- // val is never null so this would be an error
- matchIterator = IteratorFactory.makeIterator(val);
- if (matchIterator == null) {
- matchIterator = IteratorFactory.EMPTY_ITERATOR;
- }
-
- }
- catch (IteratorFactoryException ife) {
- String s = Bundle.getString("Tags_Iteration_Error",
- new Object[]{ife.getTypeName()});
- registerTagError(s, ife);
- reportErrors();
+ // val is never null so this would be an error
+ matchIterator = IteratorFactory.createIterator(val);
+ if (matchIterator == null) {
+ matchIterator = IteratorFactory.EMPTY_ITERATOR;
}
ArrayList matchList = new ArrayList();
Modified:
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/SelectOption.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/SelectOption.java?view=diff&r1=153994&r2=153995
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/SelectOption.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/SelectOption.java
Tue Feb 15 21:25:34 2005
@@ -329,16 +329,15 @@
if (_repeatingType == null)
return true;
- int stage = sel.getRepeatingStage();
- if (stage == Select.STAGE_NULL)
+ if (sel.isNullStage())
return _repeatingType.equals(Select.REPEATING_NULL);
if (_repeatingType.equals(Select.REPEATING_DATA))
return true;
- if (stage == Select.STAGE_OPTION &&
_repeatingType.equals(Select.REPEATING_OPTION))
+ if (sel.isOptionStage() &&
_repeatingType.equals(Select.REPEATING_OPTION))
return true;
- if (stage == Select.STAGE_DATASOURCE &&
_repeatingType.equals(Select.REPEATING_DATASOURCE))
+ if (sel.isDataSourceStage() &&
_repeatingType.equals(Select.REPEATING_DATASOURCE))
return true;
- if (stage == Select.STAGE_DEFAULT &&
_repeatingType.equals(Select.REPEATING_DEFAULT))
+ if (sel.isDefaultStage() &&
_repeatingType.equals(Select.REPEATING_DEFAULT))
return true;
return false;
}
Modified:
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/Bundle.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/Bundle.java?view=diff&r1=153994&r2=153995
==============================================================================
---
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/Bundle.java
(original)
+++
incubator/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/Bundle.java
Tue Feb 15 21:25:34 2005
@@ -17,10 +17,8 @@
*/
package org.apache.beehive.netui.util;
-import java.util.Locale;
-import java.util.ResourceBundle;
import java.text.MessageFormat;
-import java.net.URL;
+import java.util.ResourceBundle;
/**
* Convenience class for dealing with resource bundles.
Added:
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/bugs/j299/index.jsp
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/bugs/j299/index.jsp?view=auto&rev=153995
==============================================================================
--- incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/bugs/j299/index.jsp
(added)
+++ incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/bugs/j299/index.jsp
Tue Feb 15 21:25:34 2005
@@ -0,0 +1,19 @@
+<%@ page language="java" contentType="text/html;charset=UTF-8"%>
+<%@ taglib prefix="netui" uri="http://beehive.apache.org/netui/tags-html-1.0"%>
+<%@ taglib prefix="netui-data"
uri="http://beehive.apache.org/netui/tags-databinding-1.0"%>
+<%@ taglib prefix="netui-template"
uri="http://beehive.apache.org/netui/tags-template-1.0"%>
+<netui:html>
+ <head>
+ <netui:base/>
+ </head>
+ <netui:body>
+ Causes Script error <br />
+ <netui:anchor onMouseDown="alert(\'OnMOUSEDOWN\')"
href="index.jsp">Script Error For onmousedown when formatted this
way.</netui:anchor>
+ <br />
+ The following generate valid javascript:
+ <br />
+ <netui:anchor onMouseDown='alert("onmousedown")' href="index.jsp">No
script error when double quotes switched with single quotes</netui:anchor>
+ <a href="index.jsp" onmousedown="alert('onmousedown')">No script error
when html anchor tag is used with the same formatting as netui:anchor which
returns a script error</a>
+ <a href="index.jsp" onmousedown='alert("onmousedown")'>No script
error</a>
+ </netui:body>
+</netui:html>
\ No newline at end of file
Modified:
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/repeatSelect/index.jsp
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/repeatSelect/index.jsp?view=diff&r1=153994&r2=153995
==============================================================================
---
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/repeatSelect/index.jsp
(original)
+++
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/repeatSelect/index.jsp
Tue Feb 15 21:25:34 2005
@@ -29,12 +29,12 @@
<tr><td>
<netui:select dataSource="pageFlow.resultsTwo"
optionsDataSource="${pageFlow.opts}" repeater="true"
nullable="true">
- <c:if test="${container.metadata.repeatingStage == '1'}">
+ <c:if test="${container.metadata.optionStage}">
<netui:selectOption repeatingType="Option"
value="${container.item.optionValue}" styleClass="normalAttr">
<netui:span value="${container.item.name}" />
</netui:selectOption>
</c:if>
- <c:if test="${container.metadata.repeatingStage == '4'}">
+ <c:if test="${container.metadata.nullStage}">
<netui:selectOption repeatingType="Null" value="null-opt"
styleClass="normalAttr">
<netui:span value="[Nothing]" />
</netui:selectOption>
Added:
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/selectOrder/Controller.jpf
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/selectOrder/Controller.jpf?view=auto&rev=153995
==============================================================================
---
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/selectOrder/Controller.jpf
(added)
+++
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/selectOrder/Controller.jpf
Tue Feb 15 21:25:34 2005
@@ -0,0 +1,133 @@
+/*
+ * Copyright 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.
+ *
+ * $Header:$
+ */
+package tags.selectOrder;
+
+import org.apache.beehive.netui.pageflow.PageFlowController;
+import org.apache.beehive.netui.pageflow.Forward;
+import org.apache.beehive.netui.pageflow.annotations.Jpf;
+
[EMAIL PROTECTED](
+)
+public class Controller extends PageFlowController
+{
+ private Options[] opts;
+ private String[] resultsOne;
+ private String resultsTwo;
+
+ public Options[] getOpts()
+ {
+ return opts;
+ }
+
+ public void setOpts(Options[] opts)
+ {
+ this.opts = opts;
+ }
+
+ public String[] getResultsOne()
+ {
+ return resultsOne;
+ }
+
+ public void setResultsOne(String[] resultsOne)
+ {
+ this.resultsOne = resultsOne;
+ }
+
+ public String getResultsTwo()
+ {
+ return resultsTwo;
+ }
+
+ public void setResultsTwo(String resultsTwo)
+ {
+ this.resultsTwo = resultsTwo;
+ }
+
+ protected void onCreate()
+ {
+ // initialize the opts
+ opts = new Options[3];
+ opts[0] = new Options("Option One","opt-1", "normal");
+ opts[1] = new Options("Option Two","opt-2", "normal2");
+ opts[2] = new Options("Option Three","opt-3", "normal3");
+ }
+
+ /**
+ * @jpf:action
+ * @jpf:forward name="index" path="index.jsp"
+ */
+ @Jpf.Action(
+ forwards = {
+ @Jpf.Forward(
+ name = "index",
+ path = "index.jsp")
+ })
+ protected Forward begin()
+ {
+ return new Forward("index");
+ }
+
+ /**
+ * @jpf:action
+ * @jpf:forward name="index" path="Results.jsp"
+ */
+ @Jpf.Action(
+ forwards = {
+ @Jpf.Forward(
+ name = "index",
+ path = "Results.jsp")
+ })
+ protected Forward post()
+ {
+ return new Forward("index");
+ }
+
+ public static class Options implements java.io.Serializable {
+ private String _name;
+ private String _optionValue;
+ private String _style;
+
+ public Options(String name, String value, String style) {
+ _name = name;
+ _optionValue = value;
+ _style = style;
+ }
+
+ public void setName(String name) {
+ _name = name;
+ }
+ public String getName() {
+ return _name;
+ }
+
+ public void setOptionValue(String optionValue) {
+ _optionValue = optionValue;
+ }
+ public String getOptionValue() {
+ return _optionValue;
+ }
+
+ public void setStyle(String style) {
+ _style = style;
+ }
+ public String getStyle() {
+ return _style;
+ }
+ }
+}
Added:
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/selectOrder/Results.jsp
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/selectOrder/Results.jsp?view=auto&rev=153995
==============================================================================
---
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/selectOrder/Results.jsp
(added)
+++
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/selectOrder/Results.jsp
Tue Feb 15 21:25:34 2005
@@ -0,0 +1,20 @@
+<[EMAIL PROTECTED] contentType="text/html;charset=UTF-8" language="java"%>
+<%@ page language="java" contentType="text/html;charset=UTF-8"%>
+<%@ taglib uri="http://beehive.apache.org/netui/tags-databinding-1.0"
prefix="netui-data"%>
+<%@ taglib uri="http://beehive.apache.org/netui/tags-html-1.0" prefix="netui"%>
+<%@ taglib uri="http://beehive.apache.org/netui/tags-template-1.0"
prefix="netui-template"%>
+<html>
+ <head>
+ </head>
+ <body>
+ <h4>Results One</h4>
+ <netui:anchor action="begin">Home</netui:anchor>
+ <ul>
+ <netui-data:repeater dataSource="pageFlow.resultsOne">
+ <li><netui:span value="${container.item}"/></li>
+ </netui-data:repeater>
+ </ul>
+ <br/>
+ Results Two: <netui:span value="${pageFlow.resultsTwo}" />
+ </body>
+</html>
Added:
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/selectOrder/index.jsp
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/selectOrder/index.jsp?view=auto&rev=153995
==============================================================================
---
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/selectOrder/index.jsp
(added)
+++
incubator/beehive/trunk/netui/test/webapps/drt/coreWeb/tags/selectOrder/index.jsp
Tue Feb 15 21:25:34 2005
@@ -0,0 +1,43 @@
+<%@ page language="java" contentType="text/html;charset=UTF-8"%>
+<%@ taglib uri="http://beehive.apache.org/netui/tags-html-1.0" prefix="netui"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+
+<netui:html>
+ <head>
+ <title>Order Repeating Select</title>
+ <style type="text/css">
+ .normalAttr {color: #cc0099;font-family:Verdana;
font-size:8pt;margin:0,0,0,0;}
+ </style>
+ </head>
+ <netui:body>
+ <h4>Order Repeating SElect</h4>
+ <netui:form action="post">
+ <table>
+ <tr><td>
+ <netui:select dataSource="pageFlow.resultsOne" defaultValue="default
Value"
+ optionsDataSource="${pageFlow.opts}" repeater="true" size="3"
+ multiple="true" nullable="true">
+ <c:if test="${container.metadata.optionStage}">
+ <netui:selectOption repeatingType="Option"
+ value="${container.item.optionValue}"
styleClass="normalAttr">
+ <netui:span value="${container.item.name}" />
+ </netui:selectOption>
+ </c:if>
+ <c:if test="${container.metadata.defaultStage}">
+ <netui:selectOption repeatingType="Default"
+ value="${container.item}" styleClass="normalAttr">
+ <netui:span value="${container.item}" />
+ </netui:selectOption>
+ </c:if>
+ <netui:selectOption repeatingType="Null" value="null-opt"
+ styleClass="normalAttr">
+ <netui:span value="[Nothing]" />
+ </netui:selectOption>
+ </netui:select>
+ <tr><td><netui:button value="Post" /></td></tr>
+ <table>
+ </netui:form>
+ </netui:body>
+</netui:html>
+
+