[seam-commits] Seam SVN: r13224 - in examples/trunk/booking-simplified/src/main: webapp and 4 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu Jun 17 17:12:03 EDT 2010


Author: dan.j.allen
Date: 2010-06-17 17:12:01 -0400 (Thu, 17 Jun 2010)
New Revision: 13224

Added:
   examples/trunk/booking-simplified/src/main/webapp/resources/components/model/
   examples/trunk/booking-simplified/src/main/webapp/resources/components/model/displayAccount.xhtml
   examples/trunk/booking-simplified/src/main/webapp/resources/components/model/displayHotel.xhtml
Removed:
   examples/trunk/booking-simplified/src/main/webapp/WEB-INF/fragments/
Modified:
   examples/trunk/booking-simplified/src/main/java/org/jboss/seam/faces/component/UIInputContainer.java
   examples/trunk/booking-simplified/src/main/webapp/account.xhtml
   examples/trunk/booking-simplified/src/main/webapp/book.xhtml
   examples/trunk/booking-simplified/src/main/webapp/confirm.xhtml
   examples/trunk/booking-simplified/src/main/webapp/hotel.xhtml
   examples/trunk/booking-simplified/src/main/webapp/password.xhtml
   examples/trunk/booking-simplified/src/main/webapp/register.xhtml
   examples/trunk/booking-simplified/src/main/webapp/resources/components/property/output.xhtml
Log:
replace fragments with composite components
bug fixes to UIInputContainer


Modified: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/faces/component/UIInputContainer.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/faces/component/UIInputContainer.java	2010-06-17 19:34:31 UTC (rev 13223)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/faces/component/UIInputContainer.java	2010-06-17 21:12:01 UTC (rev 13224)
@@ -42,6 +42,7 @@
 import javax.faces.component.UIViewRoot;
 import javax.faces.component.behavior.AjaxBehavior;
 import javax.faces.component.behavior.ClientBehavior;
+import javax.faces.component.behavior.ClientBehaviorHolder;
 import javax.faces.component.html.HtmlOutputLabel;
 import javax.faces.context.FacesContext;
 import javax.faces.validator.BeanValidator;
@@ -268,10 +269,13 @@
       // temporary workaround for state saving bug; remove any ClientBehaviors added dynamically
       for (EditableValueHolder i : elements.getInputs())
       {
-         Map<String, List<ClientBehavior>> b = ((UIInput) i).getClientBehaviors();
-         for (String k : b.keySet())
+         if (i instanceof ClientBehaviorHolder)
          {
-            b.get(k).clear();
+            Map<String, List<ClientBehavior>> b = ((ClientBehaviorHolder) i).getClientBehaviors();
+            for (String k : b.keySet())
+            {
+               b.get(k).clear();
+            }
          }
       }
    }
@@ -503,21 +507,24 @@
       public void registerInput(final EditableValueHolder input, final Validator validator, final FacesContext context)
       {
          inputs.add(input);
-         UIInput inputc = (UIInput) input;
-         String ajaxEvent = (String) attributes.get(getAjaxAttributeName());
-         if (ajaxEvent != null && (ajaxEvent.equalsIgnoreCase("default")))
+         if (input instanceof ClientBehaviorHolder)
          {
-            ajaxEvent = inputc.getDefaultEventName();
-         }
-         if (ajaxEvent != null)
-         {
-            Map<String, List<ClientBehavior>> behaviors = inputc.getClientBehaviors();
-            if (!behaviors.containsKey(ajaxEvent))
+            ClientBehaviorHolder bh = (ClientBehaviorHolder) input;
+            String ajaxEvent = (String) attributes.get(getAjaxAttributeName());
+            if (ajaxEvent != null && (ajaxEvent.equalsIgnoreCase("default")))
             {
-               AjaxBehavior ajax = new AjaxBehavior();
-               ajax.setRender(Arrays.asList(containerId));
-               inputc.addClientBehavior(ajaxEvent.toLowerCase(), ajax);
+               ajaxEvent = bh.getDefaultEventName();
             }
+            if (ajaxEvent != null)
+            {
+               Map<String, List<ClientBehavior>> behaviors = bh.getClientBehaviors();
+               if (!behaviors.containsKey(ajaxEvent))
+               {
+                  AjaxBehavior ajax = new AjaxBehavior();
+                  ajax.setRender(Arrays.asList(containerId));
+                  bh.addClientBehavior(ajaxEvent.toLowerCase(), ajax);
+               }
+            }
          }
          if (input.isRequired() || isRequiredByConstraint(input, validator, context))
          {
@@ -569,13 +576,21 @@
             return false;
          }
 
-         // NOTE believe it or not, getValueReference on ValueExpression is
-         // broken, so we have to do it ourselves
-         ValueReference vref = new ValueExpressionAnalyzer(((UIComponent) input).getValueExpression("value")).getValueReference(context.getELContext());
-         PropertyDescriptor d = validator.getConstraintsForClass(vref.getBase().getClass()).getConstraintsForProperty((String) vref.getProperty());
+         ValueReference vref = buildValueReference(input, context);
+         String property = (String) vref.getProperty();
+         // optimization, though not sitting right
+         if (propertyName != null)
+         {
+            propertyName = property;
+         }
+         PropertyDescriptor d = validator.getConstraintsForClass(vref.getBase().getClass()).getConstraintsForProperty(property);
          return (d != null) && d.hasConstraints();
       }
 
