You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2010/06/24 22:28:03 UTC

svn commit: r957706 - in /myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main: java/org/apache/myfaces/tobago/example/demo/bestpractice/ webapp/WEB-INF/ webapp/best-practice/ webapp/tobago-resource/html/standard/standard/property/

Author: lofwyr
Date: Thu Jun 24 20:28:03 2010
New Revision: 957706

URL: http://svn.apache.org/viewvc?rev=957706&view=rev
Log:
Add example to show how facelets can be used dynamically. The demo shows, how you can write a use-customizable toolbar.

Added:
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/bestpractice/ToolBarCustomizer.java
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-customizer.xhtml   (contents, props changed)
      - copied, changed from r957002, myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/validation.xhtml
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-item-delete.xhtml
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-item-edit.xhtml
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-item-new.xhtml
Modified:
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/faces-config.xml
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview.properties.xml

Added: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/bestpractice/ToolBarCustomizer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/bestpractice/ToolBarCustomizer.java?rev=957706&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/bestpractice/ToolBarCustomizer.java (added)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/bestpractice/ToolBarCustomizer.java Thu Jun 24 20:28:03 2010
@@ -0,0 +1,98 @@
+package org.apache.myfaces.tobago.example.demo.bestpractice;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import javax.faces.component.UIParameter;
+import javax.faces.event.ActionEvent;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+
+public class ToolBarCustomizer {
+
+  private List<Item> list;
+
+  public ToolBarCustomizer() {
+    resetList();
+  }
+
+  public String resetList() {
+    list = new ArrayList<Item>(Arrays.asList(
+
+        // TODO: load data from webapp/bestpractice/tool-bar-item*.xhtml
+
+        new Item("New"),
+        new Item("Edit"),
+        new Item("Delete")
+    ));
+
+    return null;
+  }
+
+  public void itemUp(ActionEvent event) {
+    Item item = (Item) ((UIParameter) event.getComponent().getChildren().get(0)).getValue();
+    int oldIndex = list.indexOf(item);
+    if (oldIndex > 0) {
+      list.remove(item);
+      list.add(oldIndex - 1, item);
+    }
+  }
+
+  public void itemDown(ActionEvent event) {
+    Item item = (Item) ((UIParameter) event.getComponent().getChildren().get(0)).getValue();
+    int oldIndex = list.indexOf(item);
+    if (oldIndex < list.size()) {
+      list.remove(item);
+      list.add(oldIndex + 1, item);
+    }
+  }
+
+  public List<Item> getList() {
+    return list;
+  }
+
+  public static class Item {
+
+    private String label;
+    private String name;
+
+    private boolean visible = true;
+
+    private Item(String label) {
+      this.label = label;
+      this.name = "tool-bar-item-" + label.toLowerCase(Locale.ENGLISH) + ".xhtml";
+    }
+
+    public String getLabel() {
+      return label;
+    }
+
+    public String getName() {
+      return name;
+    }
+
+    public boolean isVisible() {
+      return visible;
+    }
+
+    public void setVisible(boolean visible) {
+      this.visible = visible;
+    }
+  }
+}

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/faces-config.xml?rev=957706&r1=957705&r2=957706&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/faces-config.xml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/faces-config.xml Thu Jun 24 20:28:03 2010
@@ -243,6 +243,14 @@
     <managed-bean-scope>session</managed-bean-scope>
   </managed-bean>
 
+<!--
+  <managed-bean>
+    <managed-bean-name>validationSeverity</managed-bean-name>
+    <managed-bean-class>org.apache.myfaces.tobago.example.demo.overview.ValidationSeverity</managed-bean-class>
+    <managed-bean-scope>none</managed-bean-scope>
+  </managed-bean>
+-->
+
   <!--best practice-->
 
   <managed-bean>
@@ -263,6 +271,12 @@
     <managed-bean-scope>request</managed-bean-scope>
   </managed-bean>
 
+  <managed-bean>
+    <managed-bean-name>customizer</managed-bean-name>
+    <managed-bean-class>org.apache.myfaces.tobago.example.demo.bestpractice.ToolBarCustomizer</managed-bean-class>
+    <managed-bean-scope>session</managed-bean-scope>
+  </managed-bean>
+
   <navigation-rule>
     <navigation-case>
       <from-outcome>best-practice/intro</from-outcome>
@@ -288,6 +302,10 @@
       <from-outcome>best-practice/non-faces-response</from-outcome>
       <to-view-id>/best-practice/non-faces-response.jsp</to-view-id>
     </navigation-case>
+    <navigation-case>
+      <from-outcome>best-practice/tool-bar-customizer</from-outcome>
+      <to-view-id>/best-practice/tool-bar-customizer.xhtml</to-view-id>
+    </navigation-case>
   </navigation-rule>
 
   <navigation-rule>

Copied: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-customizer.xhtml (from r957002, myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/validation.xhtml)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-customizer.xhtml?p2=myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-customizer.xhtml&p1=myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/validation.xhtml&r1=957002&r2=957706&rev=957706&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/overview/validation.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-customizer.xhtml Thu Jun 24 20:28:03 2010
@@ -17,53 +17,59 @@
  * limitations under the License.
 -->
 
