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/22 10:16:58 UTC

svn commit: r956811 - in /myfaces/tobago/branches/tobago-1.0.x/example: data/src/main/java/org/apache/myfaces/tobago/example/data/ demo/ demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/ demo/src/main/webapp/overview/ demo/src/main/we...

Author: lofwyr
Date: Tue Jun 22 08:16:57 2010
New Revision: 956811

URL: http://svn.apache.org/viewvc?rev=956811&view=rev
Log:
example applications: optimize ajax example

Modified:
    myfaces/tobago/branches/tobago-1.0.x/example/data/src/main/java/org/apache/myfaces/tobago/example/data/LocaleList.java
    myfaces/tobago/branches/tobago-1.0.x/example/demo/pom.xml
    myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
    myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/webapp/overview/basic.jsp
    myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview.properties.xml
    myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview_de.properties.xml
    myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/java/org/apache/myfaces/tobago/example/test/SheetController.java

Modified: myfaces/tobago/branches/tobago-1.0.x/example/data/src/main/java/org/apache/myfaces/tobago/example/data/LocaleList.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/example/data/src/main/java/org/apache/myfaces/tobago/example/data/LocaleList.java?rev=956811&r1=956810&r2=956811&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/example/data/src/main/java/org/apache/myfaces/tobago/example/data/LocaleList.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/example/data/src/main/java/org/apache/myfaces/tobago/example/data/LocaleList.java Tue Jun 22 08:16:57 2010
@@ -17,16 +17,46 @@ package org.apache.myfaces.tobago.exampl
  * limitations under the License.
  */
 
+import org.apache.commons.lang.StringUtils;
+
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
 import java.util.Locale;
