myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmarinsc...@apache.org
Subject svn commit: r433909 - in /myfaces/tomahawk/trunk/examples/simple/src/main: java/org/apache/myfaces/examples/common/ java/org/apache/myfaces/examples/util/ resources/org/apache/myfaces/examples/resource/ webapp/
Date Wed, 23 Aug 2006 05:23:55 GMT
Author: mmarinschek
Date: Tue Aug 22 22:23:54 2006
New Revision: 433909

URL: http://svn.apache.org/viewvc?rev=433909&view=rev
Log:
Added an example to selectbox.jsp, where the value of a selectItem and the value of the corresponding
UISelectOne / UISelectMany is referencing a java data-type

Modified:
    myfaces/tomahawk/trunk/examples/simple/src/main/java/org/apache/myfaces/examples/common/CarConfigurator.java
    myfaces/tomahawk/trunk/examples/simple/src/main/java/org/apache/myfaces/examples/util/LocalizedSelectItem.java
    myfaces/tomahawk/trunk/examples/simple/src/main/resources/org/apache/myfaces/examples/resource/example_messages.properties
    myfaces/tomahawk/trunk/examples/simple/src/main/webapp/options.jsp
    myfaces/tomahawk/trunk/examples/simple/src/main/webapp/selectbox.jsp
    myfaces/tomahawk/trunk/examples/simple/src/main/webapp/sortAutoTable.jsp
    myfaces/tomahawk/trunk/examples/simple/src/main/webapp/validate.jsp

Modified: myfaces/tomahawk/trunk/examples/simple/src/main/java/org/apache/myfaces/examples/common/CarConfigurator.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/examples/simple/src/main/java/org/apache/myfaces/examples/common/CarConfigurator.java?rev=433909&r1=433908&r2=433909&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/examples/simple/src/main/java/org/apache/myfaces/examples/common/CarConfigurator.java
(original)
+++ myfaces/tomahawk/trunk/examples/simple/src/main/java/org/apache/myfaces/examples/common/CarConfigurator.java
Tue Aug 22 22:23:54 2006
@@ -22,6 +22,9 @@
 import javax.faces.context.FacesContext;
 import javax.faces.model.SelectItem;
 import javax.faces.validator.ValidatorException;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+import javax.servlet.http.HttpServletResponse;
 import java.io.Serializable;
 import java.math.BigDecimal;
 import java.util.ArrayList;
@@ -60,10 +63,10 @@
         _cars.add(new SelectItem("c6", "James Blond Car", null));
         _cars.add(new SelectItem("c7", "Neko Bus", null));
 
-        _colors.add(new LocalizedSelectItem("color_black"));
-        _colors.add(new LocalizedSelectItem("color_blue"));
-        _colors.add(new LocalizedSelectItem("color_marine"));
-        _colors.add(new LocalizedSelectItem("color_red"));
+        _colors.add(new LocalizedSelectItem(new Color("color_black"),"color_black"));
+        _colors.add(new LocalizedSelectItem(new Color("color_blue"),"color_blue"));
+        _colors.add(new LocalizedSelectItem(new Color("color_marine"),"color_marine"));
+        _colors.add(new LocalizedSelectItem(new Color("color_red"),"color_red"));
 
         _extrasList.add(new LocalizedSelectItem("extra_aircond"));
         _extrasList.add(new LocalizedSelectItem("extra_sideab"));
@@ -96,7 +99,8 @@
     private String _discount2 = "0";
     private String _bandName;
     private String _car;
-    private String _color = "color_blue";
+    private Color _color = new Color("color_blue");
+    private List _interiorColors = null;
     private boolean _salesTax = false;
     private int _doors = 4;
 
@@ -142,16 +146,26 @@
         _car = car;
     }
 
-    public String getColor()
+    public Color getColor()
     {
         return _color;
     }
 
-    public void setColor(String color)
+    public void setColor(Color color)
     {
         _color = color;
     }
 