+      /**
+       * Gets the name of the property bound to the first input, or null if there
+       * are no inputs present.
+       */
       public String getPropertyName(final FacesContext context)
       {
          if (propertyName != null)
@@ -588,10 +603,17 @@
             return null;
          }
 
-         propertyName = (String) new ValueExpressionAnalyzer(((UIComponent) inputs.get(0)).getValueExpression("value")).getValueReference(context.getELContext()).getProperty();
+         propertyName = buildValueReference(inputs.get(0), context).getProperty().toString();
          return propertyName;
       }
 
+      private ValueReference buildValueReference(final EditableValueHolder input, final FacesContext context)
+      {
+         // NOTE believe it or not, getValueReference on ValueExpression is broken, so we have to do it ourselves
+         return new ValueExpressionAnalyzer(((UIComponent) input).getValueExpression("value"))
+            .getValueReference(context.getELContext());
+      }
+
       public void wire(final FacesContext context)
       {
          int numInputs = inputs.size();

Modified: examples/trunk/booking-simplified/src/main/webapp/account.xhtml
===================================================================
--- examples/trunk/booking-simplified/src/main/webapp/account.xhtml	2010-06-17 19:34:31 UTC (rev 13223)
+++ examples/trunk/booking-simplified/src/main/webapp/account.xhtml	2010-06-17 21:12:01 UTC (rev 13224)
@@ -4,6 +4,7 @@
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
+   xmlns:m="http://http://java.sun.com/jsf/composite/components/model"
    template="/WEB-INF/layout/template.xhtml">
 
    <ui:define name="content">
@@ -18,7 +19,7 @@
             <h:messages id="messages" globalOnly="true"/>
          </div>
 
-         <ui:include src="/WEB-INF/fragments/account.xhtml"/>
+         <m:displayAccount value="#{currentUser}" showEmail="true"/>
 
          <div class="buttonBox">
             <h:button id="changePassword" value="Change password" outcome="/password.xhtml"/>

Modified: examples/trunk/booking-simplified/src/main/webapp/book.xhtml
===================================================================
--- examples/trunk/booking-simplified/src/main/webapp/book.xhtml	2010-06-17 19:34:31 UTC (rev 13223)
+++ examples/trunk/booking-simplified/src/main/webapp/book.xhtml	2010-06-17 21:12:01 UTC (rev 13224)
@@ -5,6 +5,7 @@
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:s="http://jboss.org/seam/faces"
+   xmlns:m="http://http://java.sun.com/jsf/composite/components/model"
    xmlns:p="http://http://java.sun.com/jsf/composite/components/property"
    template="/WEB-INF/layout/template.xhtml">
 
@@ -18,7 +19,7 @@
             <h:messages id="messages" globalOnly="true"/>
          </div>
       
-         <ui:include src="/WEB-INF/fragments/hotel.xhtml"/>
+         <m:displayHotel value="#{hotel}"/>
          
          <div style="clear: both;"/>
       

Modified: examples/trunk/booking-simplified/src/main/webapp/confirm.xhtml
===================================================================
--- examples/trunk/booking-simplified/src/main/webapp/confirm.xhtml	2010-06-17 19:34:31 UTC (rev 13223)
+++ examples/trunk/booking-simplified/src/main/webapp/confirm.xhtml	2010-06-17 21:12:01 UTC (rev 13224)
@@ -4,6 +4,7 @@
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
+   xmlns:m="http://http://java.sun.com/jsf/composite/components/model"
    xmlns:p="http://http://java.sun.com/jsf/composite/components/property"
    template="/WEB-INF/layout/template.xhtml">
 
@@ -15,7 +16,7 @@
 
       <div class="section">
 
-         <ui:include src="/WEB-INF/fragments/hotel.xhtml"/>
+         <m:displayHotel value="#{hotel}"/>
       
          <p:output label="Total payment" value="#{booking.total}">
             <f:convertNumber for="output" type="currency" currencySymbol="$"/>

Modified: examples/trunk/booking-simplified/src/main/webapp/hotel.xhtml
===================================================================
--- examples/trunk/booking-simplified/src/main/webapp/hotel.xhtml	2010-06-17 19:34:31 UTC (rev 13223)
+++ examples/trunk/booking-simplified/src/main/webapp/hotel.xhtml	2010-06-17 21:12:01 UTC (rev 13224)
@@ -5,6 +5,7 @@
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:s="http://jboss.org/seam/faces"
+   xmlns:m="http://java.sun.com/jsf/composite/components/model"
    template="/WEB-INF/layout/template.xhtml">
 
    <f:metadata>
@@ -19,7 +20,7 @@
       </div>
 
       <div class="section">
-         <ui:include src="/WEB-INF/fragments/hotel.xhtml"/>
+         <m:displayHotel value="#{hotel}"/>
 
          <div class="buttonBox">
             <h:panelGroup rendered="#{not identity.loggedIn}">

Modified: examples/trunk/booking-simplified/src/main/webapp/password.xhtml
===================================================================
--- examples/trunk/booking-simplified/src/main/webapp/password.xhtml	2010-06-17 19:34:31 UTC (rev 13223)
+++ examples/trunk/booking-simplified/src/main/webapp/password.xhtml	2010-06-17 21:12:01 UTC (rev 13224)
@@ -26,7 +26,7 @@
             
                <p:input id="current">
                   <h:inputSecret id="password" value="#{currentUser.password}">
-                  	<f:validator validatorId="currentPasswordValidator" />
+                  	<f:validator validatorId="currentPasswordValidator"/>
                   </h:inputSecret>
                </p:input>
             

Modified: examples/trunk/booking-simplified/src/main/webapp/register.xhtml
===================================================================
--- examples/trunk/booking-simplified/src/main/webapp/register.xhtml	2010-06-17 19:34:31 UTC (rev 13223)
+++ examples/trunk/booking-simplified/src/main/webapp/register.xhtml	2010-06-17 21:12:01 UTC (rev 13224)
@@ -5,7 +5,7 @@
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:s="http://jboss.org/seam/faces"
-   xmlns:p="http://http://java.sun.com/jsf/composite/components/property"
+   xmlns:prop="http://http://java.sun.com/jsf/composite/components/property"
    template="/WEB-INF/layout/template.xhtml">
 
    <ui:param name="pageClass" value="home"/>
@@ -29,9 +29,9 @@
          </div>
 
          <h:form id="registrationForm" prependId="false">
-            <h:outputScript name="jsf.js" library="javax.faces" target="head"/>
             <fieldset>
 
+               <!-- manually append Ajax behavior -->
                <p:input id="username">
                   <h:inputText id="input" value="#{newUser.username}"
                      binding="#{registrar.usernameInput}">
@@ -39,6 +39,7 @@
                   </h:inputText>
                </p:input>
 
+               <!-- automatically append Ajax behavior -->
                <p:input id="name" ajax="true">
                   <h:inputText id="input" value="#{newUser.name}"/>
                </p:input>

Added: examples/trunk/booking-simplified/src/main/webapp/resources/components/model/displayAccount.xhtml
===================================================================
--- examples/trunk/booking-simplified/src/main/webapp/resources/components/model/displayAccount.xhtml	                        (rev 0)
+++ examples/trunk/booking-simplified/src/main/webapp/resources/components/model/displayAccount.xhtml	2010-06-17 21:12:01 UTC (rev 13224)
@@ -0,0 +1,19 @@
+<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<ui:composition xmlns="http://www.w3.org/1999/xhtml"
+   xmlns:ui="http://java.sun.com/jsf/facelets"
+   xmlns:p="http://http://java.sun.com/jsf/composite/components/property"
+   xmlns:cc="http://java.sun.com/jsf/composite">
+
+   <cc:interface>
+      <cc:attribute name="value" required="true"/>
+      <cc:attribute name="showEmail" required="false" default="false"/>
+   </cc:interface>
+
+   <cc:implementation>
+      <p:output label="Full name" value="#{cc.attrs.value.name}"/>
+      <p:output label="Username" value="#{cc.attrs.value.username}"/>
+      <p:output label="Email address" value="#{cc.attrs.value.email}" rendered="#{not cc.attrs.showEmail}"/>
+   </cc:implementation>
+
+</ui:composition>

Added: examples/trunk/booking-simplified/src/main/webapp/resources/components/model/displayHotel.xhtml
===================================================================
--- examples/trunk/booking-simplified/src/main/webapp/resources/components/model/displayHotel.xhtml	                        (rev 0)
+++ examples/trunk/booking-simplified/src/main/webapp/resources/components/model/displayHotel.xhtml	2010-06-17 21:12:01 UTC (rev 13224)
@@ -0,0 +1,29 @@
+<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<ui:composition xmlns="http://www.w3.org/1999/xhtml"
+   xmlns:ui="http://java.sun.com/jsf/facelets"
+   xmlns:f="http://java.sun.com/jsf/core"
+   xmlns:h="http://java.sun.com/jsf/html"
+   xmlns:p="http://http://java.sun.com/jsf/composite/components/property"
+   xmlns:cc="http://java.sun.com/jsf/composite">
+
+   <cc:interface>
+      <cc:attribute name="value" required="true"/>
+   </cc:interface>
+
+   <cc:implementation>
+      <p:output label="Name" value="#{cc.attrs.value.name}"/>
+      <p:output label="Address" value="#{cc.attrs.value.address}"/>
+      <p:output label="City" value="#{cc.attrs.value.city}"/>
+      <p:output label="State" value="#{cc.attrs.value.state}"/>
+      <p:output label="Zip" value="#{cc.attrs.value.zip}"/>
+      <p:output label="Country" value="#{cc.attrs.value.country}"/>
+      <p:output label="Class" override="true">
+         <h:graphicImage value="/img/#{cc.attrs.value.stars}-star.gif" style="padding-top: 4px;"/>
+      </p:output>
+      <p:output label="Nightly rate" value="#{cc.attrs.value.price}">
+         <f:convertNumber for="output" type="currency" currencySymbol="$"/>
+      </p:output>
+   </cc:implementation>
+
+</ui:composition>

Modified: examples/trunk/booking-simplified/src/main/webapp/resources/components/property/output.xhtml
===================================================================
--- examples/trunk/booking-simplified/src/main/webapp/resources/components/property/output.xhtml	2010-06-17 19:34:31 UTC (rev 13223)
+++ examples/trunk/booking-simplified/src/main/webapp/resources/components/property/output.xhtml	2010-06-17 21:12:01 UTC (rev 13224)
@@ -10,7 +10,7 @@
    <cc:interface>
       <cc:attribute name="label" required="true"/>
       <cc:attribute name="value" required="false"/>
-      <cc:attribute name="override" required="false" default="false"/>
+      <cc:attribute name="verbatim" required="false" default="false"/>
    </cc:interface>
 
    <cc:implementation>
@@ -18,8 +18,8 @@
          <span class="label">#{cc.attrs.label}:</span>
          <span class="output">
             <c:choose>
-               <c:when test="#{cc.attrs.override}"><cc:insertChildren/></c:when>
-               <c:otherwise><h:outputText id="output" value="#{cc.attrs.value}"><cc:insertChildren/></h:outputText></c:otherwise>
+               <c:when test="#{cc.attrs.verbatim}"><cc:insertChildren/></c:when>
+               <c:otherwise><h:outputText value="#{cc.attrs.value}"><cc:insertChildren/></h:outputText></c:otherwise>
             </c:choose>
          </span>
       </div>



More information about the seam-commits mailing list