+import java.util.Set;
+
+public class LocaleList {
+
+  public static final List<LocaleEntry> DATA;
 
-public class LocaleList extends ArrayList<LocaleEntry> {
+  public static final List<String> COUNTRY_LANGUAGE;
 
-  {
+  static {
+    List<LocaleEntry> init = new ArrayList<LocaleEntry>();
     for (Locale displayLocale : Locale.getAvailableLocales()) {
       for (Locale locale : Locale.getAvailableLocales()) {
-        add(new LocaleEntry(locale, displayLocale));
+        init.add(new LocaleEntry(locale, displayLocale));
       }
     }
+    DATA = Collections.unmodifiableList(init);
+  }
+
+  static {
+    Set<String> init = new HashSet<String>();
+    for (LocaleEntry localeEntry : DATA) {
+      if (StringUtils.isNotBlank(localeEntry.getCountry())
+          && StringUtils.isNotBlank(localeEntry.getLanguage())) {
+        final String name = localeEntry.getCountry() + " (" + localeEntry.getLanguage() + ")";
+        init.add(name);
+      }
+    }
+    final ArrayList<String> list = new ArrayList<String>(init);
+    Collections.sort(list);
+    COUNTRY_LANGUAGE = Collections.unmodifiableList(list);
+  }
+
+  private LocaleList() {
+    // do not call
   }
 }

Modified: myfaces/tobago/branches/tobago-1.0.x/example/demo/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/example/demo/pom.xml?rev=956811&r1=956810&r2=956811&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/example/demo/pom.xml (original)
+++ myfaces/tobago/branches/tobago-1.0.x/example/demo/pom.xml Tue Jun 22 08:16:57 2010
@@ -70,6 +70,11 @@
   </scm>
 
   <dependencies>
+    <dependency>
+      <groupId>org.apache.myfaces.tobago</groupId>
+      <artifactId>tobago-example-data</artifactId>
+      <version>${project.version}</version>
+    </dependency>
     <!--dependency>
       <groupId>org.apache.myfaces.tobago</groupId>
       <artifactId>tobago-theme-example</artifactId>
@@ -324,4 +329,4 @@
       </build>
     </profile>
   </profiles>
-</project>
\ No newline at end of file
+</project>

Modified: myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java?rev=956811&r1=956810&r2=956811&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/overview/OverviewController.java Tue Jun 22 08:16:57 2010
@@ -24,6 +24,7 @@ import org.apache.myfaces.tobago.context
 import org.apache.myfaces.tobago.context.ResourceManagerFactory;
 import org.apache.myfaces.tobago.event.SortActionEvent;
 import org.apache.myfaces.tobago.event.TabChangeEvent;
+import org.apache.myfaces.tobago.example.data.LocaleList;
 import org.apache.myfaces.tobago.example.demo.model.Salutation;
 import org.apache.myfaces.tobago.example.demo.model.solar.SolarObject;
 import org.apache.myfaces.tobago.model.SheetState;
@@ -72,6 +73,8 @@ public class OverviewController {
 
   private String basicInput = "";
 
+  private String suggestInput;
+
   private String basicArea = "";
 
   private Date basicDate = new Date();
@@ -351,6 +354,14 @@ public class OverviewController {
     this.basicInput = basicInput;
   }
 
+  public String getSuggestInput() {
+    return suggestInput;
+  }
+
+  public void setSuggestInput(String suggestInput) {
+    this.suggestInput = suggestInput;
+  }
+
   public String getBasicArea() {
     return basicArea;
   }
@@ -413,10 +424,16 @@ public class OverviewController {
 
   public List<String> getInputSuggestItems(String prefix) {
     LOG.info("Creating items for prefix: '" + prefix + "'");
-    List<String> li = new ArrayList<String>();
-    for (int i = 1; i <= 6; i++) {
-      li.add(prefix + i);
+    prefix = prefix.toLowerCase();
+    List<String> result = new ArrayList<String>();
+    for (String name : LocaleList.COUNTRY_LANGUAGE) {
+      if (name.toLowerCase().startsWith(prefix)) {
+        result.add(name);
+      }
+      if (result.size() > 100) { // this value should be greater than the value of the input control
+        break;
+      }
     }
-    return li;
+    return result;
   }
 }

Modified: myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/webapp/overview/basic.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/webapp/overview/basic.jsp?rev=956811&r1=956810&r2=956811&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/webapp/overview/basic.jsp (original)
+++ myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/webapp/overview/basic.jsp Tue Jun 22 08:16:57 2010
@@ -52,17 +52,19 @@
 
         <tc:panel>
           <f:facet name="layout">
-            <tc:gridLayout rows="fixed;fixed;fixed" />
+            <tc:gridLayout rows="fixed;fixed;fixed;fixed" />
           </f:facet>
           <tx:in value="#{overviewController.basicInput}" required="true" tabIndex="1"
-              label="#{overviewBundle.basic_textboxLabel}" tip="test"
-              suggestMethod="#{overviewController.getInputSuggestItems}" />
-          <tx:date value="#{overviewController.basicDate}" tabIndex="3"
-              label="#{overviewBundle.basic_dateLabel}" required="true" >
+                 label="#{overviewBundle.basic_textboxLabel}" tip="#{overviewBundle.basic_textboxTip}"/>
+          <tx:in value="#{overviewController.suggestInput}" tabIndex="3"
+                 label="#{overviewBundle.basic_suggestLabel}" tip="#{overviewBundle.basic_suggestTip}"
+                 suggestMethod="#{overviewController.getInputSuggestItems}"/>
+          <tx:date value="#{overviewController.basicDate}" tabIndex="4"
+                   label="#{overviewBundle.basic_dateLabel}" required="true" >
             <f:convertDateTime pattern="dd/MM/yyyy" />
             <tc:validateSubmittedValueLength maximum="10"/>
           </tx:date>
-          <tx:time label="#{overviewBundle.basic_timeLabel}" tabIndex="4"
+          <tx:time label="#{overviewBundle.basic_timeLabel}" tabIndex="5"
               value="#{overviewController.basicTime}" />
         </tc:panel>
 

Modified: myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview.properties.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview.properties.xml?rev=956811&r1=956810&r2=956811&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview.properties.xml (original)
+++ myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview.properties.xml Tue Jun 22 08:16:57 2010
@@ -109,6 +109,9 @@
   <entry key="basic_itemMr">Mr.</entry>
   <entry key="basic_itemMrs">Mrs.</entry>
   <entry key="basic_textboxLabel">Inputfield</entry>
+  <entry key="basic_textboxTip">A simple input field</entry>
+  <entry key="basic_suggestLabel">Suggest (AJAX)</entry>
+  <entry key="basic_suggestTip">Please type in "po" for example</entry>
   <entry key="basic_dateLabel">Date</entry>
   <entry key="basic_timeLabel">Time</entry>
   <entry key="basic_textareaLabel">Textarea</entry>

Modified: myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview_de.properties.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview_de.properties.xml?rev=956811&r1=956810&r2=956811&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview_de.properties.xml (original)
+++ myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/webapp/tobago-resource/html/standard/standard/property/overview_de.properties.xml Tue Jun 22 08:16:57 2010
@@ -84,6 +84,9 @@
   <entry key="basic_itemMr">Herr</entry>
   <entry key="basic_itemMrs">Frau</entry>
   <entry key="basic_textboxLabel">Eingabefeld</entry>
+  <entry key="basic_textboxTip">A simple input field</entry>
+  <entry key="basic_suggestLabel">Suggest (AJAX)</entry>
+  <entry key="basic_suggestTip">Please type in "po" for example</entry>
   <entry key="basic_dateLabel">Datum</entry>
   <entry key="basic_timeLabel">Uhrzeit</entry>
   <entry key="basic_textareaLabel">Textfeld</entry>

Modified: myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/java/org/apache/myfaces/tobago/example/test/SheetController.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/java/org/apache/myfaces/tobago/example/test/SheetController.java?rev=956811&r1=956810&r2=956811&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/java/org/apache/myfaces/tobago/example/test/SheetController.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/example/test/src/main/java/org/apache/myfaces/tobago/example/test/SheetController.java Tue Jun 22 08:16:57 2010
@@ -17,20 +17,25 @@ package org.apache.myfaces.tobago.exampl
  * limitations under the License.
  */
 
+import org.apache.myfaces.tobago.example.data.LocaleEntry;
 import org.apache.myfaces.tobago.example.data.LocaleList;
 import org.apache.myfaces.tobago.example.data.SolarObject;
 
+import java.util.ArrayList;
+import java.util.List;
+
 public class SheetController {
   
   private SolarObject[] solarArray = SolarObject.getArray();
 
-  private LocaleList localeList = new LocaleList();
+  // Create a copy for sorting, because the LocaleList.DATA is not modifiable.
+  private List<LocaleEntry> localeList = new ArrayList<LocaleEntry>(LocaleList.DATA);
 
   public SolarObject[] getSolarArray() {
     return solarArray;
   }
 
-  public LocaleList getLocaleList() {
+  public List<LocaleEntry> getLocaleList() {
     return localeList;
   }
 }