+    public List getInteriorColors()
+    {
+        return _interiorColors;
+    }
+
+    public void setInteriorColors(List interiorColors)
+    {
+        _interiorColors = interiorColors;
+    }
+
     public BigDecimal getPrice()
     {
         return _price;
@@ -215,7 +229,7 @@
     public String calcPrice()
     {
         String car = getCar();
-        String color = getColor();
+        Color color = getColor();
         if (car == null ||
             color == null)
         {
@@ -224,7 +238,7 @@
         }
 
         BigDecimal carprice = (BigDecimal)_priceList.get(car);
-        BigDecimal colorfactor = (BigDecimal)_priceFactorColors.get(color);
+        BigDecimal colorfactor = (BigDecimal)_priceFactorColors.get(color.getColor());
         if (carprice == null ||
             colorfactor == null)
         {
@@ -294,5 +308,64 @@
         }
     }
 
+    public Converter getColorConverter()
+    {
+        return new ColorConverter();
+    }
+
+    public static class ColorConverter implements Converter
+    {
+
+        public Object getAsObject(FacesContext facesContext, UIComponent component, String
string) throws ConverterException
+        {
+            if(string==null)
+                return null;
+
+            return new Color(string);
+        }
+
+        public String getAsString(FacesContext facesContext, UIComponent component, Object
object) throws ConverterException
+        {
+            if(object instanceof Color)
+            {
+                return ((Color) object).getColor();
+            }
+
+            return null;
+        }
+    }
+
+    public static class Color implements Serializable
+    {
+        private String color;
+
+        public Color(String color)
+        {
+            this.color = color;
+        }
+
+        public String getColor()
+        {
+            return color;
+        }
+
+        public void setColor(String color)
+        {
+            this.color = color;
+        }
+
+        public boolean equals(Object cmp)
+        {
+            if(!(cmp instanceof Color))
+                return false;
+
+            String cmpColor = ((Color) cmp).getColor();
+
+            if(this.color == null && cmpColor!=null)
+                return false;
+
+            return this.color.equals(cmpColor);
+        }
+    }
 
 }

Modified: myfaces/tomahawk/trunk/examples/simple/src/main/java/org/apache/myfaces/examples/util/LocalizedSelectItem.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/examples/simple/src/main/java/org/apache/myfaces/examples/util/LocalizedSelectItem.java?rev=433909&r1=433908&r2=433909&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/examples/simple/src/main/java/org/apache/myfaces/examples/util/LocalizedSelectItem.java
(original)
+++ myfaces/tomahawk/trunk/examples/simple/src/main/java/org/apache/myfaces/examples/util/LocalizedSelectItem.java
Tue Aug 22 22:23:54 2006
@@ -35,4 +35,12 @@
         String label = GuiUtil.getMessageResource(key, null);
         setLabel(label);
     }
+
+    public LocalizedSelectItem(Object value, String key)
+    {
+        super(value);
+
+        String label = GuiUtil.getMessageResource(key, null);
+        setLabel(label);
+    }
 }

Modified: myfaces/tomahawk/trunk/examples/simple/src/main/resources/org/apache/myfaces/examples/resource/example_messages.properties
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/examples/simple/src/main/resources/org/apache/myfaces/examples/resource/example_messages.properties?rev=433909&r1=433908&r2=433909&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/examples/simple/src/main/resources/org/apache/myfaces/examples/resource/example_messages.properties
(original)
+++ myfaces/tomahawk/trunk/examples/simple/src/main/resources/org/apache/myfaces/examples/resource/example_messages.properties
Tue Aug 22 22:23:54 2006
@@ -94,6 +94,7 @@
 color_blue = blue
 color_marine = marine blue
 color_red = red
+label_interior_color = Interior Color
 extra_aircond = Aircondition
 extra_sideab = Sideairbag
 extra_mirrowheat = Heated Mirrors

Modified: myfaces/tomahawk/trunk/examples/simple/src/main/webapp/options.jsp
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/examples/simple/src/main/webapp/options.jsp?rev=433909&r1=433908&r2=433909&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/examples/simple/src/main/webapp/options.jsp (original)
+++ myfaces/tomahawk/trunk/examples/simple/src/main/webapp/options.jsp Tue Aug 22 22:23:54
2006
@@ -1,10 +1,10 @@
 <%@ page session="false" contentType="text/html;charset=utf-8" %>
-<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
-<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
-<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
+<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
+<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
+<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>
 <html>
 
