You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by pr...@apache.org on 2005/11/19 01:20:07 UTC

svn commit: r345606 - in /myfaces/examples/trunk/sandbox: inputAjax.jsp src/java/org/apache/myfaces/examples/inputAjax/InputAjaxBean.java

Author: prophecy
Date: Fri Nov 18 16:20:04 2005
New Revision: 345606

URL: http://svn.apache.org/viewcvs?rev=345606&view=rev
Log:
- was setting the message id wrong so wasn't working with multiple message tags on the same page, fixed
- now it will also clear the error message on success

Modified:
    myfaces/examples/trunk/sandbox/inputAjax.jsp
    myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputAjax/InputAjaxBean.java

Modified: myfaces/examples/trunk/sandbox/inputAjax.jsp
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/sandbox/inputAjax.jsp?rev=345606&r1=345605&r2=345606&view=diff
==============================================================================
--- myfaces/examples/trunk/sandbox/inputAjax.jsp (original)
+++ myfaces/examples/trunk/sandbox/inputAjax.jsp Fri Nov 18 16:20:04 2005
@@ -73,7 +73,9 @@
                                  id="text2"
                                  forceId="true"
                                  showOkButton="true"
-                                 showCancelText="true"></s:inputTextAjax>
+                                 showCancelText="true"
+                                 validator="#{inputAjaxBean.validateText2}"></s:inputTextAjax>
+                <t:message for="text2" styleClass="error"/>
                 <f:verbatim>This component demonstrates ajax updating ability, but you must click Ok for it to send.
                     Cancel will clear the text and not send an update.</f:verbatim>
             </h:panelGrid>

Modified: myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputAjax/InputAjaxBean.java
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputAjax/InputAjaxBean.java?rev=345606&r1=345605&r2=345606&view=diff
==============================================================================
--- myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputAjax/InputAjaxBean.java (original)
+++ myfaces/examples/trunk/sandbox/src/java/org/apache/myfaces/examples/inputAjax/InputAjaxBean.java Fri Nov 18 16:20:04 2005
@@ -16,9 +16,14 @@
 package org.apache.myfaces.examples.inputAjax;
 
 import javax.faces.model.SelectItem;
+import javax.faces.context.FacesContext;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
+import javax.faces.application.FacesMessage;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Date;
+import java.util.Calendar;
 
 /**
  * User: treeder
@@ -35,6 +40,30 @@
 
     private String radioValue;
     private List radioItems;
+
+
+    /**
+     * Simple validator to show error handling messages in examples, returns an error if value string is
+     * less then 3 characters
+     *
+     * @param context
+     * @param toValidate
+     * @param value
+     */
+    public void validateText2(FacesContext context, UIComponent toValidate, Object value)
+    {
+        // make sure it's not in the past
+        if (value != null)
+        {
+            // lets say it must be more than 2 characters
+            String valStr = (String) value;
+            if (valStr.length() < 3)
+            {
+                ((UIInput) toValidate).setValid(false);
+                context.addMessage(toValidate.getClientId(context), new FacesMessage(FacesMessage.SEVERITY_ERROR, "Text must be longer than 3 characters", null));
+            }
+        }
+    }
 
     public String submit()
     {