-<ui:composition template="/WEB-INF/tags/layout/overview.xhtml"
-                xmlns:jsp="http://java.sun.com/JSP/Page"
-                xmlns:tc="http://myfaces.apache.org/tobago/component"
-                xmlns:tx="http://myfaces.apache.org/tobago/extension"
-                xmlns:ui="http://java.sun.com/jsf/facelets"
-                xmlns:h="http://java.sun.com/jsf/html"
-                xmlns:f="http://java.sun.com/jsf/core">
-  <ui:param name="title" value="#{overviewBundle.validation}"/>
-  <tc:panel>
+<ui:composition
+    template="/WEB-INF/tags/layout/overview.xhtml"
+    xmlns:jsp="http://java.sun.com/JSP/Page"
+    xmlns:tc="http://myfaces.apache.org/tobago/component"
+    xmlns:tx="http://myfaces.apache.org/tobago/extension"
+    xmlns:ui="http://java.sun.com/jsf/facelets"
+    xmlns:f="http://java.sun.com/jsf/core"
+    xmlns:c="http://java.sun.com/jstl/core">
+  <tc:box label="Customizable Tool Bar">
     <f:facet name="layout">
-      <tc:gridLayout rows="80px;1*"/>
+      <tc:gridLayout rows="auto;100px;auto;*"/>
     </f:facet>
 
-    <tc:out escape="false" value="#{overviewBundle.validation_text}"/>
+    <tc:toolBar>
+      <c:forEach items="#{customizer.list}" var="item">
+        <c:if test="#{item.visible}">
+          <ui:include src="#{item.name}"/>
+        </c:if>
+      </c:forEach>
+    </tc:toolBar>
+
+    <tc:sheet var="item" value="#{customizer.list}" columns="*;*;*;*">
+      <tc:column label="Item Name">
+        <tc:out value="#{item.label}"/>
+      </tc:column>
+      <tc:column label="Visible">
+        <tc:selectBooleanCheckbox value="#{item.visible}"/>
+      </tc:column>
+      <tc:column>
+        <tc:link actionListener="#{customizer.itemUp}" label="Up">
+          <f:param value="#{item}" name="item"/>
+        </tc:link>
+      </tc:column>
+      <tc:column>
+        <tc:link actionListener="#{customizer.itemDown}" label="Down">
+          <f:param value="#{item}" name="item"/>
+        </tc:link>
+      </tc:column>
+    </tc:sheet>
 
-    <tc:box label="#{overviewBundle.validation_sampleTitle}">
+    <tc:panel>
       <f:facet name="layout">
-        <tc:gridLayout rows="fixed;1*;fixed;fixed"/>
+        <tc:gridLayout columns="*;auto;auto"/>
       </f:facet>
 
-      <tc:panel>
-        <f:facet name="layout">
-          <tc:gridLayout columns="1*;1*"/>
-        </f:facet>
-        <tx:in label="#{overviewBundle.validation_number}" markup="number" required="true">
-          <f:validateLength minimum="7" maximum="7"/>
-          <f:validateLongRange maximum="9000000"/>
-        </tx:in>
-        <tx:in label="#{overviewBundle.validation_price}" markup="number">
-          <f:validateDoubleRange minimum="0.01" maximum="1000"/>
-        </tx:in>
-        <tx:in label="#{overviewBundle.validation_custom}" validator="#{overviewController.customValidator}">
-        </tx:in>
-      </tc:panel>
-
-      <tx:textarea label="#{overviewBundle.validation_description}" required="true"/>
-
-      <tc:messages/>
-
-      <tc:panel>
-        <f:facet name="layout">
-          <tc:gridLayout columns="1*;100px"/>
-        </f:facet>
-        <tc:cell/>
-        <tc:button action="#{overviewController.noop}" label="#{overviewBundle.validation_submit}"/>
-      </tc:panel>
-
-    </tc:box>
-  </tc:panel>
+      <tc:panel/>
+      <tc:button label="Reset List" action="#{customizer.resetList}"/>
+      <tc:button label="Update"/>
+    </tc:panel>
+
+    <tc:out value="The data of the model can also be loaded directly from the webapp directory.
+       So we can define an Item for each facelet matching best-practice/tool-bar-item-*.xhtml.
+       With this, we can create applications with pluggable UI. And we don't have to fight with bindings and
+       creating components in Java code."/>
+  </tc:box>
 </ui:composition>

Propchange: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-customizer.xhtml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-customizer.xhtml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-customizer.xhtml
------------------------------------------------------------------------------
    svn:mergeinfo = 

Added: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-item-delete.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-item-delete.xhtml?rev=957706&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-item-delete.xhtml (added)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-item-delete.xhtml Thu Jun 24 20:28:03 2010
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+
+<tc:toolBarCommand xmlns:tc="http://myfaces.apache.org/tobago/component" label="Delete"/>

Added: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-item-edit.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-item-edit.xhtml?rev=957706&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-item-edit.xhtml (added)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-item-edit.xhtml Thu Jun 24 20:28:03 2010
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+
+<tc:toolBarCommand xmlns:tc="http://myfaces.apache.org/tobago/component" label="Edit"/>

Added: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-item-new.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-item-new.xhtml?rev=957706&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-item-new.xhtml (added)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/best-practice/tool-bar-item-new.xhtml Thu Jun 24 20:28:03 2010
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+
+<tc:toolBarCommand xmlns:tc="http://myfaces.apache.org/tobago/component" label="New"/>

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview.properties.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview.properties.xml?rev=957706&r1=957705&r2=957706&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview.properties.xml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview.properties.xml Thu Jun 24 20:28:03 2010
@@ -56,6 +56,7 @@
   <entry key="theme">Themes</entry>
   <entry key="transition">Transition</entry>
   <entry key="nonFacesResponse">Non Faces Resp.</entry>
+  <entry key="toolBarCustomizer">Customize</entry>
 
   <entry key="reference_intro">Ref. (under constr.)</entry>
   <entry key="reference_command">Command</entry>