-<%@include file="inc/head.inc" %>
+<%@ include file="inc/head.inc" %>
 
 <!--
 /*
@@ -34,64 +34,65 @@
 
 <f:view>
 
-    <t:saveState id="ss1" value="#{optionsForm.language}" />
+    <t:saveState id="ss1" value="#{optionsForm.language}"/>
 
     <f:loadBundle basename="org.apache.myfaces.examples.resource.example_messages" var="example_messages"/>
 
     <t:panelLayout id="page" layout="#{globalOptions.pageLayout}"
-            styleClass="pageLayout"
-            headerClass="pageHeader"
-            navigationClass="pageNavigation"
-            bodyClass="pageBody"
-            footerClass="pageFooter" >
+                   styleClass="pageLayout"
+                   headerClass="pageHeader"
+                   navigationClass="pageNavigation"
+                   bodyClass="pageBody"
+                   footerClass="pageFooter">
 
         <f:facet name="header">
             <f:subview id="header">
-                <jsp:include page="inc/page_header.jsp" />
+                <jsp:include page="inc/page_header.jsp"/>
             </f:subview>
         </f:facet>
 
         <f:facet name="navigation">
-            <f:subview id="menu" >
-                <jsp:include page="inc/navigation.jsp" />
+            <f:subview id="menu">
+                <jsp:include page="inc/navigation.jsp"/>
             </f:subview>
         </f:facet>
 
 
         <f:facet name="body">
             <h:panelGroup id="body">
-                <h:messages id="messageList" />
+                <h:messages id="messageList"/>
 
-<f:verbatim>
-                <h4>Options</h4>
-                <table border="1"><tr><td>
-</f:verbatim>
-                    <h:form id="form1">
-                        <h:outputText value="#{example_messages['option_lang']}" />
-<f:verbatim>:&nbsp;</f:verbatim>
-                        <h:selectOneMenu id="locale" value="#{optionsForm.language}">
-                            <f:selectItems id="available" value="#{optionsForm.availableLanguages}"
/>
-                        </h:selectOneMenu>
-<f:verbatim><br></f:verbatim>
-                        <h:outputText value="#{example_messages['option_layout']}" />
-<f:verbatim>:&nbsp;</f:verbatim>
-                        <h:selectOneMenu id="layout" value="#{globalOptions.pageLayout}"
 >
-                            <f:selectItem id="item101" itemLabel="Classic" itemValue="classic"
/>
-                            <f:selectItem id="item102" itemLabel="Navigation right" itemValue="navigationRight"
/>
-                            <f:selectItem id="item103" itemLabel="Upside down" itemValue="upsideDown"
/>
-                        </h:selectOneMenu>
-<f:verbatim><br></f:verbatim>
-                        <h:commandButton id="apply" value="#{example_messages['button_apply']}"
action="#{optionsCtrl.changeLocale}"/>
-                    </h:form>
-
-<f:verbatim>
-                </td></tr></table>
-</f:verbatim>
+                <f:verbatim>
+                    <h4>Options</h4>
+                    <table border="1"><tr><td>
+                </f:verbatim>
+                <h:form id="form1">
+                    <h:outputText value="#{example_messages['option_lang']}"/>
+                    <f:verbatim>:&nbsp;</f:verbatim>
+                    <h:selectOneMenu id="locale" value="#{optionsForm.language}">
+                        <f:selectItems id="available" value="#{optionsForm.availableLanguages}"/>
+                    </h:selectOneMenu>
+                    <f:verbatim><br></f:verbatim>
+                    <h:outputText value="#{example_messages['option_layout']}"/>
+                    <f:verbatim>:&nbsp;</f:verbatim>
+                    <h:selectOneMenu id="layout" value="#{globalOptions.pageLayout}">
+                        <f:selectItem id="item101" itemLabel="Classic" itemValue="classic"/>
+                        <f:selectItem id="item102" itemLabel="Navigation right" itemValue="navigationRight"/>
+                        <f:selectItem id="item103" itemLabel="Upside down" itemValue="upsideDown"/>
+                    </h:selectOneMenu>
+                    <f:verbatim><br></f:verbatim>
+                    <h:commandButton id="apply" value="#{example_messages['button_apply']}"
+                                     action="#{optionsCtrl.changeLocale}"/>
+                </h:form>
+
+                <f:verbatim>
+                    </td></tr></table>
+                </f:verbatim>
 
             </h:panelGroup>
         </f:facet>
 
-        <%@include file="inc/page_footer.jsp" %>
+        <%@ include file="inc/page_footer.jsp" %>
 
     </t:panelLayout>
 

Modified: myfaces/tomahawk/trunk/examples/simple/src/main/webapp/selectbox.jsp
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/examples/simple/src/main/webapp/selectbox.jsp?rev=433909&r1=433908&r2=433909&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/examples/simple/src/main/webapp/selectbox.jsp (original)
+++ myfaces/tomahawk/trunk/examples/simple/src/main/webapp/selectbox.jsp Tue Aug 22 22:23:54
2006
@@ -47,11 +47,18 @@
             </h:selectOneListbox>
 
             <h:outputLabel for="selone_menu_colors" value="#{example_messages['label_colors']}"
/>
-            <h:selectOneMenu id="selone_menu_colors" value="#{carconf.color}" styleClass="selectOneMenu"
required="true" >
+            <h:selectOneMenu id="selone_menu_colors" value="#{carconf.color}"
+                             styleClass="selectOneMenu" required="true" converter="#{carconf.colorConverter}">
                 <f:selectItem itemValue="" itemLabel="#{example_messages['empty_selitem']}"
/>
                 <f:selectItems value="#{carconf.colors}" />
             </h:selectOneMenu>
 
+            <h:outputLabel for="selmany_menu_colors" value="#{example_messages['label_interior_color']}"
/>
+            <h:selectManyListbox id="selmany_menu_colors" value="#{carconf.interiorColors}"
+                             styleClass="selectOneMenu" required="true" converter="#{carconf.colorConverter}">
+                <f:selectItems value="#{carconf.colors}" />
+            </h:selectManyListbox>
+
             <h:outputLabel for="selone_menu_extras" value="#{example_messages['label_extras']}"
/>
             <h:selectManyCheckbox id="selone_menu_extras" value="#{carconf.extras}" layout="pageDirection"
styleClass="selectManyCheckbox">
                 <f:selectItems value="#{carconf.extrasList}" />
@@ -111,6 +118,15 @@
     <h:outputFormat value="#{example_messages['msg_price']}" >
         <f:param value="#{carconf.price}" />
     </h:outputFormat>
+
+    <h:dataTable var="interiorColor" value="#{carconf.interiorColors}">
+        <h:column>
+            <f:facet name="header">
+                <h:outputText value="#{example_messages.label_interior_color}"/>
+            </f:facet>
+            <h:outputText value="#{example_messages[interiorColor.color]}"/>
+        </h:column>
+    </h:dataTable>
 
 </f:view>
 

Modified: myfaces/tomahawk/trunk/examples/simple/src/main/webapp/sortAutoTable.jsp
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/examples/simple/src/main/webapp/sortAutoTable.jsp?rev=433909&r1=433908&r2=433909&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/examples/simple/src/main/webapp/sortAutoTable.jsp (original)
+++ myfaces/tomahawk/trunk/examples/simple/src/main/webapp/sortAutoTable.jsp Tue Aug 22 22:23:54
2006
@@ -1,3 +1,4 @@
+
 <%@ page session="false" contentType="text/html;charset=utf-8"%>
 <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
 <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>

Modified: myfaces/tomahawk/trunk/examples/simple/src/main/webapp/validate.jsp
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/examples/simple/src/main/webapp/validate.jsp?rev=433909&r1=433908&r2=433909&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/examples/simple/src/main/webapp/validate.jsp (original)
+++ myfaces/tomahawk/trunk/examples/simple/src/main/webapp/validate.jsp Tue Aug 22 22:23:54
2006
@@ -1,12 +1,12 @@
 <%@ page import="java.math.BigDecimal,
-                 java.util.Date"%>
-<%@ page session="false" contentType="text/html;charset=utf-8"%>
-<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
-<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
-<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
+                 java.util.Date" %>
+<%@ page session="false" contentType="text/html;charset=utf-8" %>
+<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
+<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
+<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>
 <html>
 
-<%@include file="inc/head.inc" %>
+<%@ include file="inc/head.inc" %>
 
 <!--
 /*
@@ -39,57 +39,58 @@
 
     <h:panelGroup id="body">
 
-                <t:messages showDetail="true" showSummary="false"/>
+        <t:messages showDetail="true" showSummary="false"/>
 
-                <h:form id="form1">
-                   <h:panelGrid columns="3">
+        <h:form id="form1">
+            <h:panelGrid columns="3">
 
-                                <h:outputLabel for="email" value="#{example_messages['validate_email']}"
/>
-            <h:inputText id="email" value="#{validateForm.email}" required="true">
-                <f:validator validatorId="org.apache.myfaces.validator.Email"/>
-            </h:inputText>
-                                <t:message id="emailError" for="email" styleClass="error"
/>
-
-                                <h:outputLabel for="email2" value="#{example_messages['validate_email']}2"
/>
-            <h:inputText id="email2" value="#{validateForm.email2}" required="true">
-                <t:validateEmail />
-            </h:inputText>
-                                <t:message id="emailError2" for="email2" styleClass="error"
/>
-
-                                <h:outputLabel for="creditCardNumber" value="#{example_messages['validate_credit']}"
/>
-            <h:inputText id="creditCardNumber" value="#{validateForm.creditCardNumber}"
required="true">
-                <t:validateCreditCard />
-            </h:inputText>
-                                <t:message id="creditCardNumberError" for="creditCardNumber"
styleClass="error" />
-
-                 <h:outputLabel for="regExprValue" value="#{example_messages['validate_regexp']}"
/>
-            <h:inputText id="regExprValue" value="#{validateForm.regExpr}" required="true">
-                <t:validateRegExpr pattern='\d{5}' />
-            </h:inputText>
-                 <t:message id="regExprValueError" for="regExprValue" styleClass="error"
/>
-
-                                <h:outputLabel for="equal" value="#{example_messages['validate_equal']}"
/>
-            <h:inputText id="equal" value="#{validateForm.equal}" required="true"/>
-                                <t:message id="equalError" for="equal" styleClass="error"
/>
-
-                                <h:outputLabel for="equal2" value="#{example_messages['validate_equal']}2"
/>
-            <h:inputText id="equal2" value="#{validateForm.equal2}" required="true">
-                <t:validateEqual for="equal" />
-            </h:inputText>
-                                <t:message id="equal2Error" for="equal2" styleClass="error"
/>
-
-            <h:panelGroup/>
-                            <h:commandButton id="validateButton" value="#{example_messages['button_submit']}"
action="#{validateForm.submit}"/>
-            <h:panelGroup/>
+                <h:outputLabel for="email" value="#{example_messages['validate_email']}"/>
+                <h:inputText id="email" value="#{validateForm.email}" required="true">
+                    <f:validator validatorId="org.apache.myfaces.validator.Email"/>
+                </h:inputText>
+                <t:message id="emailError" for="email" styleClass="error"/>
+
+                <h:outputLabel for="email2" value="#{example_messages['validate_email']}2"/>
+                <h:inputText id="email2" value="#{validateForm.email2}" required="true">
+                    <t:validateEmail/>
+                </h:inputText>
+                <t:message id="emailError2" for="email2" styleClass="error"/>
+
+                <h:outputLabel for="creditCardNumber" value="#{example_messages['validate_credit']}"/>
+                <h:inputText id="creditCardNumber" value="#{validateForm.creditCardNumber}"
required="true">
+                    <t:validateCreditCard/>
+                </h:inputText>
+                <t:message id="creditCardNumberError" for="creditCardNumber" styleClass="error"/>
+
+                <h:outputLabel for="regExprValue" value="#{example_messages['validate_regexp']}"/>
+                <h:inputText id="regExprValue" value="#{validateForm.regExpr}" required="true">
+                    <t:validateRegExpr pattern='\d{5}'/>
+                </h:inputText>
+                <t:message id="regExprValueError" for="regExprValue" styleClass="error"/>
+
+                <h:outputLabel for="equal" value="#{example_messages['validate_equal']}"/>
+                <h:inputText id="equal" value="#{validateForm.equal}" required="true"/>
+                <t:message id="equalError" for="equal" styleClass="error"/>
+
+                <h:outputLabel for="equal2" value="#{example_messages['validate_equal']}2"/>
+                <h:inputText id="equal2" value="#{validateForm.equal2}" required="true">
+                    <t:validateEqual for="equal"/>
+                </h:inputText>
+                <t:message id="equal2Error" for="equal2" styleClass="error"/>
+
+                <h:panelGroup/>
+                <h:commandButton id="validateButton" value="#{example_messages['button_submit']}"
+                                 action="#{validateForm.submit}"/>
+                <h:panelGroup/>
 
-                    </h:panelGrid>
-                </h:form>
+            </h:panelGrid>
+        </h:form>
 
     </h:panelGroup>
 
 </f:view>
 
-<%@include file="inc/page_footer.jsp" %>
+<%@ include file="inc/page_footer.jsp" %>
 
 </body>
 



Mime
View raw message