Author: lfryc(a)redhat.com
Date: 2010-07-10 14:11:56 -0400 (Sat, 10 Jul 2010)
New Revision: 17817
Added:
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/TemplatesList.java
root/tests/metamer/trunk/src/main/webapp/templates/blue_div.xhtml
root/tests/metamer/trunk/src/main/webapp/templates/red_div.xhtml
Removed:
root/tests/metamer/trunk/src/main/webapp/templates/reddiv.xhtml
Modified:
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/Template.java
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/TemplateBean.java
root/tests/metamer/trunk/src/main/webapp/components/a4jCommandLink/simple.xhtml
root/tests/metamer/trunk/src/main/webapp/templates/header.xhtml
root/tests/metamer/trunk/src/main/webapp/templates/plain.xhtml
root/tests/metamer/trunk/src/main/webapp/templates/template.xhtml
Log:
https://jira.jboss.org/jira/browse/RFPL-466
* added nested templating
Modified: root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/Template.java
===================================================================
--- root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/Template.java 2010-07-10
18:10:54 UTC (rev 17816)
+++ root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/Template.java 2010-07-10
18:11:56 UTC (rev 17817)
@@ -27,7 +27,8 @@
*/
public enum Template {
PLAIN ("plain", "", "Plain"),
- RED_DIV ("reddiv", "", "Red div");
+ RED_DIV ("red_div", "", "Red div"),
+ BLUE_DIV ("blue_div", "", "Blue div");
private String name;
Added: root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/TemplatesList.java
===================================================================
--- root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/TemplatesList.java
(rev 0)
+++
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/TemplatesList.java 2010-07-10
18:11:56 UTC (rev 17817)
@@ -0,0 +1,168 @@
+/*******************************************************************************
+ * 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 java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ *
+ * @author <a href="mailto:ppitonak@redhat.com">Pavol Pitonak</a>
+ * @version $Revision$
+ */
+public class TemplatesList implements List<Template> {
+
+ private List<Template> templates = new ArrayList<Template>();
+ private Logger logger = LoggerFactory.getLogger(TemplatesList.class);
+
+ public boolean add(Template e) {
+ // if list is empty, add template
+ if (templates.isEmpty()) {
+ return templates.add(e);
+ }
+
+ // if last item in list is plain template, don't do anything
+ if (templates.get(size() - 1) == Template.PLAIN) {
+ return false;
+ }
+
+ return templates.add(e);
+ }
+
+ 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);
+ }
+ }
+ }
+
+ public boolean addAll(Collection<? extends Template> c) {
+ return templates.addAll(c);
+ }
+
+ public boolean addAll(int index, Collection<? extends Template> c) {
+ return templates.addAll(index, c);
+ }
+
+ public void clear() {
+ templates.clear();
+ }
+
+ public boolean contains(Object o) {
+ return templates.contains(o);
+ }
+
+ public boolean containsAll(Collection<?> c) {
+ return templates.containsAll(c);
+ }
+
+ public Template get(int index) {
+ return templates.get(index);
+ }
+
+ public int indexOf(Object o) {
+ return templates.indexOf(o);
+ }
+
+ public boolean isEmpty() {
+ return templates.isEmpty();
+ }
+
+ public Iterator<Template> iterator() {
+ return templates.iterator();
+ }
+
+ public int lastIndexOf(Object o) {
+ return templates.lastIndexOf(o);
+ }
+
+ public ListIterator<Template> listIterator() {
+ return templates.listIterator();
+ }
+
+ public ListIterator<Template> listIterator(int index) {
+ return templates.listIterator(index);
+ }
+
+ public boolean remove(Object o) {
+ return templates.remove(o);
+ }
+
+ public Template remove(int index) {
+ return templates.remove(index);
+ }
+
+ public boolean removeAll(Collection<?> c) {
+ return templates.removeAll(c);
+ }
+
+ public boolean retainAll(Collection<?> c) {
+ return templates.retainAll(c);
+ }
+
+ 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);
+ }
+
+ return old;
+ }
+
+ public int size() {
+ return templates.size();
+ }
+
+ public List<Template> subList(int fromIndex, int toIndex) {
+ return templates.subList(fromIndex, toIndex);
+ }
+
+ public Object[] toArray() {
+ return templates.toArray();
+ }
+
+ public <T> T[] toArray(T[] a) {
+ return templates.toArray(a);
+ }
+
+}
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:10:54 UTC (rev 17816)
+++
root/tests/metamer/trunk/src/main/java/org/richfaces/testapp/bean/TemplateBean.java 2010-07-10
18:11:56 UTC (rev 17817)
@@ -25,16 +25,13 @@
import java.util.ArrayList;
import java.util.List;
-import javax.el.ELException;
-import javax.el.ExpressionFactory;
-import javax.el.MethodExpression;
+import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
-import javax.faces.context.FacesContext;
-import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
import org.richfaces.testapp.Template;
+import org.richfaces.testapp.TemplatesList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -55,6 +52,8 @@
public static final String PARAM_NAME = "t";
private Template template = Template.PLAIN;
+
+ private TemplatesList templates;
private Template templatePath = Template.PLAIN;
@@ -62,10 +61,25 @@
private Integer dataTableRowIndex = 0;
+ private int templateIndex = 0;
+
+ @PostConstruct
+ public void init() {
+ templates = new TemplatesList();
+ templates.add(Template.PLAIN);
+ }
+
+ /**
+ * @return the templates
+ */
+ public List<Template> getTemplates() {
+ return templates;
+ }
+
public String getTemplateId() {
return template.toString();
}
-
+
public void setTemplateId(String template) {
this.template = Template.valueOf(template);
// if (this.template.equals(Template.DATA_TABLE)) {
@@ -150,5 +164,29 @@
public List<String> getDataTableModel() {
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();
+ }
+
+ public String getNextTemplate() {
+ return templates.get(++templateIndex).toString().toLowerCase();
+ }
}
\ No newline at end of file
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:10:54 UTC (rev 17816)
+++
root/tests/metamer/trunk/src/main/webapp/components/a4jCommandLink/simple.xhtml 2010-07-10
18:11:56 UTC (rev 17817)
@@ -3,7 +3,7 @@
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:rich="http://java.sun.com/jsf/composite/rich"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:c="http://java.sun.com/jsp/jstl/core">
-<ui:composition template="#{templateBean.template}">
+<ui:composition template="/templates/template.xhtml">
<ui:define name="viewParams">
<f:metadata>
Copied: root/tests/metamer/trunk/src/main/webapp/templates/blue_div.xhtml (from rev 17816,
root/tests/metamer/trunk/src/main/webapp/templates/plain.xhtml)
===================================================================
--- root/tests/metamer/trunk/src/main/webapp/templates/blue_div.xhtml
(rev 0)
+++ root/tests/metamer/trunk/src/main/webapp/templates/blue_div.xhtml 2010-07-10 18:11:56
UTC (rev 17817)
@@ -0,0 +1,12 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:rich="http://java.sun.com/jsf/composite/rich">
+
+<ui:composition>
+
+ <div style="border: 3px blue dotted; padding: 10px; margin-top: 10px;
margin-bottom: 10px;"><ui:include
+ src="#{templateBean.nextTemplate}.xhtml" /></div>
+
+</ui:composition>
+</html>
\ No newline at end of file
Modified: root/tests/metamer/trunk/src/main/webapp/templates/header.xhtml
===================================================================
--- root/tests/metamer/trunk/src/main/webapp/templates/header.xhtml 2010-07-10 18:10:54
UTC (rev 17816)
+++ root/tests/metamer/trunk/src/main/webapp/templates/header.xhtml 2010-07-10 18:11:56
UTC (rev 17817)
@@ -1,10 +1,16 @@
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
-
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://java.sun.com/jsf/composite/rich">
+
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://java.sun.com/jsf/composite/rich"
+
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:form id="headerForm" style="padding-bottom: 30px;"
prependId="false">
<h:panelGrid columns="6" border="1">
+ <h:panelGrid columns="1">
+ <h:commandLink id="goHomeLink"
action="/index?faces-redirect=true" value="Home" />
+ <a4j:commandLink render="commonGrid" value="Rerender
all" id="reRenderAllLink" />
+ </h:panelGrid>
+
<h:panelGrid columns="2" style="width: 180px;">
<h:outputLabel id="a4jLogLabel"
for="a4jLogCheckbox" value="a4j:log" />
<h:selectBooleanCheckbox id="a4jLogCheckbox"
value="#{richBean.log}">
@@ -20,7 +26,8 @@
<h:panelGrid columns="2">
<h:outputLabel id="reTestsCheckboxLabel" value="Display
tests" for="reTestsCheckbox" />
- <h:selectBooleanCheckbox id="reTestsCheckbox"
value="#{richBean.reTests}" onchange="submit();"
disabled="true"/>
+ <h:selectBooleanCheckbox id="reTestsCheckbox"
value="#{richBean.reTests}" onchange="submit();"
+ disabled="true" />
<h:outputLabel id="reComponentCheckboxLabel"
value="Display component" for="reComponentCheckbox" />
<h:selectBooleanCheckbox id="reComponentCheckbox"
value="#{richBean.reComponent}" onchange="submit();" />
@@ -38,20 +45,21 @@
</h:selectOneMenu>
</h:panelGrid>
- <h:panelGrid columns="1">
+ <h:panelGrid id="templatesSelector" columns="1">
+ <h:outputText id="templateSelectMenuLabel"
value="Template:" />
- <h:panelGroup layout="block">
- <h:outputLabel id="templateSelectMenuLabel"
for="templateSelectMenu" value="Template:" />
- <h:selectOneMenu value="#{templateBean.templateId}"
id="templateSelectMenu" style="width: 150px;">
+ <ui:repeat var="var"
value="#{templateBean.templates}" varStatus="status">
+ <h:selectOneMenu
value="#{templateBean.templates[status.index]}" id="templateSelect"
+ style="width: 150px;">
<f:selectItems
value="#{templateBean.availableTemplates}" />
- <a4j:ajax event="change" action="/index"
/>
+ <f:converter converterId="templateNameConverter"
/>
+ <a4j:ajax event="change"
render="headerForm" />
</h:selectOneMenu>
- <h:commandLink id="loadTemplate" value="Load"
render="commonGrid" />
- </h:panelGroup>
-
- <h:commandLink id="goHomeLink"
action="/index?faces-redirect=true" value="Home" />
-
- <a4j:commandLink render="commonGrid" value="Rerender
all" id="reRenderAllLink" />
+ <br />
+ </ui:repeat>
+
+ <h:commandLink id="loadTemplate" value="Load"
render="commonGrid" />
+
</h:panelGrid>
<h:panelGrid columns="1">
Modified: root/tests/metamer/trunk/src/main/webapp/templates/plain.xhtml
===================================================================
--- root/tests/metamer/trunk/src/main/webapp/templates/plain.xhtml 2010-07-10 18:10:54 UTC
(rev 17816)
+++ root/tests/metamer/trunk/src/main/webapp/templates/plain.xhtml 2010-07-10 18:11:56 UTC
(rev 17817)
@@ -3,15 +3,9 @@
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://java.sun.com/jsf/composite/rich">
-<ui:composition template="template.xhtml">
+<ui:composition>
- <ui:define name="template">
- <div style="margin-bottom: 20px;"><ui:insert
name="outOfTemplateBefore" /></div>
-
- <ui:insert name="component" />
-
- <div style="margin-top: 20px;"><ui:insert
name="outOfTemplateAfter" /></div>
- </ui:define>
+ <ui:insert name="component" >content of
plain.xhtml</ui:insert>
</ui:composition>
</html>
\ No newline at end of file
Copied: root/tests/metamer/trunk/src/main/webapp/templates/red_div.xhtml (from rev 17816,
root/tests/metamer/trunk/src/main/webapp/templates/reddiv.xhtml)
===================================================================
--- root/tests/metamer/trunk/src/main/webapp/templates/red_div.xhtml
(rev 0)
+++ root/tests/metamer/trunk/src/main/webapp/templates/red_div.xhtml 2010-07-10 18:11:56
UTC (rev 17817)
@@ -0,0 +1,12 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:rich="http://java.sun.com/jsf/composite/rich">
+
+<ui:composition>
+
+ <div style="border: 3px red solid; padding: 10px; margin-top: 10px;
margin-bottom: 10px;"><ui:include
+ src="#{templateBean.nextTemplate}.xhtml" /></div>
+
+</ui:composition>
+</html>
\ No newline at end of file
Deleted: root/tests/metamer/trunk/src/main/webapp/templates/reddiv.xhtml
===================================================================
--- root/tests/metamer/trunk/src/main/webapp/templates/reddiv.xhtml 2010-07-10 18:10:54
UTC (rev 17816)
+++ root/tests/metamer/trunk/src/main/webapp/templates/reddiv.xhtml 2010-07-10 18:11:56
UTC (rev 17817)
@@ -1,17 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
-
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
-
xmlns:rich="http://java.sun.com/jsf/composite/rich">
-
-<ui:composition template="template.xhtml">
-
- <ui:define name="template">
- <div style="margin-bottom: 20px;"><ui:insert
name="outOfTemplateBefore" /></div>
-
- <div style="border: 3px red solid; padding: 10px; margin-top: 10px;
margin-bottom: 10px;"><ui:insert name="component" /></div>
-
- <div style="margin-top: 20px;"><ui:insert
name="outOfTemplateAfter" /></div>
- </ui:define>
-
-</ui:composition>
-</html>
\ No newline at end of file
Modified: root/tests/metamer/trunk/src/main/webapp/templates/template.xhtml
===================================================================
--- root/tests/metamer/trunk/src/main/webapp/templates/template.xhtml 2010-07-10 18:10:54
UTC (rev 17816)
+++ root/tests/metamer/trunk/src/main/webapp/templates/template.xhtml 2010-07-10 18:11:56
UTC (rev 17817)
@@ -24,7 +24,9 @@
id="statusMessage" /></div>
<br />
<div><h:form id="componentForm">
- <ui:insert name="template" />
+ <div style="margin-bottom: 20px;"><ui:insert
name="outOfTemplateBefore" /></div>
+ <ui:include src="/templates/#{templateBean.firstTemplate}.xhtml"
/>
+ <div style="margin-top: 20px;"><ui:insert
name="outOfTemplateAfter" /></div>
</h:form></div>
</h:panelGroup> <br />