JBoss Rich Faces SVN: r8690 - trunk/samples/richfaces-demo/src/main/webapp/richfaces/form.
by richfaces-svn-commits@lists.jboss.org
Author: smukhina
Date: 2008-05-22 08:02:24 -0400 (Thu, 22 May 2008)
New Revision: 8690
Modified:
trunk/samples/richfaces-demo/src/main/webapp/richfaces/form/usage.xhtml
Log:
http://jira.jboss.com/jira/browse/RF-398
Modified: trunk/samples/richfaces-demo/src/main/webapp/richfaces/form/usage.xhtml
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/richfaces/form/usage.xhtml 2008-05-22 11:50:22 UTC (rev 8689)
+++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/form/usage.xhtml 2008-05-22 12:02:24 UTC (rev 8690)
@@ -9,16 +9,16 @@
<ui:define name="sample">
<style type="text/css">
- .viewcodeexamplepanel {
- padding:10px;
- width:100%;
- overflow:auto;
- border-width:0;
- background-color:#FFFFFF;
- }
- .viewsourcebody {
- padding:0;
- }
+ .viewcodeexamplepanel {
+ padding:10px;
+ width:100%;
+ overflow:auto;
+ border-width:0;
+ background-color:#FFFFFF;
+ }
+ .viewsourcebody {
+ padding:0;
+ }
</style>
<p>a4j:form functionality is similar to the standard h:form component except two additional features:
@@ -39,8 +39,8 @@
<fieldset class="demo_fieldset">
<legend class="demo_legend">Code Example</legend>
- <rich:panel styleClass="viewcodeexamplepanel" bodyClass="viewsourcebody rich-laguna-panel-no-header">
- <rich:insert src="/richfaces/form/snippets/commandLinkProblem.xhtml" highlight="xhtml"/>
+ <rich:panel styleClass="viewcodeexamplepanel" bodyClass="viewsourcebody rich-laguna-panel-no-header">
+ <rich:insert src="/richfaces/form/snippets/commandLinkProblem.xhtml" highlight="xhtml"/>
</rich:panel>
</fieldset>
@@ -50,8 +50,8 @@
When ajaxSubmit="true", all standard action components on this form become ajaxable. This
approach is similar to the one AjaxAnywhere framework uses. If a form works in an ajax mode,
the standard ajax attribute such as reRender, eventQueue, requestDelay can be used. The
- following example demonstates the difference between partial and full-page refreshing.
- In both cases, the regular h:commandButton is used for the form submision.
+ following example shows the difference between partial and full-page refreshing.
+ In both cases, the regular h:commandButton is used for the form submission.
</p>
<fieldset class="demo_fieldset">
16 years, 7 months
JBoss Rich Faces SVN: r8689 - trunk/test-applications/seleniumTest/src/test/java/org/richfaces.
by richfaces-svn-commits@lists.jboss.org
Author: andrei_exadel
Date: 2008-05-22 07:50:22 -0400 (Thu, 22 May 2008)
New Revision: 8689
Added:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandButtonTest.java
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandLinkTest.java
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxPollTest.java
Log:
Added: trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandButtonTest.java
===================================================================
--- trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandButtonTest.java (rev 0)
+++ trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandButtonTest.java 2008-05-22 11:50:22 UTC (rev 8689)
@@ -0,0 +1,94 @@
+package org.richfaces;
+
+import org.ajax4jsf.test.base.RichSeleniumTest;
+import org.ajax4jsf.test.base.SeleniumTestBase;
+import org.ajax4jsf.test.base.Templates;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Parameters;
+import org.testng.annotations.Test;
+
+
+public class AjaxCommandButtonTest extends SeleniumTestBase implements RichSeleniumTest {
+
+ public AjaxCommandButtonTest() {
+ super("http", "localhost", "8080");
+ }
+
+ /**
+ * This method are invoking before selenium tests started
+ */
+ @BeforeTest
+ @Parameters( { "browser" })
+ public void startSelenium(String browser) {
+ super.startSelenium(browser);
+ }
+
+ /**
+ * This method are invoking after selenium tests completed
+ */
+ @AfterTest
+ public void stopSelenium() {
+ super.stopSelenium();
+ }
+
+ @Test
+ public void testAjaxCommandButtonComponent() throws Exception {
+ _testAjaxCommandButtonComponent(Templates.SIMPLE);
+ _testAjaxCommandButtonComponent(Templates.DATATABLE);
+ _testAjaxCommandButtonComponent(Templates.MODALPANEL);
+ }
+
+ private void _testAjaxCommandButtonComponent(Templates template) {
+ renderPage(getTestUrl(), template);
+
+ String parentId = getParentId() + "_form:";
+
+ String buttonId = parentId + "b1";
+ String inputId = parentId + "_value";
+
+ writeStatus("Click button 1 : ");
+ clickById(buttonId);
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "12345");
+
+ writeStatus("Click button 1 again: ");
+ clickById(buttonId);
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "123452345");
+
+ buttonId = parentId + "b2";
+
+ writeStatus("Click button 2: ");
+ clickById(buttonId);
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "1234523455");
+
+ buttonId = parentId + "b3";
+
+ writeStatus("Click button 3: ");
+ clickById(buttonId);
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "1234523455");
+
+ buttonId = parentId + "b4";
+
+ writeStatus("Click button 4: ");
+ clickById(buttonId);
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "12345234555");
+
+ buttonId = parentId + "b5";
+
+ writeStatus("Click button 5: ");
+ clickById(buttonId);
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "12345234555");
+
+ }
+
+ public String getTestUrl() {
+ return "/faces/pages/ajaxCommandButton/ajaxButtonTest.xhtml";
+ }
+
+}
Added: trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandLinkTest.java
===================================================================
--- trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandLinkTest.java (rev 0)
+++ trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandLinkTest.java 2008-05-22 11:50:22 UTC (rev 8689)
@@ -0,0 +1,93 @@
+package org.richfaces;
+
+import org.ajax4jsf.test.base.RichSeleniumTest;
+import org.ajax4jsf.test.base.SeleniumTestBase;
+import org.ajax4jsf.test.base.Templates;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Parameters;
+import org.testng.annotations.Test;
+
+public class AjaxCommandLinkTest extends SeleniumTestBase implements RichSeleniumTest {
+
+ public AjaxCommandLinkTest() {
+ super("http", "localhost", "8080");
+ }
+
+ /**
+ * This method are invoking before selenium tests started
+ */
+ @BeforeTest
+ @Parameters( { "browser" })
+ public void startSelenium(String browser) {
+ super.startSelenium(browser);
+ }
+
+ /**
+ * This method are invoking after selenium tests completed
+ */
+ @AfterTest
+ public void stopSelenium() {
+ super.stopSelenium();
+ }
+
+ @Test
+ public void testAjaxCommandLinkComponent() throws Exception {
+ _testAjaxCommandLinkComponent(Templates.SIMPLE);
+ _testAjaxCommandLinkComponent(Templates.DATATABLE);
+ _testAjaxCommandLinkComponent(Templates.MODALPANEL);
+ }
+
+ private void _testAjaxCommandLinkComponent(Templates template) {
+ renderPage(getTestUrl(), template);
+
+ String parentId = getParentId() + "_form:";
+
+ String LinkId = parentId + "l1";
+ String inputId = parentId + "_value";
+
+ writeStatus("Click link 1 : ");
+ clickById(LinkId);
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "12345");
+
+ writeStatus("Click link 1 again: ");
+ clickById(LinkId);
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "123452345");
+
+ LinkId = parentId + "l2";
+
+ writeStatus("Click link 2 : ");
+ clickById(LinkId);
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "1234523455");
+
+ LinkId = parentId + "l3";
+
+ writeStatus("Click link 3 : ");
+ clickById(LinkId);
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "1234523455");
+
+ LinkId = parentId + "l4";
+
+ writeStatus("Click link 4 : ");
+ clickById(LinkId);
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "12345234555");
+
+ LinkId = parentId + "l5";
+
+ writeStatus("Click link 5 : ");
+ clickById(LinkId);
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "12345234555");
+
+ }
+
+ public String getTestUrl() {
+ return "/faces/pages/ajaxCommandLink/ajaxLinkTest.xhtml";
+ }
+
+}
Added: trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxPollTest.java
===================================================================
--- trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxPollTest.java (rev 0)
+++ trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxPollTest.java 2008-05-22 11:50:22 UTC (rev 8689)
@@ -0,0 +1,80 @@
+/**
+ *
+ */
+package org.richfaces;
+
+import org.ajax4jsf.test.base.RichSeleniumTest;
+import org.ajax4jsf.test.base.SeleniumTestBase;
+import org.ajax4jsf.test.base.Templates;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Parameters;
+import org.testng.annotations.Test;
+
+/**
+ * @author Andrey Markavstov
+ *
+ */
+public class AjaxPollTest extends SeleniumTestBase implements RichSeleniumTest {
+
+ public AjaxPollTest() {
+ super("http", "localhost", "8080");
+ }
+
+ /**
+ * This method are invoking before selenium tests started
+ */
+ @BeforeTest
+ @Parameters( { "browser" })
+ public void startSelenium(String browser) {
+ super.startSelenium(browser);
+ }
+
+ /**
+ * This method are invoking after selenium tests completed
+ */
+ @AfterTest
+ public void stopSelenium() {
+ super.stopSelenium();
+ }
+
+ @Test
+ public void testAjaxPollComponent() {
+ _testAjaxPollComponent(Templates.SIMPLE);
+ _testAjaxPollComponent(Templates.DATATABLE);
+ _testAjaxPollComponent(Templates.MODALPANEL);
+ }
+
+ private void _testAjaxPollComponent(Templates template) {
+ renderPage(getTestUrl(), template);
+ String parentId = getParentId() + "_form:";
+ String pollId = parentId + "poll";
+ String inputId = parentId + "_value";
+
+ writeStatus("Start polling...");
+ clickById(parentId + "_enabled");
+ waitForAjaxCompletion();
+ AssertValueEquals(inputId, "1");
+
+ writeStatus("Polling in progress...");
+ pause(1500, pollId);
+ AssertValueNotEquals(inputId, "1");
+ waiteForCondition("document.getElementById('"+inputId+"').value == 8", 7000);
+
+ pause(1500, pollId);
+ writeStatus("Polling should be stopped...");
+ AssertValueEquals(inputId, "8");
+ AssertTextEquals(parentId + "_text", "Polling");
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.test.base.RichSeleniumTest#getTestUrl()
+ */
+ public String getTestUrl() {
+ return "/faces/pages/ajaxPoll/ajaxPollTest.xhtml";
+ }
+
+}
16 years, 7 months
JBoss Rich Faces SVN: r8688 - trunk/test-applications/seleniumTest/src/test/java/org/richfaces.
by richfaces-svn-commits@lists.jboss.org
Author: dsvyatobatsko
Date: 2008-05-22 07:38:01 -0400 (Thu, 22 May 2008)
New Revision: 8688
Modified:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxRegionTest.java
Log:
some improvements
Modified: trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxRegionTest.java
===================================================================
--- trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxRegionTest.java 2008-05-22 11:15:52 UTC (rev 8687)
+++ trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxRegionTest.java 2008-05-22 11:38:01 UTC (rev 8688)
@@ -42,49 +42,53 @@
String parentId = getParentId() + "_form:";
- //test nested regions
+ writeStatus("check nested regions");
+
String externalLink = parentId + "externalLink";
String internalLink = parentId + "internalLink";
String internalElemId = parentId + "internal";
String externalElemId = parentId + "external";
- setValueById(internalElemId, "5");
- setValueById(externalElemId, "5");
+ selenium.type(internalElemId, "5");
+ selenium.type(externalElemId, "5");
clickById(internalLink);
waitForAjaxCompletion();
AssertValueEquals(internalElemId, "5");
AssertValueEquals(externalElemId, "0");
- setValueById(internalElemId, "10");
- setValueById(externalElemId, "10");
+ selenium.type(internalElemId, "10");
+ selenium.type(externalElemId, "10");
clickById(externalLink);
waitForAjaxCompletion();
AssertValueEquals(internalElemId, "10");
AssertValueEquals(externalElemId, "10");
- //test "selfRendered" attribute
+ writeStatus("verify \"selfRendered\" component's attribute");
+
String selfRenderedLink = parentId + "selfRenderedLink";
clickById(selfRenderedLink);
waitForAjaxCompletion();
AssertNotPresent("transientText");
- //test "renderRegionOnly" attribute
+ writeStatus("verify \"renderRegionOnly\" component's attribute");
+
String renderOnlyLink = parentId + "renderOnlyLink";
String renderLink = parentId + "renderLink";
String renderOnlyElemId = parentId + "renderOnly";
String renderElemId = parentId + "render";
- setValueById(renderOnlyElemId, "7");
+ selenium.type(renderOnlyElemId, "7");
+
clickById(renderOnlyLink);
AssertValueEquals(renderOnlyElemId, "7");
AssertValueEquals(renderElemId, "0");
- setValueById(renderElemId, "11");
+ selenium.type(renderElemId, "11");
clickById(renderLink);
AssertValueEquals(renderOnlyElemId, "11");
16 years, 7 months
JBoss Rich Faces SVN: r8687 - trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base.
by richfaces-svn-commits@lists.jboss.org
Author: dsvyatobatsko
Date: 2008-05-22 07:15:52 -0400 (Thu, 22 May 2008)
New Revision: 8687
Modified:
trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/SeleniumTestBase.java
Log:
Modified: trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/SeleniumTestBase.java
===================================================================
--- trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/SeleniumTestBase.java 2008-05-22 11:03:33 UTC (rev 8686)
+++ trunk/test-applications/seleniumTest/src/test/java/org/ajax4jsf/test/base/SeleniumTestBase.java 2008-05-22 11:15:52 UTC (rev 8687)
@@ -370,7 +370,7 @@
* a new DOM element's value
*/
public void setValueById(String id, String value) {
- runScript(String.format("$('%1$s').value=%2$s;", id, value));
+ runScript(String.format("document.getElementById('%1$s').value=%2$s;", id, value));
}
/**
16 years, 7 months
JBoss Rich Faces SVN: r8686 - in trunk/ui/columns/src: main/java/org/richfaces/taglib and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: andrei_exadel
Date: 2008-05-22 07:03:33 -0400 (Thu, 22 May 2008)
New Revision: 8686
Added:
trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag.java
Removed:
trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag.java
trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag2.java
Modified:
trunk/ui/columns/src/main/config/component/columns.xml
trunk/ui/columns/src/main/java/org/richfaces/taglib/ComponentHandler.java
trunk/ui/columns/src/test/java/org/richfaces/jsp/tag/ColumnsJspTagTest.java
Log:
RF-3499
Modified: trunk/ui/columns/src/main/config/component/columns.xml
===================================================================
--- trunk/ui/columns/src/main/config/component/columns.xml 2008-05-22 11:02:54 UTC (rev 8685)
+++ trunk/ui/columns/src/main/config/component/columns.xml 2008-05-22 11:03:33 UTC (rev 8686)
@@ -16,7 +16,7 @@
<tag generate="false">
<name>columns</name>
<classname>
- org.richfaces.taglib.ColumnsTag2
+ org.richfaces.taglib.ColumnsTag
</classname>
<test/>
</tag>
Deleted: trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag.java
===================================================================
--- trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag.java 2008-05-22 11:02:54 UTC (rev 8685)
+++ trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag.java 2008-05-22 11:03:33 UTC (rev 8686)
@@ -1,1290 +0,0 @@
-/*
- * AbstractColumnsTag.java Date created: 26.11.2007
- * Last modified by: $Author$
- * $Revision$ $Date$
- */
-
-package org.richfaces.taglib;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Pattern;
-
-import javax.el.ELContext;
-import javax.el.ELException;
-import javax.el.ELResolver;
-import javax.el.FunctionMapper;
-import javax.el.MethodExpression;
-import javax.el.ValueExpression;
-import javax.el.VariableMapper;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.webapp.UIComponentClassicTagBase;
-import javax.faces.webapp.UIComponentTag;
-import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.JspTagException;
-import javax.servlet.jsp.PageContext;
-import javax.servlet.jsp.tagext.BodyContent;
-import javax.servlet.jsp.tagext.IterationTag;
-
-import org.richfaces.component.UIColumn;
-import org.richfaces.iterator.ForEachIterator;
-import org.richfaces.iterator.SimpleForEachIterator;
-
-/**
- * Class provides implementation for columns tag
- *
- * @author "Andrey Markavtsov"
- *
- */
-/**
- * @author Andrey
- *
- */
-public class ColumnsTag extends UIComponentClassicTagBase implements
- IterationTag {
-
- /** Component type */
- private static final String COLUMN_COMPONENT_TYPE = UIColumn.COMPONENT_TYPE;
-
- /** Prefix before id to be assigned for column */
- private static final String COLUMN_ID_PREFIX = "rf";
-
- /** Current column counter */
- private Integer index = -1;
-
- /** Data table */
- private UIComponent dataTable;
-
- private Pattern varPattern = null;
-
- private Pattern indexPattern = null;
-
- /**
- * <p>
- * The {@link UIComponent} that is being encoded by this tag, if any.
- * </p>
- */
- private UIComponent component = null;
-
- /** Flag indicates if columns are already created */
- private boolean created = false;
-
- /** Iterator for columns's tag value attribute */
- protected ForEachIterator items; // our 'digested' items
-
- /** Value attribute value */
- protected Object rawItems; // our 'raw' items
-
- /** End attribute - defines count of column if value attr hasn't been defined */
- private ValueExpression columns;
-
- /** Begin attribute - defines the first iteration item */
- private ValueExpression begin;
-
- /** Begin attribute - defines the last iteration item */
- private ValueExpression end;
-
- /** Index attr - defines page variable for current column counter */
- private ValueExpression _index;
-
- /** Var attr - defines page variable for current item */
- private String indexId;
-
- /** Integer value of end attr. */
- private Integer _columns;
-
- /** Integer value of begin attr. */
- private Integer _begin;
-
- /** Integer value of end attr. */
- private Integer _end;
-
- /** String value of var attr */
- private String itemId = null;
-
- /** Expression for var item */
- private IteratedExpression iteratedExpression;
-
- /** Column incrementer */
- private Integer counter = 0;
-
- /**
- * <p>
- * The <code>Lst</code> of {@link UIComponent} ids created or located by
- * nested {@link UIComponentTag}s while processing the current request.
- * </p>
- */
- // public List<String> createdComponents = null;
- /**
- * Caches the nearest enclosing {@link UIComponentRichClassicTagBase} of
- * this tag. This is used for duplicate id detection.
- */
- private UIComponentClassicTagBase parentTag = null;
-
- /**
- * <p>
- * Return the {@link UIComponent} instance that is associated with this tag
- * instance. This method is designed to be used by tags nested within this
- * tag, and only returns useful results between the execution of
- * <code>doStartTag()</code> and <code>doEndTag()</code> on this tag
- * instance.
- * </p>
- */
- public UIComponent getComponentInstance() {
-
- return (this.component);
-
- }
-
- /**
- * <p>
- * The request scope attribute under which a component tag stack for the
- * current request will be maintained.
- * </p>
- */
- private static final String COMPONENT_TAG_STACK_ATTR = "javax.faces.webapp.COMPONENT_TAG_STACK";
-
- /**
- * <p>
- * An override for the rendered attribute associated with our
- * {@link UIComponent}.
- * </p>
- */
- private ValueExpression rendered = null;
-
- /**
- * Dir attr
- */
- private ValueExpression _dir;
-
- /**
- * Sets dir attr
- *
- * @param dir
- */
- public void setDir(ValueExpression dir) {
- _dir = dir;
- }
-
- /**
- * style CSS style(s) is/are to be applied when this component is rendered
- */
- private ValueExpression _style;
-
- /**
- * CSS style(s) is/are to be applied when this component is rendered Setter
- * for style
- *
- * @param style -
- * new value
- */
- public void setStyle(ValueExpression __style) {
- this._style = __style;
- }
-
- /**
- * breakBefore if "true" next column begins from the first row
- */
- private ValueExpression _breakBefore;
-
- /**
- * if "true" next column begins from the first row Setter for breakBefore
- *
- * @param breakBefore -
- * new value
- */
- public void setBreakBefore(ValueExpression __breakBefore) {
- this._breakBefore = __breakBefore;
- }
-
- /**
- * colspan Corresponds to the HTML colspan attribute
- */
- private ValueExpression _colspan;
-
- /**
- * Corresponds to the HTML colspan attribute Setter for colspan
- *
- * @param colspan -
- * new value
- */
- public void setColspan(ValueExpression __colspan) {
- this._colspan = __colspan;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.webapp.UIComponentClassicTagBase#createComponent(javax.faces.context.FacesContext,
- * java.lang.String)
- */
- @Override
- protected UIComponent createComponent(FacesContext context, String newId)
- throws JspException {
- // TODO Auto-generated method stub
- return context.getApplication().createComponent(COLUMN_COMPONENT_TYPE);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.webapp.UIComponentTagBase#getComponentType()
- */
- @Override
- public String getComponentType() {
- // TODO Auto-generated method stub
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.webapp.UIComponentTagBase#getRendererType()
- */
- @Override
- public String getRendererType() {
- // TODO Auto-generated method stub
- return null;
- }
-
- /**
- * footerClass Space-separated list of CSS style class(es) that are be
- * applied to any footer generated for this table
- */
- private ValueExpression _footerClass;
-
- /**
- * Space-separated list of CSS style class(es) that are be applied to any
- * footer generated for this table Setter for footerClass
- *
- * @param footerClass -
- * new value
- */
- public void setFooterClass(ValueExpression __footerClass) {
- this._footerClass = __footerClass;
- }
-
- /**
- * headerClass Space-separated list of CSS style class(es) that are be
- * applied to any header generated for this table
- */
- private ValueExpression _headerClass;
-
- /**
- * Space-separated list of CSS style class(es) that are be applied to any
- * header generated for this table Setter for headerClass
- *
- * @param headerClass -
- * new value
- */
- public void setHeaderClass(ValueExpression __headerClass) {
- this._headerClass = __headerClass;
- }
-
- /**
- * rowspan Corresponds to the HTML rowspan attribute
- */
- private ValueExpression _rowspan;
-
- /**
- * Corresponds to the HTML rowspan attribute Setter for rowspan
- *
- * @param rowspan -
- * new value
- */
- public void setRowspan(ValueExpression __rowspan) {
- this._rowspan = __rowspan;
- }
-
- /**
- * sortExpression Attribute defines a bean property which is used for
- * sorting of a column
- */
- private ValueExpression _sortExpression;
-
- /**
- * Attribute defines a bean property which is used for sorting of a column
- * Setter for sortExpression
- *
- * @param sortExpression -
- * new value
- */
- public void setSortExpression(ValueExpression __sortExpression) {
- this._sortExpression = __sortExpression;
- }
-
- /**
- * sortable Boolean attribute. If "true" it's possible to sort the column
- * content after click on the header. Default value is "true"
- */
- private ValueExpression _sortable;
-
- /*
- * sortBy Attribute defines a bean property which is used for sorting of a
- * column
- */
- private ValueExpression _sortBy;
-
- /**
- * Attribute defines a bean property which is used for sorting of a column
- * Setter for sortBy
- *
- * @param sortBy -
- * new value
- */
- public void setSortBy(ValueExpression __sortBy) {
- this._sortBy = __sortBy;
- }
-
- /**
- * sortOrder SortOrder is an enumeration of the possible sort orderings.
- */
- private ValueExpression _sortOrder;
-
- /**
- * SortOrder is an enumeration of the possible sort orderings. Setter for
- * sortOrder
- *
- * @param sortOrder -
- * new value
- */
- public void setSortOrder(ValueExpression __sortOrder) {
- this._sortOrder = __sortOrder;
- }
-
- /**
- * selfSorted
- *
- */
- private ValueExpression _selfSorted;
-
- /**
- *
- * Setter for selfSorted
- *
- * @param selfSorted -
- * new value
- */
- public void setSelfSorted(ValueExpression __selfSorted) {
- this._selfSorted = __selfSorted;
- }
-
- /**
- * comparator
- *
- */
- private ValueExpression _comparator;
-
- /**
- *
- * Setter for comparator
- *
- * @param comparator -
- * new value
- */
- public void setComparator(ValueExpression __comparator) {
- this._comparator = __comparator;
- }
-
- /*
- * filterBy
- *
- */
- private ValueExpression _filterBy;
-
- /**
- *
- * Setter for filterBy
- *
- * @param filterBy -
- * new value
- */
- public void setFilterBy(ValueExpression __filterBy) {
- this._filterBy = __filterBy;
- }
-
- /*
- * filterDefaultLabel
- *
- */
- private ValueExpression _filterDefaultLabel;
-
- /**
- *
- * Setter for filterDefaultLabel
- *
- * @param filterDefaultLabel -
- * new value
- */
- public void setFilterDefaultLabel(ValueExpression __filterDefaultLabel) {
- this._filterDefaultLabel = __filterDefaultLabel;
- }
-
- /*
- * filterEvent Event for filter input that forces the filtration (default =
- * onchange)
- */
- private ValueExpression _filterEvent;
-
- /**
- * Event for filter input that forces the filtration (default = onchange)
- * Setter for filterEvent
- *
- * @param filterEvent -
- * new value
- */
- public void setFilterEvent(ValueExpression __filterEvent) {
- this._filterEvent = __filterEvent;
- }
-
- /*
- * filterExpression Attribute defines a bean property which is used for
- * filtering of a column
- */
- private ValueExpression _filterExpression;
-
- /**
- * Attribute defines a bean property which is used for filtering of a column
- * Setter for filterExpression
- *
- * @param filterExpression -
- * new value
- */
- public void setFilterExpression(ValueExpression __filterExpression) {
- this._filterExpression = __filterExpression;
- }
-
- /*
- * filterMethod
- *
- */
- private MethodExpression _filterMethod;
-
- /**
- *
- * Setter for filterMethod
- *
- * @param filterMethod -
- * new value
- */
- public void setFilterMethod(MethodExpression __filterMethod) {
- this._filterMethod = __filterMethod;
- }
-
- /*
- * filterValue
- *
- */
- private ValueExpression _filterValue;
-
- /**
- *
- * Setter for filterValue
- *
- * @param filterValue -
- * new value
- */
- public void setFilterValue(ValueExpression __filterValue) {
- this._filterValue = __filterValue;
- }
-
- /**
- * Boolean attribute. If "true" it's possible to sort the column content
- * after click on the header. Default value is "true" Setter for sortable
- *
- * @param sortable -
- * new value
- */
- public void setSortable(ValueExpression __sortable) {
- this._sortable = __sortable;
- }
-
- /**
- * styleClass Corresponds to the HTML class attribute
- */
- private ValueExpression _styleClass;
-
- /**
- * Corresponds to the HTML class attribute Setter for styleClass
- *
- * @param styleClass -
- * new value
- */
- public void setStyleClass(ValueExpression __styleClass) {
- this._styleClass = __styleClass;
- }
-
- /**
- * value The current value for this component
- */
- private ValueExpression _value;
-
- /**
- * The current value for this component Setter for value
- *
- * @param value -
- * new value
- */
- public void setValue(ValueExpression __value) {
- this._value = __value;
- }
-
- /**
- * var A request-scope attribute via which the data object for the current
- * row will be used when iterating
- */
- private ValueExpression _var;
-
- /**
- * A request-scope attribute via which the data object for the current row
- * will be used when iterating Setter for var
- *
- * @param var -
- * new value
- */
- public void setVar(ValueExpression __var) {
- this._var = __var;
- }
-
- /*
- * width Attribute defines width of column. Default value is "100px".
- */
- private ValueExpression _width;
-
- /**
- * Attribute defines width of column. Default value is "100px". Setter for
- * width
- *
- * @param width -
- * new value
- */
- public void setWidth(ValueExpression __width) {
- this._width = __width;
- }
-
- /**
- * Default constructor for AbstractColumnsTag class
- */
- public ColumnsTag() {
- super();
- }
-
- /**
- * <p>
- * Set an override for the rendered attribute.
- * </p>
- *
- * @param rendered
- * The new value for rendered attribute
- */
- public void setRendered(ValueExpression rendered) {
- this.rendered = rendered;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.jsp.tagext.BodyTagSupport#doAfterBody()
- */
- @Override
- public int doAfterBody() throws JspException {
-
- if (hasNext()) {
- exposeVariables();
- loop();
- } else
- return EVAL_BODY_INCLUDE;
-
- exposeVariables();
-
- return EVAL_BODY_AGAIN;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.webapp.UIComponentClassicTagBase#addFacet(java.lang.String)
- */
- protected void addFacet(String name) {
- super.addFacet(name);
-
- // add created component in facet in childrenList to reduce duplicated
- // Id exp.
- if (this.component != null && this.component.getFacets() != null) {
- Map<String, UIComponent> facets = this.component.getFacets();
- Iterator<UIComponent> it = facets.values().iterator();
- while (it.hasNext()) {
- super.addChild(it.next());
- }
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.jsp.tagext.BodyTagSupport#doInitBody()
- */
- @Override
- public void doInitBody() throws JspException {
- // TODO Auto-generated method stub
- super.doInitBody();
-
- }
-
- /**
- * Removes any attributes that this LoopTagSupport set.
- *
- * <p>
- * These attributes are intended to support scripting variables with NESTED
- * scope, so we don't want to pollute attribute space by leaving them lying
- * around.
- */
- public void doFinally() {
- /*
- * Make sure to un-expose variables, restoring them to their prior
- * values, if applicable.
- */
- unExposeVariables();
- }
-
- /**
- * Removes page attributes that we have exposed and, if applicable, restores
- * them to their prior values (and scopes).
- */
- private void unExposeVariables() {
- // "nested" variables are now simply removed
- if (itemId != null) {
- pageContext.removeAttribute(itemId, PageContext.PAGE_SCOPE);
- VariableMapper vm = pageContext.getELContext().getVariableMapper();
- if (vm != null)
- vm.setVariable(itemId, null);
- }
- if (indexId != null) {
- pageContext.removeAttribute(indexId, PageContext.PAGE_SCOPE);
- VariableMapper vm = pageContext.getELContext().getVariableMapper();
- if (vm != null)
- vm.setVariable(indexId, null);
- }
- }
-
- /**
- * Method is invoking by each iteration of body again rendering
- *
- * @throws JspTagException
- */
- private void loop() throws JspTagException {
- if (!atFirst()) {
- popUIComponentClassicTagBase();
- }
- UIComponent component = createColumn();
- pushUIComponentClassicTagBase(this);
-
- dataTable.getChildren().add(component);
-
- next();
- }
-
- private String generateColumnId() {
- return COLUMN_ID_PREFIX + Integer.toString(counter++);
- }
-
- /**
- * Creates column instance
- *
- * @return
- */
- private UIComponent createColumn() {
- UIComponent component = getFacesContext().getApplication()
- .createComponent(COLUMN_COMPONENT_TYPE);
- component.setId(generateColumnId());
-
- initColumnByThis(component);
-
- this.component = component;
- this.parentTag = getParentUIComponentClassicTagBase(pageContext);
-
- return component;
- }
-
- /**
- * Inits column component by columns tag attrs
- *
- * @param column
- */
- void initColumnByThis(UIComponent column) {
-
- ELContext elContext = getContext(getELContext());
- Field[] fields = this.getClass().getDeclaredFields();
- for (Field field : fields) {
- try {
- Object o = field.get(this);
- if ((o != null) && (o instanceof ValueExpression)) {
- String fieldName = field.getName();
- String attributeName = fieldName.replace("_", "");
- ValueExpression ex = (ValueExpression) o;
- column.setValueExpression(attributeName,
- createValueExpression(elContext, ex));
-
- }
- } catch (Exception e) {
- continue;
- }
- }
- }
-
- /**
- * Creates value expression to be out into column
- * @param context
- * @param orig
- * @return
- */
- private ValueExpression createValueExpression(ELContext context,
- ValueExpression orig) {
- ValueExpression vexpr = getFacesContext().getApplication()
- .getExpressionFactory().createValueExpression(
- getContext(context), orig.getExpressionString(),
- orig.getExpectedType());
- return vexpr;
- }
-
- /**
- * Create custom context with VariableMapper override.
- * @param context
- * @return
- */
- private ELContext getContext(final ELContext context) {
- return new ELContext() {
-
- @Override
- public ELResolver getELResolver() {
- // TODO Auto-generated method stub
- return context.getELResolver();
- }
-
- @Override
- public FunctionMapper getFunctionMapper() {
- // TODO Auto-generated method stub
- return context.getFunctionMapper();
- }
-
- @Override
- public VariableMapper getVariableMapper() {
- return new VariableMapper() {
-
- @Override
- public ValueExpression resolveVariable(String variable) {
- // TODO Auto-generated method stub
- if (variable.equals(itemId)) {
- return new IndexedValueExpression(_value, index + 1);
- } else if (variable.equals(indexId)) {
- return new IteratedIndexExpression(index + 1);
- }
- return context.getVariableMapper().resolveVariable(
- variable);
- }
-
- @Override
- public ValueExpression setVariable(String variable,
- ValueExpression expression) {
- // TODO Auto-generated method stub
- return context.getVariableMapper().setVariable(
- variable, expression);
- }
-
- };
- }
-
- };
- }
-
- /**
- * Returns true if this is the first loop of columns tag
- *
- * @return
- */
- private boolean atFirst() {
- return (index == _begin - 1);
- }
-
- /**
- * Deletes dynamic rich columns created before
- */
- private void deleteRichColumns() {
- List<UIComponent> children = dataTable.getChildren();
- Iterator<UIComponent> it = children.iterator();
- List<UIComponent> forDelete = new ArrayList<UIComponent>();
- Integer i = 0;
- while (it.hasNext()) {
- UIComponent child = it.next();
- String id = child.getId();
- if (id != null && id.startsWith(COLUMN_ID_PREFIX)) {
- forDelete.add(child);
- }
- i++;
- }
- it = forDelete.iterator();
- while (it.hasNext()) {
- UIComponent elem = it.next();
- children.remove(elem);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.jsp.tagext.BodyTagSupport#doStartTag()
- */
- @Override
- public int doStartTag() throws JspException {
-
- prepare();
-
- if (created) {
- deleteRichColumns();
- created = false;
- }
-
- // get the item we're interested in
- if (!hasNext()) {
- return SKIP_BODY;
- }
-
- exposeVariables();
-
- loop();
-
- exposeVariables();
-
- return EVAL_BODY_INCLUDE;
- }
-
- /**
- * Method prepares all we need for starting of tag rendering
- *
- * @throws JspTagException
- */
- private void prepare() throws JspTagException {
- dataTable = getParentUIComponentClassicTagBase(pageContext)
- .getComponentInstance();
- created = (dataTable.getChildCount() > 0);
-
- initVariables();
-
- // produce the right sort of ForEachIterator
- if (_value != null) {
- // If this is a deferred expression, make a note and get
- // the 'items' instance.
- if (_value instanceof ValueExpression) {
- rawItems = _value.getValue(pageContext.getELContext());
- }
- // extract an iterator over the 'items' we've got
- items = SimpleForEachIterator
- .supportedTypeForEachIterator(rawItems);
- } else {
- // no 'items', so use 'begin' and 'end'
- items = SimpleForEachIterator.beginEndForEachIterator(_columns - 1);
- }
-
- correctFirst();
-
- /*
- * ResultSet no more supported in <c:forEach> // step must be 1 when
- * ResultSet is passed in if (rawItems instanceof ResultSet && step !=
- * 1) throw new JspTagException(
- * Resources.getMessage("FOREACH_STEP_NO_RESULTSET"));
- */
-
- }
-
- /**
- * Extracts integer value from end attr
- */
- private void initColumnsCount() {
- if (columns != null) {
- if (columns instanceof ValueExpression)
- try {
- String t = (String) columns.getValue(getELContext());
- _columns = Integer.parseInt(t);
- if (_columns < 0) {
- _columns = 0; // If end is negative set up zero
- }
- } catch (Exception e) {
- _columns = 0;
- }
- } else {
- _columns = 0;
- }
- }
-
- /**
- * Extracts string value from var attr
- */
- private void initVar() {
- if (_var != null) {
- try {
- itemId = (String) _var.getValue(getELContext());
- varPattern = Pattern.compile("[\\W]+" + itemId + "[\\W]+");
- } catch (ClassCastException e) {
- itemId = null;
- }
-
- }
- }
-
- /**
- * Extracts string value from index attr
- */
- private void initIndex() {
- if (_index != null) {
- try {
- indexId = (String) _index.getValue(getELContext());
- indexPattern = Pattern.compile("[\\W]+" + indexId + "[\\W]+");
- } catch (ClassCastException e) {
- indexId = null;
- }
-
- }
- }
-
- /**
- * Extracts string value from index attr
- */
- private void initBegin() {
- _begin = 0;
- if (begin != null) {
- try {
- String t = (String) begin.getValue(getELContext());
- _begin = Integer.parseInt(t);
- _begin--; // correct begin value
- if (_begin < 0) {
- _begin = 0;
- }
- } catch (ClassCastException e) {
- _begin = 0;
- }
-
- }
- }
-
- /**
- * Extracts string value from index attr
- */
- private void initEnd() {
- _end = 0;
- if (end != null) {
- try {
- String t = (String) end.getValue(getELContext());
- _end = Integer.parseInt(t);
- if (_end < 0) {
- _end = 0;
- }
- } catch (ClassCastException e) {
- _end = 0;
- }
-
- }
- }
-
- /**
- * Extracts tags attributes values
- */
- private void initVariables() {
- initColumnsCount();
- initIndex();
- initVar();
- initBegin();
- initEnd();
- }
-
- /**
- * Return true if we didn't complete column's count
- *
- * @return
- * @throws JspTagException
- */
- private boolean hasNext() throws JspTagException {
- if (_end != 0) {
- return (index < (_end - 1)) ? items.hasNext() : false;
- } else {
- return items.hasNext();
- }
- }
-
- /**
- * Iterate to next column
- *
- * @return
- * @throws JspTagException
- */
- private Object next() throws JspTagException {
- Object o = items.next();
- index++;
- return o;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.jsp.tagext.BodyTagSupport#getBodyContent()
- */
- @Override
- public BodyContent getBodyContent() {
- // TODO Auto-generated method stub
- return super.getBodyContent();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.webapp.UIComponentClassicTagBase#setProperties(javax.faces.component.UIComponent)
- */
- protected void setProperties(UIComponent component) {
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.webapp.UIComponentClassicTagBase#hasBinding()
- */
- protected boolean hasBinding() {
- return false;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.webapp.UIComponentClassicTagBase#doEndTag()
- */
- @Override
- public int doEndTag() throws JspException {
- if (!atFirst()) {
- popUIComponentClassicTagBase();
- }
- return EVAL_PAGE;
- }
-
- /**
- * Sets page request variables
- *
- * @throws JspTagException
- */
- private void exposeVariables() throws JspTagException {
-
- /*
- * We need to support null items returned from next(); we do this simply
- * by passing such non-items through to the scoped variable as
- * effectively 'null' (that is, by calling removeAttribute()).
- *
- * Also, just to be defensive, we handle the case of a null 'status'
- * object as well.
- *
- * We call getCurrent() and getLoopStatus() (instead of just using
- * 'item' and 'status') to bridge to subclasses correctly. A subclass
- * can override getCurrent() or getLoopStatus() but still depend on our
- * doStartTag() and doAfterBody(), which call this method
- * (exposeVariables()), to expose 'item' and 'status' correctly.
- */
-
- // Set up var variable
- if (itemId != null) {
- if (index == null)
- pageContext.removeAttribute(itemId, PageContext.PAGE_SCOPE);
- else if (_value != null) {
- VariableMapper vm = // getFacesContext().getELContext().getVariableMapper();
- pageContext.getELContext().getVariableMapper();
- if (vm != null) {
- ValueExpression ve = getVarExpression(_value);
- vm.setVariable(itemId, ve);
- getELContext().getVariableMapper().setVariable(itemId, ve);
- }
- } else
- pageContext.setAttribute(itemId, index);
- }
-
- // Set up index variable
-
- if (indexId != null) {
- if (index == null)
- pageContext.removeAttribute(indexId, PageContext.PAGE_SCOPE);
- else {
- IteratedIndexExpression indexExpression = new IteratedIndexExpression(
- index - _begin);
- VariableMapper vm = pageContext.getELContext()
- .getVariableMapper();
- if (vm != null) {
- vm.setVariable(indexId, indexExpression);
- getELContext().getVariableMapper().setVariable(indexId,
- indexExpression);
- }
- pageContext.setAttribute(indexId, index - _begin);
- }
- }
-
- }
-
- @Override
- public void setPageContext(PageContext pageContext) {
- super.setPageContext(pageContext);
- }
-
- /**
- * Return expression for page variables
- *
- * @param expr
- * @return
- */
- private ValueExpression getVarExpression(ValueExpression expr) {
- Object o = expr.getValue(pageContext.getELContext());
- if (o.getClass().isArray() || o instanceof List) {
- return new IndexedValueExpression(_value, index);
- }
-
- if (o instanceof Collection || o instanceof Iterator
- || o instanceof Enumeration || o instanceof Map
- || o instanceof String) {
-
- if (iteratedExpression == null) {
- iteratedExpression = new IteratedExpression(_value, getDelims());
- }
- return new IteratedValueExpression(iteratedExpression, index);
- }
-
- throw new ELException("FOREACH_BAD_ITEMS");
- }
-
- /*
- * Get the delimiter for string tokens. Used only for constructing the
- * deferred expression for it.
- */
- protected String getDelims() {
- return ",";
- }
-
- /**
- * Inits first iteration item
- */
- private void correctFirst() {
- try {
- if (items != null) {
- if (_begin > 0 && (index < (_begin - 1))) {
- while ((index < (_begin - 1)) && hasNext()) {
- next();
- }
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
-
- /**
- * <p>
- * Pop the top {@link UIComponentTag} instance off of our component tag
- * stack, deleting the stack if this was the last entry.
- * </p>
- */
- private void popUIComponentClassicTagBase() {
- FacesContext context = FacesContext.getCurrentInstance();
- Map<String, Object> requestMap = context.getExternalContext()
- .getRequestMap();
- List list = (List) requestMap.get(COMPONENT_TAG_STACK_ATTR);
- if (list != null) {
- list.remove(list.size() - 1);
- if (list.size() < 1) {
- requestMap.remove(COMPONENT_TAG_STACK_ATTR);
- }
- }
-
- }
-
- /**
- * <p>
- * Push the specified {@link UIComponentTag} instance onto our component tag
- * stack, creating a stack if necessary.
- * </p>
- */
- private void pushUIComponentClassicTagBase(UIComponentClassicTagBase tag) {
- FacesContext context = FacesContext.getCurrentInstance();
- Map<String, Object> requestMap = context.getExternalContext()
- .getRequestMap();
- List<UIComponentClassicTagBase> list = TypedCollections
- .dynamicallyCastList((List) requestMap
- .get(COMPONENT_TAG_STACK_ATTR),
- UIComponentClassicTagBase.class);
- if (list == null) {
- // noinspection CollectionWithoutInitialCapacity
- list = new ArrayList<UIComponentClassicTagBase>();
- requestMap.put(COMPONENT_TAG_STACK_ATTR, list);
- }
- list.add(tag);
-
- }
-
- /**
- * @return the begin
- */
- public ValueExpression getBegin() {
- return begin;
- }
-
- /**
- * @param begin
- * the begin to set
- */
- public void setBegin(ValueExpression begin) {
- this.begin = begin;
- }
-
- /**
- * @return the columns
- */
- public ValueExpression getColumns() {
- return columns;
- }
-
- /**
- * @param columns
- * the columns to set
- */
- public void setColumns(ValueExpression columns) {
- this.columns = columns;
- }
-
- /**
- * @return the index
- */
- public ValueExpression getIndex() {
- return _index;
- }
-
- /**
- * @param index
- * the index to set
- */
- public void setIndex(ValueExpression index) {
- this._index = index;
- }
-
- /**
- * @return the end
- */
- public ValueExpression getEnd() {
- return end;
- }
-
- /**
- * @param end
- * the end to set
- */
- public void setEnd(ValueExpression end) {
- this.end = end;
- }
-
-}
Copied: trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag.java (from rev 8672, trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag2.java)
===================================================================
--- trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag.java (rev 0)
+++ trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag.java 2008-05-22 11:03:33 UTC (rev 8686)
@@ -0,0 +1,1003 @@
+package org.richfaces.taglib;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.ELResolver;
+import javax.el.FunctionMapper;
+import javax.el.MethodExpression;
+import javax.el.ValueExpression;
+import javax.el.VariableMapper;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.webapp.UIComponentClassicTagBase;
+import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspTagException;
+import javax.servlet.jsp.PageContext;
+import javax.servlet.jsp.tagext.IterationTag;
+
+import org.richfaces.component.UIColumn;
+import org.richfaces.iterator.ForEachIterator;
+import org.richfaces.iterator.SimpleForEachIterator;
+import org.richfaces.renderkit.CellRenderer;
+
+@SuppressWarnings("unused")
+public class ColumnsTag extends UIComponentClassicTagBase implements
+ IterationTag {
+
+ /** Data table */
+ private UIComponent dataTable;
+
+ /** Prefix before id to be assigned for column */
+ private static final String COLUMN_ID_PREFIX = "rf";
+
+ /** Flag indicates if columns are already created */
+ private boolean created = false;
+
+ /** Current column counter */
+ private Integer index = -1;
+
+ /** Iterator for columns's tag value attribute */
+ protected ForEachIterator items; // our 'digested' items
+
+ /** Value attribute value */
+ protected Object rawItems; // our 'raw' items
+
+ /** End attribute - defines count of column if value attr hasn't been defined */
+ private ValueExpression __columns;
+
+ /** Begin attribute - defines the first iteration item */
+ private ValueExpression __begin;
+
+ /** Begin attribute - defines the last iteration item */
+ private ValueExpression __end;
+
+ /** Index attr - defines page variable for current column counter */
+ private ValueExpression _index;
+
+ /** Var attr - defines page variable for current item */
+ private String indexId;
+
+ /** Integer value of end attr. */
+ private Integer columns;
+
+ /** Integer value of begin attr. */
+ private Integer begin;
+
+ /** Integer value of end attr. */
+ private Integer end;
+
+ /** String value of var attr */
+ private String itemId = null;
+
+ /** Expression for var item */
+ private IteratedExpression iteratedExpression;
+
+ /** Column incrementer */
+ private Integer counter = 0;
+
+ /**
+ * style CSS style(s) is/are to be applied when this component is rendered
+ */
+ private ValueExpression _style;
+
+ /*
+ * sortBy Attribute defines a bean property which is used for sorting of a
+ * column
+ */
+ private ValueExpression _sortBy;
+
+ /**
+ * sortOrder SortOrder is an enumeration of the possible sort orderings.
+ */
+ private ValueExpression _sortOrder;
+
+ /**
+ * value The current value for this component
+ */
+ private ValueExpression __value;
+
+ /**
+ * var A request-scope attribute via which the data object for the current
+ * row will be used when iterating
+ */
+ private ValueExpression __var;
+
+ /**
+ * breakBefore if "true" next column begins from the first row
+ */
+ private ValueExpression _breakBefore;
+
+ /**
+ * colspan Corresponds to the HTML colspan attribute
+ */
+ private ValueExpression _colspan;
+
+ /**
+ * Dir attr
+ */
+ private ValueExpression _dir;
+
+ /*
+ * filterDefaultLabel
+ *
+ */
+ private ValueExpression _filterDefaultLabel;
+
+ /**
+ * comparator
+ *
+ */
+ private ValueExpression _comparator;
+
+ /*
+ * filterEvent Event for filter input that forces the filtration (default =
+ * onchange)
+ */
+ private ValueExpression _filterEvent;
+
+ /*
+ * filterExpression Attribute defines a bean property which is used for
+ * filtering of a column
+ */
+ private ValueExpression _filterExpression;
+
+ /*
+ * filterMethod
+ *
+ */
+ private MethodExpression _filterMethod;
+
+ /*
+ * filterValue
+ *
+ */
+ private ValueExpression _filterValue;
+
+ /*
+ * filterBy
+ *
+ */
+ private ValueExpression _filterBy;
+
+ /**
+ * footerClass Space-separated list of CSS style class(es) that are be
+ * applied to any footer generated for this table
+ */
+ private ValueExpression _footerClass;
+
+ /**
+ * headerClass Space-separated list of CSS style class(es) that are be
+ * applied to any header generated for this table
+ */
+ private ValueExpression _headerClass;
+
+ /**
+ * rowspan Corresponds to the HTML rowspan attribute
+ */
+ private ValueExpression _rowspan;
+
+ /**
+ * selfSorted
+ *
+ */
+ private ValueExpression _selfSorted;
+
+ /**
+ * sortable Boolean attribute. If "true" it's possible to sort the column
+ * content after click on the header. Default value is "true"
+ */
+ private ValueExpression _sortable;
+
+ /**
+ * sortExpression Attribute defines a bean property which is used for
+ * sorting of a column
+ */
+ private ValueExpression _sortExpression;
+
+ /**
+ * styleClass Corresponds to the HTML class attribute
+ */
+ private ValueExpression _styleClass;
+
+ /*
+ * width Attribute defines width of column. Default value is "100px".
+ */
+ private ValueExpression _width;
+
+ /**
+ * SortOrder is an enumeration of the possible sort orderings. Setter for
+ * sortOrder
+ *
+ * @param sortOrder -
+ * new value
+ */
+ public void setSortOrder(ValueExpression __sortOrder) {
+ this._sortOrder = __sortOrder;
+ }
+
+ /**
+ * Attribute defines a bean property which is used for sorting of a column
+ * Setter for sortBy
+ *
+ * @param sortBy -
+ * new value
+ */
+ public void setSortBy(ValueExpression __sortBy) {
+ this._sortBy = __sortBy;
+ }
+
+ /**
+ * CSS style(s) is/are to be applied when this component is rendered Setter
+ * for style
+ *
+ * @param style -
+ * new value
+ */
+ public void setStyle(ValueExpression __style) {
+ this._style = __style;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.webapp.UIComponentClassicTagBase#doStartTag()
+ */
+ @Override
+ public int doStartTag() throws JspException {
+
+ prepare();
+
+ if (hasNext()) {
+ next();
+ exposeVariables();
+ super.doStartTag();
+ } else {
+ return SKIP_BODY;
+ }
+
+ return EVAL_BODY_BUFFERED;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.webapp.UIComponentClassicTagBase#doAfterBody()
+ */
+ @Override
+ public int doAfterBody() throws JspException {
+ try {
+ if (hasNext()) {
+ super.doAfterBody();
+ super.doEndTag();
+ next();
+ exposeVariables();
+ super.doStartTag();
+ return EVAL_BODY_AGAIN;
+ } else {
+ super.doAfterBody();
+ exposeVariables();
+ return EVAL_BODY_INCLUDE;
+ }
+
+ } catch (Exception e) {
+ throw new JspException(e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.webapp.UIComponentClassicTagBase#doEndTag()
+ */
+ @Override
+ public int doEndTag() throws JspException {
+ if (!atFirst()) {
+ return super.doEndTag();
+ }
+ return EVAL_PAGE;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.webapp.UIComponentClassicTagBase#doInitBody()
+ */
+ @Override
+ public void doInitBody() throws JspException {
+
+ }
+
+ @Override
+ protected UIComponent createComponent(FacesContext context, String newId)
+ throws JspException {
+ UIComponent c = getFacesContext().getApplication().createComponent(
+ getComponentType());
+ c.setId(generateColumnId());
+ c.setTransient(false);
+ setProperties(c);
+ return c;
+ }
+
+ @Override
+ protected boolean hasBinding() {
+ return false;
+ }
+
+ @Override
+ protected void setProperties(UIComponent component) {
+ ELContext elContext = getContext(pageContext.getELContext());
+
+ Field[] fields = this.getClass().getDeclaredFields();
+ for (Field field : fields) {
+ try {
+ Object o = field.get(this);
+ if ((o != null) && (o instanceof ValueExpression)) {
+ String fieldName = field.getName();
+ if (fieldName != null && fieldName.startsWith("_")) {
+ String attributeName = fieldName.replace("_", "");
+ ValueExpression ex = (ValueExpression) o;
+ ex = createValueExpression(elContext, ex);
+ component.setValueExpression(attributeName, ex);
+ }
+
+ }
+ } catch (Exception e) {
+ continue;
+ }
+ }
+ }
+
+ /**
+ * Creates value expression to be out into column
+ *
+ * @param context
+ * @param orig
+ * @return
+ */
+ private ValueExpression createValueExpression(ELContext context,
+ ValueExpression orig) {
+ ValueExpression vexpr = getFacesContext().getApplication()
+ .getExpressionFactory().createValueExpression(context,
+ orig.getExpressionString(), orig.getExpectedType());
+ return vexpr;
+ }
+
+ /**
+ * Deletes dynamic rich columns created before
+ */
+ private void deleteRichColumns() {
+ List<UIComponent> children = dataTable.getChildren();
+ Iterator<UIComponent> it = children.iterator();
+ List<UIComponent> forDelete = new ArrayList<UIComponent>();
+ Integer i = 0;
+ while (it.hasNext()) {
+ UIComponent child = it.next();
+ String id = child.getId();
+ if (id != null && id.startsWith(COLUMN_ID_PREFIX)) {
+ forDelete.add(child);
+ }
+ i++;
+ }
+ it = forDelete.iterator();
+ while (it.hasNext()) {
+ UIComponent elem = it.next();
+ children.remove(elem);
+ }
+ }
+
+ /**
+ * Method prepares all we need for starting of tag rendering
+ *
+ * @throws JspTagException
+ */
+ private void prepare() throws JspTagException {
+ dataTable = getParentUIComponentClassicTagBase(pageContext)
+ .getComponentInstance();
+ created = (dataTable.getChildCount() > 0);
+
+ if (created) {
+ deleteRichColumns();
+ }
+
+ initVariables();
+
+ // produce the right sort of ForEachIterator
+ if (__value != null) {
+ // If this is a deferred expression, make a note and get
+ // the 'items' instance.
+ if (__value instanceof ValueExpression) {
+ rawItems = __value.getValue(pageContext.getELContext());
+ }
+ // extract an iterator over the 'items' we've got
+ items = SimpleForEachIterator
+ .supportedTypeForEachIterator(rawItems);
+ } else {
+ // no 'items', so use 'begin' and 'end'
+ items = SimpleForEachIterator.beginEndForEachIterator(columns - 1);
+ }
+
+ correctFirst();
+
+ /*
+ * ResultSet no more supported in <c:forEach> // step must be 1 when
+ * ResultSet is passed in if (rawItems instanceof ResultSet && step !=
+ * 1) throw new JspTagException(
+ * Resources.getMessage("FOREACH_STEP_NO_RESULTSET"));
+ */
+
+ }
+
+ /**
+ * Extracts tags attributes values
+ */
+ private void initVariables() {
+ initColumnsCount();
+ initIndex();
+ initVar();
+ initBegin();
+ initEnd();
+ }
+
+ private void initItarationId() {
+ String jspId = getJspId();
+ if (jspId != null) {
+ setJspId(getJspId()); // We need it twice!
+ setJspId(getJspId());
+ }
+ }
+
+ /**
+ * Extracts integer value from end attr
+ */
+ private void initColumnsCount() {
+ if (__columns != null) {
+ if (__columns instanceof ValueExpression)
+ try {
+ String t = (String) __columns.getValue(getELContext());
+ columns = Integer.parseInt(t);
+ if (columns < 0) {
+ columns = 0; // If end is negative set up zero
+ }
+ } catch (Exception e) {
+ columns = 0;
+ }
+ } else {
+ columns = 0;
+ }
+ }
+
+ /**
+ * Extracts string value from var attr
+ */
+ private void initVar() {
+ if (__var != null) {
+ try {
+ itemId = (String) __var.getValue(getELContext());
+ } catch (ClassCastException e) {
+ itemId = null;
+ }
+
+ }
+ }
+
+ /**
+ * Extracts string value from index attr
+ */
+ private void initIndex() {
+ if (_index != null) {
+ try {
+ indexId = (String) _index.getValue(getELContext());
+ } catch (ClassCastException e) {
+ indexId = null;
+ }
+
+ }
+ }
+
+ /**
+ * Extracts string value from index attr
+ */
+ private void initBegin() {
+ begin = 0;
+ if (__begin != null) {
+ try {
+ Object o = __begin.getValue(getELContext());
+ if (o instanceof Number) {
+ begin = ((Number)o).intValue();
+ } else if (o instanceof String) {
+ begin = Integer.parseInt((String)o);
+ }
+ begin--; // correct begin value
+ if (begin < 0) {
+ begin = 0;
+ }
+ } catch (ClassCastException e) {
+ begin = 0;
+ }
+
+ }
+ }
+
+ /**
+ * Extracts string value from index attr
+ */
+ private void initEnd() {
+ end = 0;
+ if (__end != null) {
+ try {
+ Object o = __end.getValue(getELContext());
+ if (o instanceof Number) {
+ end = ((Number)o).intValue();
+ } else if (o instanceof String) {
+ end = Integer.parseInt((String)o);
+ }
+ if (end < 0) {
+ end = 0;
+ }
+ } catch (ClassCastException e) {
+ end = 0;
+ }
+
+ }
+ }
+
+ /**
+ * Inits first iteration item
+ */
+ private void correctFirst() {
+ try {
+ if (items != null) {
+ if (begin > 0 && (index < (begin - 1))) {
+ while ((index < (begin - 1)) && hasNext()) {
+ next();
+ }
+ }
+ }
+ } catch (Exception e) {
+ // TODO: handle exception
+ }
+ }
+
+ /**
+ * Return true if we didn't complete column's count
+ *
+ * @return
+ * @throws JspTagException
+ */
+ private boolean hasNext() throws JspTagException {
+ if (end != 0) {
+ return (index < (end - 1)) ? items.hasNext() : false;
+ } else {
+ return items.hasNext();
+ }
+ }
+
+ /**
+ * Iterate to next column
+ *
+ * @return
+ * @throws JspTagException
+ */
+ private Object next() throws JspTagException {
+ Object o = items.next();
+ initItarationId();
+ index++;
+ return o;
+ }
+
+ /**
+ * Returns true if this is the first loop of columns tag
+ *
+ * @return
+ */
+ private boolean atFirst() {
+ return (index == begin - 1);
+ }
+
+ private String generateColumnId() {
+ return COLUMN_ID_PREFIX + Integer.toString(index);
+ }
+
+ /**
+ * Create custom context with VariableMapper override.
+ *
+ * @param context
+ * @return
+ */
+ private ELContext getContext(final ELContext cont) {
+ return new ELContext() {
+
+ @Override
+ public ELResolver getELResolver() {
+ // TODO Auto-generated method stub
+ return cont.getELResolver();
+ }
+
+ @Override
+ public FunctionMapper getFunctionMapper() {
+ // TODO Auto-generated method stub
+ return cont.getFunctionMapper();
+ }
+
+ @Override
+ public VariableMapper getVariableMapper() {
+ return new VariableMapper() {
+
+ @Override
+ public ValueExpression resolveVariable(String variable) {
+ // TODO Auto-generated method stub
+ if (variable.equals(itemId)) {
+ return new IndexedValueExpression(__value, index);
+ } else if (variable.equals(indexId)) {
+ return new IteratedIndexExpression(index);
+ }
+ return cont.getVariableMapper().resolveVariable(
+ variable);
+ }
+
+ @Override
+ public ValueExpression setVariable(String variable,
+ ValueExpression expression) {
+ // TODO Auto-generated method stub
+ return cont.getVariableMapper().setVariable(variable,
+ expression);
+ }
+
+ };
+ }
+
+ };
+ }
+
+ @Override
+ public String getComponentType() {
+ return UIColumn.COMPONENT_TYPE;
+ }
+
+ @Override
+ public String getRendererType() {
+
+ return CellRenderer.class.getName();
+ }
+
+ /**
+ * Sets page request variables
+ *
+ * @throws JspTagException
+ */
+ private void exposeVariables() throws JspTagException {
+
+ /*
+ * We need to support null items returned from next(); we do this simply
+ * by passing such non-items through to the scoped variable as
+ * effectively 'null' (that is, by calling removeAttribute()).
+ *
+ * Also, just to be defensive, we handle the case of a null 'status'
+ * object as well.
+ *
+ * We call getCurrent() and getLoopStatus() (instead of just using
+ * 'item' and 'status') to bridge to subclasses correctly. A subclass
+ * can override getCurrent() or getLoopStatus() but still depend on our
+ * doStartTag() and doAfterBody(), which call this method
+ * (exposeVariables()), to expose 'item' and 'status' correctly.
+ */
+
+ // Set up var variable
+ if (itemId != null) {
+ if (index == null)
+ pageContext.removeAttribute(itemId, PageContext.PAGE_SCOPE);
+ else if (__value != null) {
+ VariableMapper vm = pageContext.getELContext()
+ .getVariableMapper();
+ if (vm != null) {
+ ValueExpression ve = getVarExpression(__value);
+ vm.setVariable(itemId, ve);
+ }
+ } else
+ pageContext.setAttribute(itemId, index);
+ }
+
+ // Set up index variable
+
+ if (indexId != null) {
+ if (index == null)
+ pageContext.removeAttribute(indexId, PageContext.PAGE_SCOPE);
+ else {
+ IteratedIndexExpression indexExpression = new IteratedIndexExpression(
+ index - begin);
+ VariableMapper vm = pageContext.getELContext()
+ .getVariableMapper();
+ if (vm != null) {
+ vm.setVariable(indexId, indexExpression);
+ }
+ }
+ }
+
+ }
+
+ /**
+ * Return expression for page variables
+ *
+ * @param expr
+ * @return
+ */
+ private ValueExpression getVarExpression(ValueExpression expr) {
+ Object o = expr.getValue(pageContext.getELContext());
+ if (o.getClass().isArray() || o instanceof List) {
+ return new IndexedValueExpression(__value, index);
+ }
+
+ if (o instanceof Collection || o instanceof Iterator
+ || o instanceof Enumeration || o instanceof Map
+ || o instanceof String) {
+
+ if (iteratedExpression == null) {
+ iteratedExpression = new IteratedExpression(__value, getDelims());
+ }
+ return new IteratedValueExpression(iteratedExpression, index);
+ }
+
+ throw new ELException("FOREACH_BAD_ITEMS");
+ }
+
+ /*
+ * Get the delimiter for string tokens. Used only for constructing the
+ * deferred expression for it.
+ */
+ protected String getDelims() {
+ return ",";
+ }
+
+ /**
+ * @param end
+ * the end to set
+ */
+ public void setEnd(ValueExpression end) {
+ this.__end = end;
+ }
+
+ /**
+ * @param begin
+ * the begin to set
+ */
+ public void setBegin(ValueExpression begin) {
+ this.__begin = begin;
+ }
+
+ /**
+ * @param columns
+ * the columns to set
+ */
+ public void setColumns(ValueExpression columns) {
+ this.__columns = columns;
+ }
+
+ /**
+ * @param index
+ * the index to set
+ */
+ public void setIndex(ValueExpression index) {
+ this._index = index;
+ }
+
+ /**
+ * The current value for this component Setter for value
+ *
+ * @param value -
+ * new value
+ */
+ public void setValue(ValueExpression __value) {
+ this.__value = __value;
+ }
+
+ /**
+ * A request-scope attribute via which the data object for the current row
+ * will be used when iterating Setter for var
+ *
+ * @param var -
+ * new value
+ */
+ public void setVar(ValueExpression __var) {
+ this.__var = __var;
+ }
+
+ /**
+ * Corresponds to the HTML colspan attribute Setter for colspan
+ *
+ * @param colspan -
+ * new value
+ */
+ public void setColspan(ValueExpression __colspan) {
+ this._colspan = __colspan;
+ }
+
+ /**
+ * Corresponds to the HTML class attribute Setter for styleClass
+ *
+ * @param styleClass -
+ * new value
+ */
+ public void setStyleClass(ValueExpression __styleClass) {
+ this._styleClass = __styleClass;
+ }
+
+ /**
+ * Attribute defines width of column. Default value is "100px". Setter for
+ * width
+ *
+ * @param width -
+ * new value
+ */
+ public void setWidth(ValueExpression __width) {
+ this._width = __width;
+ }
+
+ /**
+ * if "true" next column begins from the first row Setter for breakBefore
+ *
+ * @param breakBefore -
+ * new value
+ */
+ public void setBreakBefore(ValueExpression __breakBefore) {
+ this._breakBefore = __breakBefore;
+ }
+
+ /**
+ *
+ * Setter for comparator
+ *
+ * @param comparator -
+ * new value
+ */
+ public void setComparator(ValueExpression __comparator) {
+ this._comparator = __comparator;
+ }
+
+ /**
+ * Sets dir attr
+ *
+ * @param dir
+ */
+ public void setDir(ValueExpression dir) {
+ _dir = dir;
+ }
+
+ /**
+ *
+ * Setter for filterBy
+ *
+ * @param filterBy -
+ * new value
+ */
+ public void setFilterBy(ValueExpression __filterBy) {
+ this._filterBy = __filterBy;
+ }
+
+ /**
+ *
+ * Setter for filterDefaultLabel
+ *
+ * @param filterDefaultLabel -
+ * new value
+ */
+ public void setFilterDefaultLabel(ValueExpression __filterDefaultLabel) {
+ this._filterDefaultLabel = __filterDefaultLabel;
+ }
+
+ /**
+ * Event for filter input that forces the filtration (default = onchange)
+ * Setter for filterEvent
+ *
+ * @param filterEvent -
+ * new value
+ */
+ public void setFilterEvent(ValueExpression __filterEvent) {
+ this._filterEvent = __filterEvent;
+ }
+
+ /**
+ * Attribute defines a bean property which is used for filtering of a column
+ * Setter for filterExpression
+ *
+ * @param filterExpression -
+ * new value
+ */
+ public void setFilterExpression(ValueExpression __filterExpression) {
+ this._filterExpression = __filterExpression;
+ }
+
+ /**
+ *
+ * Setter for filterMethod
+ *
+ * @param filterMethod -
+ * new value
+ */
+ public void setFilterMethod(MethodExpression __filterMethod) {
+ this._filterMethod = __filterMethod;
+ }
+
+ /**
+ *
+ * Setter for filterValue
+ *
+ * @param filterValue -
+ * new value
+ */
+ public void setFilterValue(ValueExpression __filterValue) {
+ this._filterValue = __filterValue;
+ }
+
+ /**
+ * Space-separated list of CSS style class(es) that are be applied to any
+ * footer generated for this table Setter for footerClass
+ *
+ * @param footerClass -
+ * new value
+ */
+ public void setFooterClass(ValueExpression __footerClass) {
+ this._footerClass = __footerClass;
+ }
+
+ /**
+ * Space-separated list of CSS style class(es) that are be applied to any
+ * header generated for this table Setter for headerClass
+ *
+ * @param headerClass -
+ * new value
+ */
+ public void setHeaderClass(ValueExpression __headerClass) {
+ this._headerClass = __headerClass;
+ }
+
+ /**
+ * Corresponds to the HTML rowspan attribute Setter for rowspan
+ *
+ * @param rowspan -
+ * new value
+ */
+ public void setRowspan(ValueExpression __rowspan) {
+ this._rowspan = __rowspan;
+ }
+
+ /**
+ *
+ * Setter for selfSorted
+ *
+ * @param selfSorted -
+ * new value
+ */
+ public void setSelfSorted(ValueExpression __selfSorted) {
+ this._selfSorted = __selfSorted;
+ }
+
+ /**
+ * Boolean attribute. If "true" it's possible to sort the column content
+ * after click on the header. Default value is "true" Setter for sortable
+ *
+ * @param sortable -
+ * new value
+ */
+ public void setSortable(ValueExpression __sortable) {
+ this._sortable = __sortable;
+ }
+
+ /**
+ * Attribute defines a bean property which is used for sorting of a column
+ * Setter for sortExpression
+ *
+ * @param sortExpression -
+ * new value
+ */
+ public void setSortExpression(ValueExpression __sortExpression) {
+ this._sortExpression = __sortExpression;
+ }
+}
Deleted: trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag2.java
===================================================================
--- trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag2.java 2008-05-22 11:02:54 UTC (rev 8685)
+++ trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag2.java 2008-05-22 11:03:33 UTC (rev 8686)
@@ -1,992 +0,0 @@
-package org.richfaces.taglib;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.el.ELContext;
-import javax.el.ELException;
-import javax.el.ELResolver;
-import javax.el.FunctionMapper;
-import javax.el.MethodExpression;
-import javax.el.ValueExpression;
-import javax.el.VariableMapper;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.webapp.UIComponentClassicTagBase;
-import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.JspTagException;
-import javax.servlet.jsp.PageContext;
-import javax.servlet.jsp.tagext.IterationTag;
-
-import org.richfaces.component.UIColumn;
-import org.richfaces.iterator.ForEachIterator;
-import org.richfaces.iterator.SimpleForEachIterator;
-import org.richfaces.renderkit.CellRenderer;
-
-@SuppressWarnings("unused")
-public class ColumnsTag2 extends UIComponentClassicTagBase implements
- IterationTag {
-
- /** Data table */
- private UIComponent dataTable;
-
- /** Prefix before id to be assigned for column */
- private static final String COLUMN_ID_PREFIX = "rf";
-
- /** Flag indicates if columns are already created */
- private boolean created = false;
-
- /** Current column counter */
- private Integer index = -1;
-
- /** Iterator for columns's tag value attribute */
- protected ForEachIterator items; // our 'digested' items
-
- /** Value attribute value */
- protected Object rawItems; // our 'raw' items
-
- /** End attribute - defines count of column if value attr hasn't been defined */
- private ValueExpression __columns;
-
- /** Begin attribute - defines the first iteration item */
- private ValueExpression __begin;
-
- /** Begin attribute - defines the last iteration item */
- private ValueExpression __end;
-
- /** Index attr - defines page variable for current column counter */
- private ValueExpression _index;
-
- /** Var attr - defines page variable for current item */
- private String indexId;
-
- /** Integer value of end attr. */
- private Integer columns;
-
- /** Integer value of begin attr. */
- private Integer begin;
-
- /** Integer value of end attr. */
- private Integer end;
-
- /** String value of var attr */
- private String itemId = null;
-
- /** Expression for var item */
- private IteratedExpression iteratedExpression;
-
- /** Column incrementer */
- private Integer counter = 0;
-
- /**
- * style CSS style(s) is/are to be applied when this component is rendered
- */
- private ValueExpression _style;
-
- /*
- * sortBy Attribute defines a bean property which is used for sorting of a
- * column
- */
- private ValueExpression _sortBy;
-
- /**
- * sortOrder SortOrder is an enumeration of the possible sort orderings.
- */
- private ValueExpression _sortOrder;
-
- /**
- * value The current value for this component
- */
- private ValueExpression __value;
-
- /**
- * var A request-scope attribute via which the data object for the current
- * row will be used when iterating
- */
- private ValueExpression __var;
-
- /**
- * breakBefore if "true" next column begins from the first row
- */
- private ValueExpression _breakBefore;
-
- /**
- * colspan Corresponds to the HTML colspan attribute
- */
- private ValueExpression _colspan;
-
- /**
- * Dir attr
- */
- private ValueExpression _dir;
-
- /*
- * filterDefaultLabel
- *
- */
- private ValueExpression _filterDefaultLabel;
-
- /**
- * comparator
- *
- */
- private ValueExpression _comparator;
-
- /*
- * filterEvent Event for filter input that forces the filtration (default =
- * onchange)
- */
- private ValueExpression _filterEvent;
-
- /*
- * filterExpression Attribute defines a bean property which is used for
- * filtering of a column
- */
- private ValueExpression _filterExpression;
-
- /*
- * filterMethod
- *
- */
- private MethodExpression _filterMethod;
-
- /*
- * filterValue
- *
- */
- private ValueExpression _filterValue;
-
- /*
- * filterBy
- *
- */
- private ValueExpression _filterBy;
-
- /**
- * footerClass Space-separated list of CSS style class(es) that are be
- * applied to any footer generated for this table
- */
- private ValueExpression _footerClass;
-
- /**
- * headerClass Space-separated list of CSS style class(es) that are be
- * applied to any header generated for this table
- */
- private ValueExpression _headerClass;
-
- /**
- * rowspan Corresponds to the HTML rowspan attribute
- */
- private ValueExpression _rowspan;
-
- /**
- * selfSorted
- *
- */
- private ValueExpression _selfSorted;
-
- /**
- * sortable Boolean attribute. If "true" it's possible to sort the column
- * content after click on the header. Default value is "true"
- */
- private ValueExpression _sortable;
-
- /**
- * sortExpression Attribute defines a bean property which is used for
- * sorting of a column
- */
- private ValueExpression _sortExpression;
-
- /**
- * styleClass Corresponds to the HTML class attribute
- */
- private ValueExpression _styleClass;
-
- /*
- * width Attribute defines width of column. Default value is "100px".
- */
- private ValueExpression _width;
-
- /**
- * SortOrder is an enumeration of the possible sort orderings. Setter for
- * sortOrder
- *
- * @param sortOrder -
- * new value
- */
- public void setSortOrder(ValueExpression __sortOrder) {
- this._sortOrder = __sortOrder;
- }
-
- /**
- * Attribute defines a bean property which is used for sorting of a column
- * Setter for sortBy
- *
- * @param sortBy -
- * new value
- */
- public void setSortBy(ValueExpression __sortBy) {
- this._sortBy = __sortBy;
- }
-
- /**
- * CSS style(s) is/are to be applied when this component is rendered Setter
- * for style
- *
- * @param style -
- * new value
- */
- public void setStyle(ValueExpression __style) {
- this._style = __style;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.webapp.UIComponentClassicTagBase#doStartTag()
- */
- @Override
- public int doStartTag() throws JspException {
-
- prepare();
-
- if (hasNext()) {
- next();
- exposeVariables();
- super.doStartTag();
- } else {
- return SKIP_BODY;
- }
-
- return EVAL_BODY_BUFFERED;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.webapp.UIComponentClassicTagBase#doAfterBody()
- */
- @Override
- public int doAfterBody() throws JspException {
- try {
- if (hasNext()) {
- super.doAfterBody();
- super.doEndTag();
- next();
- exposeVariables();
- super.doStartTag();
- return EVAL_BODY_AGAIN;
- } else {
- super.doAfterBody();
- exposeVariables();
- return EVAL_BODY_INCLUDE;
- }
-
- } catch (Exception e) {
- throw new JspException(e);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.webapp.UIComponentClassicTagBase#doEndTag()
- */
- @Override
- public int doEndTag() throws JspException {
- if (!atFirst()) {
- return super.doEndTag();
- }
- return EVAL_PAGE;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.webapp.UIComponentClassicTagBase#doInitBody()
- */
- @Override
- public void doInitBody() throws JspException {
-
- }
-
- @Override
- protected UIComponent createComponent(FacesContext context, String newId)
- throws JspException {
- UIComponent c = getFacesContext().getApplication().createComponent(
- getComponentType());
- c.setId(generateColumnId());
- c.setTransient(false);
- setProperties(c);
- return c;
- }
-
- @Override
- protected boolean hasBinding() {
- return false;
- }
-
- @Override
- protected void setProperties(UIComponent component) {
- ELContext elContext = getContext(pageContext.getELContext());
-
- Field[] fields = this.getClass().getDeclaredFields();
- for (Field field : fields) {
- try {
- Object o = field.get(this);
- if ((o != null) && (o instanceof ValueExpression)) {
- String fieldName = field.getName();
- if (fieldName != null && fieldName.startsWith("_")) {
- String attributeName = fieldName.replace("_", "");
- ValueExpression ex = (ValueExpression) o;
- ex = createValueExpression(elContext, ex);
- component.setValueExpression(attributeName, ex);
- }
-
- }
- } catch (Exception e) {
- continue;
- }
- }
- }
-
- /**
- * Creates value expression to be out into column
- *
- * @param context
- * @param orig
- * @return
- */
- private ValueExpression createValueExpression(ELContext context,
- ValueExpression orig) {
- ValueExpression vexpr = getFacesContext().getApplication()
- .getExpressionFactory().createValueExpression(context,
- orig.getExpressionString(), orig.getExpectedType());
- return vexpr;
- }
-
- /**
- * Deletes dynamic rich columns created before
- */
- private void deleteRichColumns() {
- List<UIComponent> children = dataTable.getChildren();
- Iterator<UIComponent> it = children.iterator();
- List<UIComponent> forDelete = new ArrayList<UIComponent>();
- Integer i = 0;
- while (it.hasNext()) {
- UIComponent child = it.next();
- String id = child.getId();
- if (id != null && id.startsWith(COLUMN_ID_PREFIX)) {
- forDelete.add(child);
- }
- i++;
- }
- it = forDelete.iterator();
- while (it.hasNext()) {
- UIComponent elem = it.next();
- children.remove(elem);
- }
- }
-
- /**
- * Method prepares all we need for starting of tag rendering
- *
- * @throws JspTagException
- */
- private void prepare() throws JspTagException {
- dataTable = getParentUIComponentClassicTagBase(pageContext)
- .getComponentInstance();
- created = (dataTable.getChildCount() > 0);
-
- if (created) {
- deleteRichColumns();
- }
-
- initVariables();
-
- // produce the right sort of ForEachIterator
- if (__value != null) {
- // If this is a deferred expression, make a note and get
- // the 'items' instance.
- if (__value instanceof ValueExpression) {
- rawItems = __value.getValue(pageContext.getELContext());
- }
- // extract an iterator over the 'items' we've got
- items = SimpleForEachIterator
- .supportedTypeForEachIterator(rawItems);
- } else {
- // no 'items', so use 'begin' and 'end'
- items = SimpleForEachIterator.beginEndForEachIterator(columns - 1);
- }
-
- correctFirst();
-
- /*
- * ResultSet no more supported in <c:forEach> // step must be 1 when
- * ResultSet is passed in if (rawItems instanceof ResultSet && step !=
- * 1) throw new JspTagException(
- * Resources.getMessage("FOREACH_STEP_NO_RESULTSET"));
- */
-
- }
-
- /**
- * Extracts tags attributes values
- */
- private void initVariables() {
- initColumnsCount();
- initIndex();
- initVar();
- initBegin();
- initEnd();
- }
-
- private void initItarationId() {
- setJspId(getJspId()); // We need it twice!
- setJspId(getJspId());
- }
-
- /**
- * Extracts integer value from end attr
- */
- private void initColumnsCount() {
- if (__columns != null) {
- if (__columns instanceof ValueExpression)
- try {
- String t = (String) __columns.getValue(getELContext());
- columns = Integer.parseInt(t);
- if (columns < 0) {
- columns = 0; // If end is negative set up zero
- }
- } catch (Exception e) {
- columns = 0;
- }
- } else {
- columns = 0;
- }
- }
-
- /**
- * Extracts string value from var attr
- */
- private void initVar() {
- if (__var != null) {
- try {
- itemId = (String) __var.getValue(getELContext());
- } catch (ClassCastException e) {
- itemId = null;
- }
-
- }
- }
-
- /**
- * Extracts string value from index attr
- */
- private void initIndex() {
- if (_index != null) {
- try {
- indexId = (String) _index.getValue(getELContext());
- } catch (ClassCastException e) {
- indexId = null;
- }
-
- }
- }
-
- /**
- * Extracts string value from index attr
- */
- private void initBegin() {
- begin = 0;
- if (__begin != null) {
- try {
- String t = (String) __begin.getValue(getELContext());
- begin = Integer.parseInt(t);
- begin--; // correct begin value
- if (begin < 0) {
- begin = 0;
- }
- } catch (ClassCastException e) {
- begin = 0;
- }
-
- }
- }
-
- /**
- * Extracts string value from index attr
- */
- private void initEnd() {
- end = 0;
- if (__end != null) {
- try {
- String t = (String) __end.getValue(getELContext());
- end = Integer.parseInt(t);
- if (end < 0) {
- end = 0;
- }
- } catch (ClassCastException e) {
- end = 0;
- }
-
- }
- }
-
- /**
- * Inits first iteration item
- */
- private void correctFirst() {
- try {
- if (items != null) {
- if (begin > 0 && (index < (begin - 1))) {
- while ((index < (begin - 1)) && hasNext()) {
- next();
- }
- }
- }
- } catch (Exception e) {
- // TODO: handle exception
- }
- }
-
- /**
- * Return true if we didn't complete column's count
- *
- * @return
- * @throws JspTagException
- */
- private boolean hasNext() throws JspTagException {
- if (end != 0) {
- return (index < (end - 1)) ? items.hasNext() : false;
- } else {
- return items.hasNext();
- }
- }
-
- /**
- * Iterate to next column
- *
- * @return
- * @throws JspTagException
- */
- private Object next() throws JspTagException {
- Object o = items.next();
- initItarationId();
- index++;
- return o;
- }
-
- /**
- * Returns true if this is the first loop of columns tag
- *
- * @return
- */
- private boolean atFirst() {
- return (index == begin - 1);
- }
-
- private String generateColumnId() {
- return COLUMN_ID_PREFIX + Integer.toString(index);
- }
-
- /**
- * Create custom context with VariableMapper override.
- *
- * @param context
- * @return
- */
- private ELContext getContext(final ELContext cont) {
- return new ELContext() {
-
- @Override
- public ELResolver getELResolver() {
- // TODO Auto-generated method stub
- return cont.getELResolver();
- }
-
- @Override
- public FunctionMapper getFunctionMapper() {
- // TODO Auto-generated method stub
- return cont.getFunctionMapper();
- }
-
- @Override
- public VariableMapper getVariableMapper() {
- return new VariableMapper() {
-
- @Override
- public ValueExpression resolveVariable(String variable) {
- // TODO Auto-generated method stub
- if (variable.equals(itemId)) {
- return new IndexedValueExpression(__value, index);
- } else if (variable.equals(indexId)) {
- return new IteratedIndexExpression(index);
- }
- return cont.getVariableMapper().resolveVariable(
- variable);
- }
-
- @Override
- public ValueExpression setVariable(String variable,
- ValueExpression expression) {
- // TODO Auto-generated method stub
- return cont.getVariableMapper().setVariable(variable,
- expression);
- }
-
- };
- }
-
- };
- }
-
- @Override
- public String getComponentType() {
- return UIColumn.COMPONENT_TYPE;
- }
-
- @Override
- public String getRendererType() {
-
- return CellRenderer.class.getName();
- }
-
- /**
- * Sets page request variables
- *
- * @throws JspTagException
- */
- private void exposeVariables() throws JspTagException {
-
- /*
- * We need to support null items returned from next(); we do this simply
- * by passing such non-items through to the scoped variable as
- * effectively 'null' (that is, by calling removeAttribute()).
- *
- * Also, just to be defensive, we handle the case of a null 'status'
- * object as well.
- *
- * We call getCurrent() and getLoopStatus() (instead of just using
- * 'item' and 'status') to bridge to subclasses correctly. A subclass
- * can override getCurrent() or getLoopStatus() but still depend on our
- * doStartTag() and doAfterBody(), which call this method
- * (exposeVariables()), to expose 'item' and 'status' correctly.
- */
-
- // Set up var variable
- if (itemId != null) {
- if (index == null)
- pageContext.removeAttribute(itemId, PageContext.PAGE_SCOPE);
- else if (__value != null) {
- VariableMapper vm = pageContext.getELContext()
- .getVariableMapper();
- if (vm != null) {
- ValueExpression ve = getVarExpression(__value);
- vm.setVariable(itemId, ve);
- }
- } else
- pageContext.setAttribute(itemId, index);
- }
-
- // Set up index variable
-
- if (indexId != null) {
- if (index == null)
- pageContext.removeAttribute(indexId, PageContext.PAGE_SCOPE);
- else {
- IteratedIndexExpression indexExpression = new IteratedIndexExpression(
- index - begin);
- VariableMapper vm = pageContext.getELContext()
- .getVariableMapper();
- if (vm != null) {
- vm.setVariable(indexId, indexExpression);
- }
- }
- }
-
- }
-
- /**
- * Return expression for page variables
- *
- * @param expr
- * @return
- */
- private ValueExpression getVarExpression(ValueExpression expr) {
- Object o = expr.getValue(pageContext.getELContext());
- if (o.getClass().isArray() || o instanceof List) {
- return new IndexedValueExpression(__value, index);
- }
-
- if (o instanceof Collection || o instanceof Iterator
- || o instanceof Enumeration || o instanceof Map
- || o instanceof String) {
-
- if (iteratedExpression == null) {
- iteratedExpression = new IteratedExpression(__value, getDelims());
- }
- return new IteratedValueExpression(iteratedExpression, index);
- }
-
- throw new ELException("FOREACH_BAD_ITEMS");
- }
-
- /*
- * Get the delimiter for string tokens. Used only for constructing the
- * deferred expression for it.
- */
- protected String getDelims() {
- return ",";
- }
-
- /**
- * @param end
- * the end to set
- */
- public void setEnd(ValueExpression end) {
- this.__end = end;
- }
-
- /**
- * @param begin
- * the begin to set
- */
- public void setBegin(ValueExpression begin) {
- this.__begin = begin;
- }
-
- /**
- * @param columns
- * the columns to set
- */
- public void setColumns(ValueExpression columns) {
- this.__columns = columns;
- }
-
- /**
- * @param index
- * the index to set
- */
- public void setIndex(ValueExpression index) {
- this._index = index;
- }
-
- /**
- * The current value for this component Setter for value
- *
- * @param value -
- * new value
- */
- public void setValue(ValueExpression __value) {
- this.__value = __value;
- }
-
- /**
- * A request-scope attribute via which the data object for the current row
- * will be used when iterating Setter for var
- *
- * @param var -
- * new value
- */
- public void setVar(ValueExpression __var) {
- this.__var = __var;
- }
-
- /**
- * Corresponds to the HTML colspan attribute Setter for colspan
- *
- * @param colspan -
- * new value
- */
- public void setColspan(ValueExpression __colspan) {
- this._colspan = __colspan;
- }
-
- /**
- * Corresponds to the HTML class attribute Setter for styleClass
- *
- * @param styleClass -
- * new value
- */
- public void setStyleClass(ValueExpression __styleClass) {
- this._styleClass = __styleClass;
- }
-
- /**
- * Attribute defines width of column. Default value is "100px". Setter for
- * width
- *
- * @param width -
- * new value
- */
- public void setWidth(ValueExpression __width) {
- this._width = __width;
- }
-
- /**
- * if "true" next column begins from the first row Setter for breakBefore
- *
- * @param breakBefore -
- * new value
- */
- public void setBreakBefore(ValueExpression __breakBefore) {
- this._breakBefore = __breakBefore;
- }
-
- /**
- *
- * Setter for comparator
- *
- * @param comparator -
- * new value
- */
- public void setComparator(ValueExpression __comparator) {
- this._comparator = __comparator;
- }
-
- /**
- * Sets dir attr
- *
- * @param dir
- */
- public void setDir(ValueExpression dir) {
- _dir = dir;
- }
-
- /**
- *
- * Setter for filterBy
- *
- * @param filterBy -
- * new value
- */
- public void setFilterBy(ValueExpression __filterBy) {
- this._filterBy = __filterBy;
- }
-
- /**
- *
- * Setter for filterDefaultLabel
- *
- * @param filterDefaultLabel -
- * new value
- */
- public void setFilterDefaultLabel(ValueExpression __filterDefaultLabel) {
- this._filterDefaultLabel = __filterDefaultLabel;
- }
-
- /**
- * Event for filter input that forces the filtration (default = onchange)
- * Setter for filterEvent
- *
- * @param filterEvent -
- * new value
- */
- public void setFilterEvent(ValueExpression __filterEvent) {
- this._filterEvent = __filterEvent;
- }
-
- /**
- * Attribute defines a bean property which is used for filtering of a column
- * Setter for filterExpression
- *
- * @param filterExpression -
- * new value
- */
- public void setFilterExpression(ValueExpression __filterExpression) {
- this._filterExpression = __filterExpression;
- }
-
- /**
- *
- * Setter for filterMethod
- *
- * @param filterMethod -
- * new value
- */
- public void setFilterMethod(MethodExpression __filterMethod) {
- this._filterMethod = __filterMethod;
- }
-
- /**
- *
- * Setter for filterValue
- *
- * @param filterValue -
- * new value
- */
- public void setFilterValue(ValueExpression __filterValue) {
- this._filterValue = __filterValue;
- }
-
- /**
- * Space-separated list of CSS style class(es) that are be applied to any
- * footer generated for this table Setter for footerClass
- *
- * @param footerClass -
- * new value
- */
- public void setFooterClass(ValueExpression __footerClass) {
- this._footerClass = __footerClass;
- }
-
- /**
- * Space-separated list of CSS style class(es) that are be applied to any
- * header generated for this table Setter for headerClass
- *
- * @param headerClass -
- * new value
- */
- public void setHeaderClass(ValueExpression __headerClass) {
- this._headerClass = __headerClass;
- }
-
- /**
- * Corresponds to the HTML rowspan attribute Setter for rowspan
- *
- * @param rowspan -
- * new value
- */
- public void setRowspan(ValueExpression __rowspan) {
- this._rowspan = __rowspan;
- }
-
- /**
- *
- * Setter for selfSorted
- *
- * @param selfSorted -
- * new value
- */
- public void setSelfSorted(ValueExpression __selfSorted) {
- this._selfSorted = __selfSorted;
- }
-
- /**
- * Boolean attribute. If "true" it's possible to sort the column content
- * after click on the header. Default value is "true" Setter for sortable
- *
- * @param sortable -
- * new value
- */
- public void setSortable(ValueExpression __sortable) {
- this._sortable = __sortable;
- }
-
- /**
- * Attribute defines a bean property which is used for sorting of a column
- * Setter for sortExpression
- *
- * @param sortExpression -
- * new value
- */
- public void setSortExpression(ValueExpression __sortExpression) {
- this._sortExpression = __sortExpression;
- }
-}
Modified: trunk/ui/columns/src/main/java/org/richfaces/taglib/ComponentHandler.java
===================================================================
--- trunk/ui/columns/src/main/java/org/richfaces/taglib/ComponentHandler.java 2008-05-22 11:02:54 UTC (rev 8685)
+++ trunk/ui/columns/src/main/java/org/richfaces/taglib/ComponentHandler.java 2008-05-22 11:03:33 UTC (rev 8686)
@@ -219,7 +219,12 @@
this.begin = getAttribute("begin");
if (begin != null) {
try {
- _begin = Integer.parseInt((String) begin.getObject(ctx));
+ Object o = begin.getObject(ctx);
+ if (o instanceof Number) {
+ _begin = ((Number)o).intValue();
+ }else if (o instanceof String) {
+ _begin = Integer.parseInt((String) o);
+ }
_begin--;
if (_begin < 0) {
_begin = 0; // If end is negative set up zero
@@ -239,7 +244,12 @@
this.end = getAttribute("end");
if (end != null) {
try {
- _end = Integer.parseInt((String) end.getObject(ctx));
+ Object o = end.getObject(ctx);
+ if (o instanceof Number) {
+ _end = ((Number)o).intValue();
+ }else if ( o instanceof String) {
+ _end = Integer.parseInt((String) o);
+ }
if (_end < 0) {
_end = 0; // If end is negative set up zero
}
Modified: trunk/ui/columns/src/test/java/org/richfaces/jsp/tag/ColumnsJspTagTest.java
===================================================================
--- trunk/ui/columns/src/test/java/org/richfaces/jsp/tag/ColumnsJspTagTest.java 2008-05-22 11:02:54 UTC (rev 8685)
+++ trunk/ui/columns/src/test/java/org/richfaces/jsp/tag/ColumnsJspTagTest.java 2008-05-22 11:03:33 UTC (rev 8686)
@@ -69,6 +69,7 @@
HtmlDataTable dataTable = new HtmlDataTable();
DataTableTagMock mock = new DataTableTagMock(dataTable);
+ mock.setPageContext(new MockPageContext());
List<UIComponentClassicTagBase> list = new ArrayList<UIComponentClassicTagBase>();
list.add(mock);
16 years, 7 months
JBoss Rich Faces SVN: r8685 - trunk/framework/test/src/main/java/org/ajax4jsf/tests.
by richfaces-svn-commits@lists.jboss.org
Author: andrei_exadel
Date: 2008-05-22 07:02:54 -0400 (Thu, 22 May 2008)
New Revision: 8685
Modified:
trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockPageContext.java
Log:
Changes to avoid test failure in columns component
Modified: trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockPageContext.java
===================================================================
--- trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockPageContext.java 2008-05-22 09:33:39 UTC (rev 8684)
+++ trunk/framework/test/src/main/java/org/ajax4jsf/tests/MockPageContext.java 2008-05-22 11:02:54 UTC (rev 8685)
@@ -246,7 +246,165 @@
@Override
public JspWriter getOut() {
// TODO Auto-generated method stub
- return null;
+ return new JspWriter(0, false) {
+
+ @Override
+ public void clear() throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void clearBuffer() throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void close() throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void flush() throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public int getRemaining() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public void newLine() throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void print(boolean b) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void print(char c) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void print(int i) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void print(long l) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void print(float f) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void print(double d) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void print(char[] s) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void print(String s) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void print(Object obj) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void println() throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void println(boolean x) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void println(char x) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void println(int x) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void println(long x) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void println(float x) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void println(double x) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void println(char[] x) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void println(String x) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void println(Object x) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ // TODO Auto-generated method stub
+
+ }
+
+ };
}
/* (non-Javadoc)
16 years, 7 months
JBoss Rich Faces SVN: r8684 - trunk/test-applications/seleniumTest/src/test/java/org/richfaces.
by richfaces-svn-commits@lists.jboss.org
Author: dsvyatobatsko
Date: 2008-05-22 05:33:39 -0400 (Thu, 22 May 2008)
New Revision: 8684
Modified:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/ComboBoxTest.java
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/DropDownMenuTest.java
Log:
fixed some broken tests
Modified: trunk/test-applications/seleniumTest/src/test/java/org/richfaces/ComboBoxTest.java
===================================================================
--- trunk/test-applications/seleniumTest/src/test/java/org/richfaces/ComboBoxTest.java 2008-05-22 09:10:21 UTC (rev 8683)
+++ trunk/test-applications/seleniumTest/src/test/java/org/richfaces/ComboBoxTest.java 2008-05-22 09:33:39 UTC (rev 8684)
@@ -47,7 +47,7 @@
String selectItemsCBId = parentId + "selectItems";
String suggestionValuesCBId = parentId + "suggestionValues";
- writeStatus("check components\\' default labels");
+ writeStatus("check components' default labels");
getTextById(predefinedCBId + "comboboxField").startsWith("Select a");
getTextById(selectItemsCBId + "comboboxField").startsWith("Select a");
Modified: trunk/test-applications/seleniumTest/src/test/java/org/richfaces/DropDownMenuTest.java
===================================================================
--- trunk/test-applications/seleniumTest/src/test/java/org/richfaces/DropDownMenuTest.java 2008-05-22 09:10:21 UTC (rev 8683)
+++ trunk/test-applications/seleniumTest/src/test/java/org/richfaces/DropDownMenuTest.java 2008-05-22 09:33:39 UTC (rev 8684)
@@ -76,7 +76,7 @@
AssertTextEquals(operation, "Close");
- writeStatus("Check menu item in \\'none\\' mode");
+ writeStatus("Check menu item in 'none' mode");
selenium.mouseOver(file);
selenium.mouseOver(exit);
16 years, 7 months
JBoss Rich Faces SVN: r8683 - in trunk: ui/pickList/src/main/config/component and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: cluts
Date: 2008-05-22 05:10:21 -0400 (Thu, 22 May 2008)
New Revision: 8683
Modified:
trunk/docs/userguide/en/src/main/docbook/included/pickList.xml
trunk/ui/pickList/src/main/config/component/picklist.xml
Log:
RF-3092 - added information about moveControlsVerticalAlign attribute; fixed description
Modified: trunk/docs/userguide/en/src/main/docbook/included/pickList.xml
===================================================================
--- trunk/docs/userguide/en/src/main/docbook/included/pickList.xml 2008-05-22 08:55:29 UTC (rev 8682)
+++ trunk/docs/userguide/en/src/main/docbook/included/pickList.xml 2008-05-22 09:10:21 UTC (rev 8683)
@@ -136,6 +136,7 @@
With the help of <emphasis><property>"moveControlsVerticalAlign"</property></emphasis> attribute
you can align <property>move controls</property> vertically.
</para>
+ <para>The possible value for <emphasis><property>"moveControlsVerticalAlign"</property></emphasis> are <property>"top"</property>, <property>"bottom"</property> and <property>"center"</property>(default value).</para>
<para>
The <emphasis role="bold">
Modified: trunk/ui/pickList/src/main/config/component/picklist.xml
===================================================================
--- trunk/ui/pickList/src/main/config/component/picklist.xml 2008-05-22 08:55:29 UTC (rev 8682)
+++ trunk/ui/pickList/src/main/config/component/picklist.xml 2008-05-22 09:10:21 UTC (rev 8683)
@@ -140,7 +140,7 @@
<property>
<name>moveControlsVerticalAlign</name>
<classname>java.lang.String</classname>
- <description>Customizes vertically a position of move/copy controls relatively to lists</description>
+ <description>Customizes vertically a position of move/copy controls relatively to lists. Default value is "center".</description>
</property>
<property>
@@ -210,20 +210,20 @@
<property hidden="true">
<name>size</name>
<classname>int</classname>
- </property>
-
- <property hidden="true" >
- <name>onchange</name>
- <classname>java.lang.String</classname>
- </property>
- <property hidden="true" >
- <name>onfocus</name>
- <classname>java.lang.String</classname>
- </property>
- <property hidden="true" >
- <name>onblur</name>
- <classname>java.lang.String</classname>
</property>
+
+ <property hidden="true" >
+ <name>onchange</name>
+ <classname>java.lang.String</classname>
+ </property>
+ <property hidden="true" >
+ <name>onfocus</name>
+ <classname>java.lang.String</classname>
+ </property>
+ <property hidden="true" >
+ <name>onblur</name>
+ <classname>java.lang.String</classname>
+ </property>
</properties>
16 years, 7 months
JBoss Rich Faces SVN: r8682 - in trunk/test-applications/seleniumTest/src: main/webapp/pages/ajaxPoll and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: andrei_exadel
Date: 2008-05-22 04:55:29 -0400 (Thu, 22 May 2008)
New Revision: 8682
Removed:
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandButtonTest.java
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandLinkTest.java
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxPollTest.java
Modified:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/A4JPollTestBean.java
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/TestListener.java
trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxPoll/ajaxPollTest.xhtml
Log:
restore failed tests
Modified: trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/A4JPollTestBean.java
===================================================================
--- trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/A4JPollTestBean.java 2008-05-21 17:38:32 UTC (rev 8681)
+++ trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/A4JPollTestBean.java 2008-05-22 08:55:29 UTC (rev 8682)
@@ -8,11 +8,15 @@
private static final String POLLING = "Polling";
- private boolean enabled = true;
+ private boolean enabled = false;
+ public void start(ActionEvent event) {
+ enabled = true;
+ }
+
public void listener(ActionEvent event) {
i++;
- if (i == 7) {
+ if (i == 8) {
enabled = false;
}
}
Modified: trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/TestListener.java
===================================================================
--- trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/TestListener.java 2008-05-21 17:38:32 UTC (rev 8681)
+++ trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/TestListener.java 2008-05-22 08:55:29 UTC (rev 8682)
@@ -22,6 +22,7 @@
UIInput i = (UIInput)component;
String v = (String)i.getValue();
i.setValue(v + "5");
+ i.setSubmittedValue(null);
}
Modified: trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxPoll/ajaxPollTest.xhtml
===================================================================
--- trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxPoll/ajaxPollTest.xhtml 2008-05-21 17:38:32 UTC (rev 8681)
+++ trunk/test-applications/seleniumTest/src/main/webapp/pages/ajaxPoll/ajaxPollTest.xhtml 2008-05-22 08:55:29 UTC (rev 8682)
@@ -9,9 +9,12 @@
<ui:composition template="#{templateBean.template}">
<ui:define name="component">
<h:form id="_form">
+ <h:selectBooleanCheckbox id="_enabled" value="#{pollBean.enabled}">
+ <a4j:support event="onchange" ajaxSingle="true" reRender="_form"></a4j:support>
+ </h:selectBooleanCheckbox>
<a4j:poll interval="700" id="poll" enabled="#{pollBean.enabled}" actionListener="#{pollBean.listener}" reRender="_value, _text"></a4j:poll><br/>
<h:inputHidden id="_value" value="#{pollBean.i}"/>
- <h:outputText id="_text" value="#{pollBean.text}" />
+ <h:outputText id="_text" value="#{pollBean.text}" rendered="#{pollBean.enabled}"/>
</h:form>
</ui:define>
</ui:composition>
Deleted: trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandButtonTest.java
===================================================================
--- trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandButtonTest.java 2008-05-21 17:38:32 UTC (rev 8681)
+++ trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandButtonTest.java 2008-05-22 08:55:29 UTC (rev 8682)
@@ -1,94 +0,0 @@
-package org.richfaces;
-
-import org.ajax4jsf.test.base.RichSeleniumTest;
-import org.ajax4jsf.test.base.SeleniumTestBase;
-import org.ajax4jsf.test.base.Templates;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Parameters;
-import org.testng.annotations.Test;
-
-
-public class AjaxCommandButtonTest extends SeleniumTestBase implements RichSeleniumTest {
-
- public AjaxCommandButtonTest() {
- super("http", "localhost", "8080");
- }
-
- /**
- * This method are invoking before selenium tests started
- */
- @BeforeTest
- @Parameters( { "browser" })
- public void startSelenium(String browser) {
- super.startSelenium(browser);
- }
-
- /**
- * This method are invoking after selenium tests completed
- */
- @AfterTest
- public void stopSelenium() {
- super.stopSelenium();
- }
-
- @Test
- public void testAjaxCommandButtonComponent() throws Exception {
- _testAjaxCommandButtonComponent(Templates.SIMPLE);
- _testAjaxCommandButtonComponent(Templates.DATATABLE);
- _testAjaxCommandButtonComponent(Templates.MODALPANEL);
- }
-
- private void _testAjaxCommandButtonComponent(Templates template) {
- renderPage(getTestUrl(), template);
-
- String parentId = getParentId() + "_form:";
-
- String buttonId = parentId + "b1";
- String inputId = parentId + "_value";
-
- writeStatus("Click button 1 : ");
- clickById(buttonId);
- waitForAjaxCompletion();
- AssertValueEquals(inputId, "12345");
-
- writeStatus("Click button 1 again: ");
- clickById(buttonId);
- waitForAjaxCompletion();
- AssertValueEquals(inputId, "123452345");
-
- buttonId = parentId + "b2";
-
- writeStatus("Click button 2: ");
- clickById(buttonId);
- waitForAjaxCompletion();
- AssertValueEquals(inputId, "123452345");
-
- buttonId = parentId + "b3";
-
- writeStatus("Click button 3: ");
- clickById(buttonId);
- waitForAjaxCompletion();
- AssertValueEquals(inputId, "123452345");
-
- buttonId = parentId + "b4";
-
- writeStatus("Click button 4: ");
- clickById(buttonId);
- waitForAjaxCompletion();
- AssertValueEquals(inputId, "12345234555");
-
- buttonId = parentId + "b5";
-
- writeStatus("Click button 5: ");
- clickById(buttonId);
- waitForAjaxCompletion();
- AssertValueEquals(inputId, "12345234555");
-
- }
-
- public String getTestUrl() {
- return "/faces/pages/ajaxCommandButton/ajaxButtonTest.xhtml";
- }
-
-}
Deleted: trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandLinkTest.java
===================================================================
--- trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandLinkTest.java 2008-05-21 17:38:32 UTC (rev 8681)
+++ trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxCommandLinkTest.java 2008-05-22 08:55:29 UTC (rev 8682)
@@ -1,93 +0,0 @@
-package org.richfaces;
-
-import org.ajax4jsf.test.base.RichSeleniumTest;
-import org.ajax4jsf.test.base.SeleniumTestBase;
-import org.ajax4jsf.test.base.Templates;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Parameters;
-import org.testng.annotations.Test;
-
-public class AjaxCommandLinkTest extends SeleniumTestBase implements RichSeleniumTest {
-
- public AjaxCommandLinkTest() {
- super("http", "localhost", "8080");
- }
-
- /**
- * This method are invoking before selenium tests started
- */
- @BeforeTest
- @Parameters( { "browser" })
- public void startSelenium(String browser) {
- super.startSelenium(browser);
- }
-
- /**
- * This method are invoking after selenium tests completed
- */
- @AfterTest
- public void stopSelenium() {
- super.stopSelenium();
- }
-
- @Test
- public void testAjaxCommandLinkComponent() throws Exception {
- _testAjaxCommandLinkComponent(Templates.SIMPLE);
- _testAjaxCommandLinkComponent(Templates.DATATABLE);
- _testAjaxCommandLinkComponent(Templates.MODALPANEL);
- }
-
- private void _testAjaxCommandLinkComponent(Templates template) {
- renderPage(getTestUrl(), template);
-
- String parentId = getParentId() + "_form:";
-
- String LinkId = parentId + "l1";
- String inputId = parentId + "_value";
-
- writeStatus("Click link 1 : ");
- clickById(LinkId);
- waitForAjaxCompletion();
- AssertValueEquals(inputId, "12345");
-
- writeStatus("Click link 1 again: ");
- clickById(LinkId);
- waitForAjaxCompletion();
- AssertValueEquals(inputId, "123452345");
-
- LinkId = parentId + "l2";
-
- writeStatus("Click link 2 : ");
- clickById(LinkId);
- waitForAjaxCompletion();
- AssertValueEquals(inputId, "123452345");
-
- LinkId = parentId + "l3";
-
- writeStatus("Click link 3 : ");
- clickById(LinkId);
- waitForAjaxCompletion();
- AssertValueEquals(inputId, "123452345");
-
- LinkId = parentId + "l4";
-
- writeStatus("Click link 4 : ");
- clickById(LinkId);
- waitForAjaxCompletion();
- AssertValueEquals(inputId, "12345234555");
-
- LinkId = parentId + "l5";
-
- writeStatus("Click link 5 : ");
- clickById(LinkId);
- waitForAjaxCompletion();
- AssertValueEquals(inputId, "12345234555");
-
- }
-
- public String getTestUrl() {
- return "/faces/pages/ajaxCommandLink/ajaxLinkTest.xhtml";
- }
-
-}
Deleted: trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxPollTest.java
===================================================================
--- trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxPollTest.java 2008-05-21 17:38:32 UTC (rev 8681)
+++ trunk/test-applications/seleniumTest/src/test/java/org/richfaces/AjaxPollTest.java 2008-05-22 08:55:29 UTC (rev 8682)
@@ -1,76 +0,0 @@
-/**
- *
- */
-package org.richfaces;
-
-import org.ajax4jsf.test.base.RichSeleniumTest;
-import org.ajax4jsf.test.base.SeleniumTestBase;
-import org.ajax4jsf.test.base.Templates;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Parameters;
-import org.testng.annotations.Test;
-
-/**
- * @author Andrey Markavstov
- *
- */
-public class AjaxPollTest extends SeleniumTestBase implements RichSeleniumTest {
-
- public AjaxPollTest() {
- super("http", "localhost", "8080");
- }
-
- /**
- * This method are invoking before selenium tests started
- */
- @BeforeTest
- @Parameters( { "browser" })
- public void startSelenium(String browser) {
- super.startSelenium(browser);
- }
-
- /**
- * This method are invoking after selenium tests completed
- */
- @AfterTest
- public void stopSelenium() {
- super.stopSelenium();
- }
-
- @Test
- public void testAjaxPollComponent() {
- _testAjaxPollComponent(Templates.SIMPLE);
- _testAjaxPollComponent(Templates.DATATABLE);
- _testAjaxPollComponent(Templates.MODALPANEL);
- }
-
- private void _testAjaxPollComponent(Templates template) {
- renderPage(getTestUrl(), template);
- String parentId = getParentId() + "_form:";
- String pollId = parentId + "poll";
- String inputId = parentId + "_value";
-
- writeStatus("Polling in progress...");
- AssertValueEquals(inputId, "1");
- pause(1500, pollId);
- AssertValueNotEquals(inputId, "1");
- waiteForCondition("document.getElementById('"+inputId+"').value == 7", 7000);
-
- pause(1500, pollId);
- writeStatus("Polling should be stopped...");
- AssertValueEquals(inputId, "7");
- AssertTextEquals(parentId + "_text", "Polling");
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.ajax4jsf.test.base.RichSeleniumTest#getTestUrl()
- */
- public String getTestUrl() {
- return "/faces/pages/ajaxPoll/ajaxPollTest.xhtml";
- }
-
-}
16 years, 7 months
JBoss Rich Faces SVN: r8681 - in trunk/test-applications/seleniumTest/src: main/webapp/pages/orderingList and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: sergeyhalipov
Date: 2008-05-21 13:38:32 -0400 (Wed, 21 May 2008)
New Revision: 8681
Modified:
trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/OrderingListTestBean.java
trunk/test-applications/seleniumTest/src/main/webapp/pages/orderingList/orderingListTest.xhtml
trunk/test-applications/seleniumTest/src/test/java/org/richfaces/OrderingListTest.java
Log:
Selenium tests for ordering list component completed.
Modified: trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/OrderingListTestBean.java
===================================================================
--- trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/OrderingListTestBean.java 2008-05-21 16:29:08 UTC (rev 8680)
+++ trunk/test-applications/seleniumTest/src/main/java/org/ajax4jsf/OrderingListTestBean.java 2008-05-21 17:38:32 UTC (rev 8681)
@@ -24,6 +24,8 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import javax.faces.component.UIComponent;
@@ -42,6 +44,7 @@
for (int i = 0; i < 4; i++) {
items.add(new Item("item" + i));
}
+ selection = new HashSet<Item>();
}
public Object getActionResult() {
@@ -79,6 +82,18 @@
public void setItems(List<Item> items) {
this.items = items;
}
+
+ public String getSelectionString() {
+ StringBuffer buff = new StringBuffer();
+ for (Iterator<Item> it = selection.iterator(); it.hasNext();) {
+ Item item = it.next();
+ buff.append(item.getName());
+ if (it.hasNext()) {
+ buff.append(',');
+ }
+ }
+ return buff.toString();
+ }
private class ItemConverter implements Converter {
@@ -112,7 +127,7 @@
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("actionResult", name);
return null;
}
-
+
public Item(String name) {
super();
this.name = name;
Modified: trunk/test-applications/seleniumTest/src/main/webapp/pages/orderingList/orderingListTest.xhtml
===================================================================
--- trunk/test-applications/seleniumTest/src/main/webapp/pages/orderingList/orderingListTest.xhtml 2008-05-21 16:29:08 UTC (rev 8680)
+++ trunk/test-applications/seleniumTest/src/main/webapp/pages/orderingList/orderingListTest.xhtml 2008-05-21 17:38:32 UTC (rev 8681)
@@ -18,7 +18,14 @@
captionLabel="Caption Label"
selection="#{orderingListBean.selection}"
- activeItem="#{orderingListBean.activeItem}" >
+ activeItem="#{orderingListBean.activeItem}"
+
+ onbottomclick="window.status = 'bottom';"
+ ondownclick="window.status = 'down';"
+ ontopclick="window.status = 'top';"
+ onupclick="window.status = 'up';"
+ onorderchanged="window.status += ' orderchanged';"
+ >
<h:column>
<f:facet name="header">
@@ -30,7 +37,7 @@
<f:facet name="header">
<h:outputText value="Ajax Action" />
</f:facet>
- <a4j:commandButton value="Ajax Action" reRender="actionResult,messages"
+ <a4j:commandButton value="Ajax Action" reRender="results"
action="#{item.action}" id="#{item.name}_ajax" />
</h:column>
<h:column>
@@ -41,10 +48,14 @@
</h:column>
</rich:orderingList>
+ <br/>
+ <h:panelGroup id="results" >
+ <h:outputText value="#{orderingListBean.actionResult}" id="actionResult" /><br />
+ <h:outputText value="#{orderingListBean.selectionString}" id="selection" /><br />
+ <h:outputText value="#{orderingListBean.activeItem}" id="activeItem" /><br />
+ <rich:messages id="messages" />
+ </h:panelGroup>
<br/>
- <h:outputText value="#{orderingListBean.actionResult}" id="actionResult" />
- <rich:messages id="messages" />
- <br/>
</h:form>
</ui:define>
</ui:composition>
Modified: trunk/test-applications/seleniumTest/src/test/java/org/richfaces/OrderingListTest.java
===================================================================
--- trunk/test-applications/seleniumTest/src/test/java/org/richfaces/OrderingListTest.java 2008-05-21 16:29:08 UTC (rev 8680)
+++ trunk/test-applications/seleniumTest/src/test/java/org/richfaces/OrderingListTest.java 2008-05-21 17:38:32 UTC (rev 8681)
@@ -45,9 +45,12 @@
private String firstRow;
- private String actionResult;
+ private String actionResultText;
private String ajax;
private String server;
+ private String thirdRow;
+ private String selectionText;
+ private String activeItemText;
public OrderingListTest() {
super("http", "localhost", "8080");
@@ -85,6 +88,16 @@
renderPage(getTestUrl(), template);
initFields();
+ _testButtons();
+ _testActions();
+ _testJSFunctions();
+ }
+
+ public String getTestUrl() {
+ return "/faces/pages/orderingList/orderingListTest.xhtml";
+ }
+
+ private void _testButtons() {
writeStatus("Check if all buttons are disabled first time");
checkButtons(true, true, true, true);
@@ -108,26 +121,73 @@
checkButtons(true, true, false, false);
Assert.assertEquals(selenium.getElementIndex("id=" + firstRow), 0);
- writeStatus("Unselect element");
- selenium.controlKeyDown();
- clickById(firstRow);
- selenium.controlKeyUp();
- checkButtons(true, true, true, true);
+ cleanSelection();
+ }
+
+ private void _testActions() {
+ writeStatus("Select two rows");
+ clickById(firstRow);
+ selenium.controlKeyDown();
+ clickById(thirdRow);
+ selenium.controlKeyUp();
+ checkButtons(true, true, false, false);
writeStatus("Click on ajax button");
clickById(ajax);
waitForAjaxCompletion();
- AssertTextEquals(actionResult, "item0");
+ AssertTextEquals(actionResultText, "item0");
+ AssertTextEquals(selectionText, "item0,item2");
+ AssertTextEquals(activeItemText, "Item [item2]");
+ writeStatus("Select one row");
+ clickById(firstRow);
+
writeStatus("Click on server link");
clickCommandAndWait(server);
- AssertTextEquals(actionResult, "item1");
+ AssertTextEquals(actionResultText, "item1");
+ AssertTextEquals(selectionText, "item0");
+ AssertTextEquals(activeItemText, "Item [item0]");
+ checkButtons(true, true, false, false);
+
+ cleanSelection();
}
- public String getTestUrl() {
- return "/faces/pages/orderingList/orderingListTest.xhtml";
+ private void _testJSFunctions() {
+ writeStatus("Select one row");
+ clickById(thirdRow);
+
+ writeStatus("Check if 'onupclick' event works");
+ clickById(upButton);
+ Assert.assertEquals(selenium.getEval("window.status"), "up orderchanged");
+
+ writeStatus("Check if 'ondownclick' event works");
+ clickById(downButton);
+ Assert.assertEquals(selenium.getEval("window.status"), "down orderchanged");
+
+ writeStatus("Check if 'ontopclick' event works");
+ clickById(firstButton);
+ Assert.assertEquals(selenium.getEval("window.status"), "top orderchanged");
+
+ writeStatus("Check if 'onbottomclick' event works");
+ clickById(lastButton);
+ Assert.assertEquals(selenium.getEval("window.status"), "bottom orderchanged");
+
+ cleanSelection();
}
+ private void cleanSelection() {
+ writeStatus("Unselect element");
+ clickById(firstRow);
+ selenium.controlKeyDown();
+ clickById(firstRow);
+ selenium.controlKeyUp();
+ checkButtons(true, true, true, true);
+
+ writeStatus("Submit empty selection to save it into server bean");
+ clickById(ajax);
+ waitForAjaxCompletion();
+ }
+
private void checkButtons(boolean firstDisabled, boolean upDisabled, boolean downDisabled, boolean lastDisabled) {
if (firstDisabled) {
Assert.assertTrue(isVisibleById(firstButtonDisabled));
@@ -178,7 +238,11 @@
lastButtonDisabled = parentId + "dislast";
firstRow = parentId + ":0";
- actionResult = getParentId() + "_form:actionResult";
+ thirdRow = parentId + ":2";
+
+ actionResultText = getParentId() + "_form:actionResult";
+ selectionText = getParentId() + "_form:selection";
+ activeItemText = getParentId() + "_form:activeItem";
ajax = firstRow + ":_ajax";
server = parentId + ":1:_server";
}
16 years, 7 months