Author: lfryc(a)redhat.com
Date: 2010-07-10 14:16:51 -0400 (Sat, 10 Jul 2010)
New Revision: 17821
Added:
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/TemplatesListConverter.java
root/tests/metamer/trunk/src/test/
root/tests/metamer/trunk/src/test/java/
root/tests/metamer/trunk/src/test/java/org/
root/tests/metamer/trunk/src/test/java/org/richfaces/
root/tests/metamer/trunk/src/test/java/org/richfaces/testapp/
root/tests/metamer/trunk/src/test/java/org/richfaces/testapp/TemplatesListTest.java
Modified:
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/Attributes.java
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/TemplateNameConverter.java
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/TemplatesList.java
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/TemplateBean.java
root/tests/metamer/trunk/src/main/webapp/components/a4jCommandButton/simple.xhtml
root/tests/metamer/trunk/src/main/webapp/components/a4jCommandLink/simple.xhtml
root/tests/metamer/trunk/src/main/webapp/components/commandButton/simple.xhtml
Log:
https://jira.jboss.org/jira/browse/RFPL-466
* nested templating fixed
* view parameters handling fixed
* added two tests for class TemplatesList
Modified: root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/Attributes.java
===================================================================
---
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/Attributes.java 2010-07-10
18:15:26 UTC (rev 17820)
+++
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/Attributes.java 2010-07-10
18:16:51 UTC (rev 17821)
@@ -40,6 +40,7 @@
import java.util.regex.Pattern;
import javax.el.ELContext;
+import javax.el.ExpressionFactory;
import javax.el.MethodExpression;
import javax.faces.bean.ManagedBean;
import javax.faces.component.UIComponentBase;
@@ -47,7 +48,6 @@
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
-import org.jboss.el.ExpressionFactoryImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -346,14 +346,15 @@
// if no select options for "action" are defined in property file and
it is an EL expression
if (!hasSelectOptions("action") && isStringEL(outcome)) {
- method = new ExpressionFactoryImpl().createMethodExpression(elContext,
outcome, String.class, new Class[0]);
+ method = ExpressionFactory.newInstance().createMethodExpression(elContext,
outcome, String.class, new Class[0]);
return (String) method.invoke(elContext, null);
}
// if select options for "action" are defined in property file
if (hasSelectOptions("action")) {
- method = new ExpressionFactoryImpl().createMethodExpression(elContext,
getMethodEL(outcome), String.class,
+ method = ExpressionFactory.newInstance().createMethodExpression(elContext,
getMethodEL(outcome), String.class,
new Class[0]);
+
return (String) method.invoke(elContext, null);
}
@@ -374,14 +375,14 @@
// if no select options for "actionListener" are defined in property
file and it is an EL expression
if (!hasSelectOptions("actionListener") &&
isStringEL(listener)) {
- method = new ExpressionFactoryImpl().createMethodExpression(elContext,
listener, void.class,
+ method = ExpressionFactory.newInstance().createMethodExpression(elContext,
listener, void.class,
new Class[] { ActionEvent.class });
method.invoke(elContext, new Object[] { event });
}
// if select options for "actionListener" are defined in property file
if (hasSelectOptions("actionListener")) {
- method = new ExpressionFactoryImpl().createMethodExpression(elContext,
getMethodEL(listener), void.class,
+ method = ExpressionFactory.newInstance().createMethodExpression(elContext,
getMethodEL(listener), void.class,
new Class[] { ActionEvent.class });
method.invoke(elContext, new Object[] { event });
}
Modified:
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/TemplateNameConverter.java
===================================================================
---
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/TemplateNameConverter.java 2010-07-10
18:15:26 UTC (rev 17820)
+++
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/TemplateNameConverter.java 2010-07-10
18:16:51 UTC (rev 17821)
@@ -40,6 +40,7 @@
/**
* {@inheritDoc}
*/
+ @Override
public Object getAsObject(FacesContext context, UIComponent component, String value)
{
try {
return Template.valueOf(value.toUpperCase());
@@ -51,6 +52,7 @@
/**
* {@inheritDoc}
*/
+ @Override
public String getAsString(FacesContext context, UIComponent component, Object value)
{
if (value instanceof String) {
return (String) value;
Modified: root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/TemplatesList.java
===================================================================
---
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/TemplatesList.java 2010-07-10
18:15:26 UTC (rev 17820)
+++
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/TemplatesList.java 2010-07-10
18:16:51 UTC (rev 17821)
@@ -19,7 +19,6 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
*******************************************************************************/
-
package org.richfaces.testapp;
import java.util.ArrayList;
@@ -39,130 +38,167 @@
*/
public class TemplatesList implements List<Template> {
- private List<Template> templates = new ArrayList<Template>();
- private Logger logger = LoggerFactory.getLogger(TemplatesList.class);
+ private List<Template> templates;
+ private Logger logger;
+ public TemplatesList() {
+ logger = LoggerFactory.getLogger(TemplatesList.class);
+ templates = new ArrayList<Template>();
+ templates.add(Template.PLAIN);
+ }
+
+ @Override
public boolean add(Template e) {
- // if list is empty, add template
- if (templates.isEmpty()) {
- return templates.add(e);
+ if (e == Template.PLAIN) {
+ return false;
}
- // if last item in list is plain template, don't do anything
- if (templates.get(size() - 1) == Template.PLAIN) {
- return false;
+ templates.add(templates.size() - 1, e);
+
+ for (Template t : templates) {
+ logger.info(t.toString());
}
- return templates.add(e);
+ return true;
}
+ @Override
public void add(int index, Template element) {
templates.add(index, element);
- // add new item to the list
- // if the last item is being changed, nothing happens, otherwise it will be again
removed
- templates.add(Template.PLAIN);
-
+
// remove the rest of list if plain is set
if (element == Template.PLAIN) {
while (templates.size() > index + 1) {
templates.remove(index + 1);
}
- }
+ }
}
+ @Override
public boolean addAll(Collection<? extends Template> c) {
return templates.addAll(c);
}
+ @Override
public boolean addAll(int index, Collection<? extends Template> c) {
return templates.addAll(index, c);
}
+ @Override
public void clear() {
templates.clear();
}
+ @Override
public boolean contains(Object o) {
- return templates.contains(o);
+ return templates.contains((Template) o);
}
+ @Override
public boolean containsAll(Collection<?> c) {
return templates.containsAll(c);
}
+ @Override
public Template get(int index) {
return templates.get(index);
}
+ @Override
public int indexOf(Object o) {
return templates.indexOf(o);
}
+ @Override
public boolean isEmpty() {
return templates.isEmpty();
}
+ @Override
public Iterator<Template> iterator() {
return templates.iterator();
}
+ @Override
public int lastIndexOf(Object o) {
return templates.lastIndexOf(o);
}
+ @Override
public ListIterator<Template> listIterator() {
return templates.listIterator();
}
+ @Override
public ListIterator<Template> listIterator(int index) {
return templates.listIterator(index);
}
+ @Override
public boolean remove(Object o) {
- return templates.remove(o);
+ return templates.remove((Template) o);
}
+ @Override
public Template remove(int index) {
return templates.remove(index);
}
+ @Override
public boolean removeAll(Collection<?> c) {
return templates.removeAll(c);
}
+ @Override
public boolean retainAll(Collection<?> c) {
return templates.retainAll(c);
}
+ @Override
public Template set(int index, Template element) {
Template old = templates.set(index, element);
-
+
// remove the rest of list if plain is set
if (element == Template.PLAIN) {
while (templates.size() > index + 1) {
templates.remove(index + 1);
}
} else {
- add(Template.PLAIN);
+ if (index == templates.size() - 1) {
+ templates.add(Template.PLAIN);
+ }
}
-
+
return old;
}
+ @Override
public int size() {
return templates.size();
}
+ @Override
public List<Template> subList(int fromIndex, int toIndex) {
return templates.subList(fromIndex, toIndex);
}
+ @Override
public Object[] toArray() {
return templates.toArray();
}
+ @Override
public <T> T[] toArray(T[] a) {
return templates.toArray(a);
}
-}
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ for (Template t : templates) {
+ sb.append(t.toString());
+ sb.append(",");
+ }
+ return sb.toString();
+ }
+}
\ No newline at end of file
Copied:
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/TemplatesListConverter.java
(from rev 17820,
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/TemplateNameConverter.java)
===================================================================
---
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/TemplatesListConverter.java
(rev 0)
+++
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/TemplatesListConverter.java 2010-07-10
18:16:51 UTC (rev 17821)
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
+
+package org.richfaces.testapp;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.FacesConverter;
+
+/**
+ * Converter used for view parameter "template".
+ *
+ * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
+ * @version $Revision$
+ */
+@FacesConverter(value = "templatesListConverter")
+public class TemplatesListConverter implements Converter {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object getAsObject(FacesContext context, UIComponent component, String value)
{
+ try {
+ TemplatesList list = new TemplatesList();
+
+ for (String template : value.split(",")) {
+ list.add(Template.valueOf(template.toUpperCase()));
+ }
+
+ return list;
+ } catch (IllegalArgumentException iae) {
+ throw new FacesException("Cannot convert parameter \"" + value
+ "\" to the list of templates.", iae);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getAsString(FacesContext context, UIComponent component, Object value)
{
+ if (value instanceof String) {
+ return (String) value;
+ }
+
+ if (value instanceof TemplatesList) {
+ return value.toString();
+ }
+
+ throw new FacesException("Cannot convert parameter \"" + value +
"\" to the list of templates.");
+ }
+}
Modified:
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/TemplateBean.java
===================================================================
---
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/TemplateBean.java 2010-07-10
18:15:26 UTC (rev 17820)
+++
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/TemplateBean.java 2010-07-10
18:16:51 UTC (rev 17821)
@@ -49,16 +49,8 @@
dataTableModel.add("2");
}
- public static final String PARAM_NAME = "t";
-
- private Template template = Template.PLAIN;
-
private TemplatesList templates;
- private Template templatePath = Template.PLAIN;
-
- private String methodName;
-
private Integer dataTableRowIndex = 0;
private int templateIndex = 0;
@@ -66,67 +58,19 @@
@PostConstruct
public void init() {
templates = new TemplatesList();
- templates.add(Template.PLAIN);
}
/**
* @return the templates
*/
- public List<Template> getTemplates() {
+ public TemplatesList getTemplates() {
return templates;
}
- public String getTemplateId() {
- return template.toString();
+ public void setTemplates(TemplatesList templates) {
+ this.templates = templates;
}
-
- public void setTemplateId(String template) {
- this.template = Template.valueOf(template);
-// if (this.template.equals(Template.DATA_TABLE)) {
-// dataTableRowIndex = 0;
-// } else if (this.template.equals(Template.DATA_TABLE2)) {
-// dataTableRowIndex = 1;
-// }
- }
-
- public String getParentId() {
- return template.getPrefix();
- }
-
- /**
- * @return the template
- */
- public String getTemplate() {
- return "/templates/" + template.getName() + ".xhtml";
- }
-
- /**
- * @return the template
- */
- public String getAutoTestTemplate() {
- return "/templates/autotest/" + template.getName() +
".xhtml";
- }
-
- /**
- * @return the template
- */
- public String getTemplatePath() {
- return template.getName() + ".xhtml";
- }
-
- /**
- * @param template
- * the template to set
- */
- public void setTemplate(Template template) {
- this.template = template;
- }
-
- public void setTemplatePath(Template templatePath) {
- this.templatePath = templatePath;
- }
-
public List<SelectItem> getAvailableTemplates() {
List<SelectItem> retVal = new ArrayList<SelectItem>();
for (Template template : Template.values()) {
@@ -137,21 +81,6 @@
}
/**
- * @return the methodName
- */
- public String getMethodName() {
- return methodName;
- }
-
- /**
- * @param methodName
- * the methodName to set
- */
- public void setMethodName(String methodName) {
- this.methodName = methodName;
- }
-
- /**
* @return the dataTableRowIndex
*/
public Integer getDataTableRowIndex() {
@@ -165,22 +94,6 @@
return dataTableModel;
}
-// public boolean isRendered(int index) {
-// if (index < 0) {
-// throw new IllegalArgumentException("Template nr. " + index +
" does not exist.");
-// }
-//
-// if (index == 0) {
-// return true;
-// }
-//
-// for (int i = 1; i <= index; i++) {
-// if (templates.get(index-1) == Template.PLAIN) {
-// return false;
-// }
-// }
-// }
-
public String getFirstTemplate() {
templateIndex = 0;
return templates.get(0).toString().toLowerCase();
Modified:
root/tests/metamer/trunk/src/main/webapp/components/a4jCommandButton/simple.xhtml
===================================================================
---
root/tests/metamer/trunk/src/main/webapp/components/a4jCommandButton/simple.xhtml 2010-07-10
18:15:26 UTC (rev 17820)
+++
root/tests/metamer/trunk/src/main/webapp/components/a4jCommandButton/simple.xhtml 2010-07-10
18:16:51 UTC (rev 17821)
@@ -7,8 +7,8 @@
<ui:define name="head">
<f:metadata>
- <f:viewParam name="template"
value="#{templateBean.templateId}">
- <f:converter converterId="templateNameConverter" />
+ <f:viewParam name="templates"
value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
</f:viewParam>
</f:metadata>
Modified: root/tests/metamer/trunk/src/main/webapp/components/a4jCommandLink/simple.xhtml
===================================================================
---
root/tests/metamer/trunk/src/main/webapp/components/a4jCommandLink/simple.xhtml 2010-07-10
18:15:26 UTC (rev 17820)
+++
root/tests/metamer/trunk/src/main/webapp/components/a4jCommandLink/simple.xhtml 2010-07-10
18:16:51 UTC (rev 17821)
@@ -7,8 +7,8 @@
<ui:define name="head">
<f:metadata>
- <f:viewParam name="template"
value="#{templateBean.templateId}">
- <f:converter converterId="templateNameConverter" />
+ <f:viewParam name="templates"
value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
</f:viewParam>
</f:metadata>
Modified: root/tests/metamer/trunk/src/main/webapp/components/commandButton/simple.xhtml
===================================================================
---
root/tests/metamer/trunk/src/main/webapp/components/commandButton/simple.xhtml 2010-07-10
18:15:26 UTC (rev 17820)
+++
root/tests/metamer/trunk/src/main/webapp/components/commandButton/simple.xhtml 2010-07-10
18:16:51 UTC (rev 17821)
@@ -7,8 +7,8 @@
<ui:define name="head">
<f:metadata>
- <f:viewParam name="template"
value="#{templateBean.templateId}">
- <f:converter converterId="templateNameConverter" />
+ <f:viewParam name="templates"
value="#{templateBean.templates}">
+ <f:converter converterId="templatesListConverter" />
</f:viewParam>
</f:metadata>
Added:
root/tests/metamer/trunk/src/test/java/org/richfaces/testapp/TemplatesListTest.java
===================================================================
--- root/tests/metamer/trunk/src/test/java/org/richfaces/testapp/TemplatesListTest.java
(rev 0)
+++
root/tests/metamer/trunk/src/test/java/org/richfaces/testapp/TemplatesListTest.java 2010-07-10
18:16:51 UTC (rev 17821)
@@ -0,0 +1,45 @@
+package org.richfaces.testapp;
+
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+/**
+ *
+ * @author Pavol Pitonak
+ */
+public class TemplatesListTest {
+
+ private TemplatesList templates;
+
+ @BeforeMethod
+ public void setUpTest() {
+ templates = new TemplatesList();
+ }
+
+ @Test
+ public void testNewList() {
+ assertEquals(templates.size(), 1, "New list should contain one
element");
+ assertEquals(templates.get(0), Template.PLAIN, "New list should contain
plain template");
+ }
+
+ @Test
+ public void testSetIntTemplate() {
+ templates.set(0, Template.RED_DIV);
+ assertEquals(templates.size(), 2, "Size after red_div was inserted on
position 0");
+ assertEquals(templates.get(0), Template.RED_DIV, "position 0");
+ assertEquals(templates.get(1), Template.PLAIN, "position 1");
+
+ templates.set(1, Template.BLUE_DIV);
+ assertEquals(templates.size(), 3, "Size after blue_div was inserted on
position 1");
+ assertEquals(templates.get(0), Template.RED_DIV, "position 0");
+ assertEquals(templates.get(1), Template.BLUE_DIV, "position 1");
+ assertEquals(templates.get(2), Template.PLAIN, "position 2");
+
+ templates.set(0, Template.BLUE_DIV);
+ assertEquals(templates.size(), 3, "Size after blue_div was inserted on
position 0");
+ assertEquals(templates.get(0), Template.BLUE_DIV, "position 0");
+ assertEquals(templates.get(1), Template.BLUE_DIV, "position 1");
+ assertEquals(templates.get(2), Template.PLAIN, "position 2");
+ }
+}