You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sc...@apache.org on 2005/07/01 04:25:40 UTC
svn commit: r208703 - in /myfaces/examples/trunk/sandbox: ./ WEB-INF/
src/java/org/ src/java/org/apache/ src/java/org/apache/myfaces/
src/java/org/apache/myfaces/examples/
src/java/org/apache/myfaces/examples/inputsuggest/
Author: schof
Date: Thu Jun 30 19:25:38 2005
New Revision: 208703
URL: http://svn.apache.org/viewcvs?rev=208703&view=rev
Log:
supporting files for myfaces sandbox examples
Added:
myfaces/examples/trunk/sandbox/src/java/org/
myfaces/examples/trunk/sandbox/src/java/org/apache/
myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/
myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/
myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputsuggest/
myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputsuggest/StateInfo.java
myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputsuggest/User.java
myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputsuggest/UserHandler.java
Modified:
myfaces/examples/trunk/sandbox/WEB-INF/examples-config.xml
myfaces/examples/trunk/sandbox/inputSuggest.jsp
Modified: myfaces/examples/trunk/sandbox/WEB-INF/examples-config.xml
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/sandbox/WEB-INF/examples-config.xml?rev=208703&r1=208702&r2=208703&view=diff
==============================================================================
--- myfaces/examples/trunk/sandbox/WEB-INF/examples-config.xml (original)
+++ myfaces/examples/trunk/sandbox/WEB-INF/examples-config.xml Thu Jun 30 19:25:38 2005
@@ -16,4 +16,226 @@
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
-</faces-config>
\ No newline at end of file
+ <managed-bean>
+ <managed-bean-name>userHandler</managed-bean-name>
+ <managed-bean-class>org.apache.myfaces.examples.inputsuggest.UserHandler</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+ <managed-property>
+ <property-name>user</property-name>
+ <value>#{user}</value>
+ </managed-property>
+ <managed-property>
+ <property-name>choices</property-name>
+ <value>#{choices}</value>
+ </managed-property>
+ </managed-bean>
+
+ <managed-bean>
+ <managed-bean-name>choices</managed-bean-name>
+ <managed-bean-class>java.util.TreeMap</managed-bean-class>
+ <managed-bean-scope>application</managed-bean-scope>
+ <map-entries>
+ <map-entry>
+ <key>1</key>
+ <value>Alabama</value>
+ </map-entry>
+ <map-entry>
+ <key>2</key>
+ <value>Alaska</value>
+ </map-entry>
+ <map-entry>
+ <key>3</key>
+ <value>Arizona</value>
+ </map-entry>
+ <map-entry>
+ <key>4</key>
+ <value>Arkansas</value>
+ </map-entry>
+ <map-entry>
+ <key>5</key>
+ <value>California</value>
+ </map-entry>
+ <map-entry>
+ <key>6</key>
+ <value>Colorado</value>
+ </map-entry>
+ <map-entry>
+ <key>7</key>
+ <value>Connecticut</value>
+ </map-entry>
+ <map-entry>
+ <key>8</key>
+ <value>Delaware</value>
+ </map-entry>
+ <map-entry>
+ <key>9</key>
+ <value>Florida</value>
+ </map-entry>
+ <map-entry>
+ <key>10</key>
+ <value>Georgia</value>
+ </map-entry>
+ <map-entry>
+ <key>11</key>
+ <value>Hawaii</value>
+ </map-entry>
+ <map-entry>
+ <key>12</key>
+ <value>Idaho</value>
+ </map-entry>
+ <map-entry>
+ <key>13</key>
+ <value>Illinois</value>
+ </map-entry>
+ <map-entry>
+ <key>14</key>
+ <value>Indiana</value>
+ </map-entry>
+ <map-entry>
+ <key>15</key>
+ <value>Iowa</value>
+ </map-entry>
+ <map-entry>
+ <key>16</key>
+ <value>Kansas</value>
+ </map-entry>
+ <map-entry>
+ <key>17</key>
+ <value>Kentucky</value>
+ </map-entry>
+ <map-entry>
+ <key>18</key>
+ <value>Louisiana</value>
+ </map-entry>
+ <map-entry>
+ <key>19</key>
+ <value>Maine</value>
+ </map-entry>
+ <map-entry>
+ <key>20</key>
+ <value>Maryland</value>
+ </map-entry>
+ <map-entry>
+ <key>21</key>
+ <value>Massachusetts</value>
+ </map-entry>
+ <map-entry>
+ <key>22</key>
+ <value>Michigan</value>
+ </map-entry>
+ <map-entry>
+ <key>23</key>
+ <value>Minnesota</value>
+ </map-entry>
+ <map-entry>
+ <key>24</key>
+ <value>Mississippi</value>
+ </map-entry>
+ <map-entry>
+ <key>25</key>
+ <value>Missouri</value>
+ </map-entry>
+ <map-entry>
+ <key>26</key>
+ <value>Montana</value>
+ </map-entry>
+ <map-entry>
+ <key>27</key>
+ <value>Nebraska</value>
+ </map-entry>
+ <map-entry>
+ <key>28</key>
+ <value>Nevada</value>
+ </map-entry>
+ <map-entry>
+ <key>29</key>
+ <value>New Hampshire</value>
+ </map-entry>
+ <map-entry>
+ <key>30</key>
+ <value>New Jersey</value>
+ </map-entry>
+ <map-entry>
+ <key>31</key>
+ <value>New Mexico</value>
+ </map-entry>
+ <map-entry>
+ <key>32</key>
+ <value>New York</value>
+ </map-entry>
+ <map-entry>
+ <key>33</key>
+ <value>North Carolina</value>
+ </map-entry>
+ <map-entry>
+ <key>34</key>
+ <value>North Dakota</value>
+ </map-entry>
+ <map-entry>
+ <key>35</key>
+ <value>Ohio</value>
+ </map-entry>
+ <map-entry>
+ <key>36</key>
+ <value>Oklahoma</value>
+ </map-entry>
+ <map-entry>
+ <key>37</key>
+ <value>Oregon</value>
+ </map-entry>
+ <map-entry>
+ <key>38</key>
+ <value>Pennsylvania</value>
+ </map-entry>
+ <map-entry>
+ <key>39</key>
+ <value>Rhode Island</value>
+ </map-entry>
+ <map-entry>
+ <key>40</key>
+ <value>South Carolina</value>
+ </map-entry>
+ <map-entry>
+ <key>41</key>
+ <value>South Dakota</value>
+ </map-entry>
+ <map-entry>
+ <key>42</key>
+ <value>Tennessee</value>
+ </map-entry>
+ <map-entry>
+ <key>43</key>
+ <value>Texas</value>
+ </map-entry>
+ <map-entry>
+ <key>44</key>
+ <value>Utah</value>
+ </map-entry>
+ <map-entry>
+ <key>45</key>
+ <value>Vermont</value>
+ </map-entry>
+ <map-entry>
+ <key>46</key>
+ <value>Virginia</value>
+ </map-entry>
+ <map-entry>
+ <key>47</key>
+ <value>Washington</value>
+ </map-entry>
+ <map-entry>
+ <key>48</key>
+ <value>West Virginia</value>
+ </map-entry>
+ <map-entry>
+ <key>49</key>
+ <value>Wisconsin</value>
+ </map-entry>
+ <map-entry>
+ <key>50</key>
+ <value>Wyoming</value>
+ </map-entry>
+ </map-entries>
+ </managed-bean>
+
+</faces-config>
Modified: myfaces/examples/trunk/sandbox/inputSuggest.jsp
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/sandbox/inputSuggest.jsp?rev=208703&r1=208702&r2=208703&view=diff
==============================================================================
--- myfaces/examples/trunk/sandbox/inputSuggest.jsp (original)
+++ myfaces/examples/trunk/sandbox/inputSuggest.jsp Thu Jun 30 19:25:38 2005
@@ -20,24 +20,24 @@
*/
//-->
<html>
-
+
<%@include file="inc/head.inc" %>
-
+
<body>
<f:view>
<h:form>
<br/>
<x:inputSuggest value="#{user.state.key}" required="true">
- <f:selectItems value="#{choices}"/>
+ <f:selectItems id="foo" value="#{choices}"/>
</x:inputSuggest>
-
+
<h:messages/>
<h:commandButton value="Update"
action="#{userHandler.update}" />
</h:form>
</f:view>
</body>
-
+
<%@include file="inc/page_footer.jsp" %>
-
-</html>
\ No newline at end of file
+
+</html>
Added: myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputsuggest/StateInfo.java
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputsuggest/StateInfo.java?rev=208703&view=auto
==============================================================================
--- myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputsuggest/StateInfo.java (added)
+++ myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputsuggest/StateInfo.java Thu Jun 30 19:25:38 2005
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+package org.apache.myfaces.examples.inputsuggest;
+
+/**
+ * This class is basically designed to simulate an application-specific bean that might exist in some
+ * application. The point here is to demonstrate how an application-specific bean such as this can
+ * be integrated into inputSuggest. The JSP page and the inputSuggest component know nothing about
+ * StateInfo or {@link User}. The {@link UserHandler} backing bean and the value binding expression in
+ * the JSP help bridge this gap.
+ *
+ * @author Sean Schofield
+ * @version $Revision: $ $Date: $
+ */
+public class StateInfo {
+ private String key;
+ private String text;
+
+ public StateInfo(String key, String text) {
+ this.key = key;
+ this.text = text;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text)
+ {
+ this.text = text;
+ }
+}
Added: myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputsuggest/User.java
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputsuggest/User.java?rev=208703&view=auto
==============================================================================
--- myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputsuggest/User.java (added)
+++ myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputsuggest/User.java Thu Jun 30 19:25:38 2005
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+package org.apache.myfaces.examples.inputsuggest;
+
+/**
+ * This class is basically designed to simulate an application-specific bean that might exist in some
+ * application. The point here is to demonstrate how an application-specific bean such as this can
+ * be integrated into inputSuggest. The JSP page and the inputSuggest component know nothing about
+ * {@link StateInfo} or User. The {@link UserHandler} backing bean and the value binding expression in
+ * the JSP help bridge this gap.
+ *
+ * @author Sean Schofield
+ * @version $Revision: $ $Date: $
+ */
+public class User {
+
+ private StateInfo state = new StateInfo("", "");
+
+ public StateInfo getState() {
+ return state;
+ }
+
+ public void setState(StateInfo state) {
+ this.state = state;
+ }
+}
Added: myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputsuggest/UserHandler.java
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputsuggest/UserHandler.java?rev=208703&view=auto
==============================================================================
--- myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputsuggest/UserHandler.java (added)
+++ myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputsuggest/UserHandler.java Thu Jun 30 19:25:38 2005
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+package org.apache.myfaces.examples.inputsuggest;
+
+import java.util.Map;
+
+/**
+ * Backing bean designed to handle changes to an inputSuggest field and map it to the
+ * {@link StateInfo} associated with a {@link User.}
+ *
+ * @author Sean Schofield
+ * @version $Revision: $ $Date: $
+ */
+public class UserHandler
+{
+ private User user;
+ private Map choices;
+
+ public void setUser(User user) {
+ this.user = user;
+ }
+
+ public void setChoices(Map choices) {
+ this.choices = choices;
+ }
+
+ /**
+ * Updates the "datastore" with the user's choice. This method simluates the process of adding a new
+ * choice to the database and setting the user's state info key to the id that the database would
+ * produce.
+ *
+ * @return String
+ */
+ public String update() {
+
+ String newKey = null;
+ String currentKey = (String) user.getState().getKey();
+ String currentText = (String) user.getState().getText();
+ if (!choices.containsKey(currentKey)) {
+
+ // database code goes here
+
+ // fake key (actual key would probably come from a database function that adds the new value)
+ newKey = String.valueOf(choices.size() + 1);
+
+ // Replace the old choice value
+ user.setState(new StateInfo(newKey, currentText));
+ }
+
+ return "success";
+ }
+}