Author: pete.muir(a)jboss.org
Date: 2009-03-28 10:54:09 -0400 (Sat, 28 Mar 2009)
New Revision: 2243
Modified:
examples/trunk/jsf2/WebContent/home.xhtml
examples/trunk/jsf2/src/main/java/org/jboss/webbeans/examples/numberguess/Game.java
examples/trunk/numberguess/src/main/java/org/jboss/webbeans/examples/numberguess/Game.java
examples/trunk/tomcat/WebContent/home.xhtml
examples/trunk/tomcat/src/main/java/org/jboss/webbeans/examples/numberguess/Game.java
Log:
WBRI-80, thanks to Brandon Blatnick
Modified: examples/trunk/jsf2/WebContent/home.xhtml
===================================================================
--- examples/trunk/jsf2/WebContent/home.xhtml 2009-03-27 22:00:49 UTC (rev 2242)
+++ examples/trunk/jsf2/WebContent/home.xhtml 2009-03-28 14:54:09 UTC (rev 2243)
@@ -20,9 +20,9 @@
<div>
Your guess:
- <h:inputText id="inputGuess" value="#{game.guess}"
required="true" size="3" disabled="#{game.number eq
game.guess}">
- <f:validateLongRange maximum="#{game.biggest}"
minimum="#{game.smallest}"/>
- </h:inputText>
+ <h:inputText id="inputGuess" value="#{game.guess}"
required="true" size="3" disabled="#{game.number eq
game.guess}"
+ validator="#{game.validateNumberRange}">
+ </h:inputText>
<h:commandButton id="GuessButton" value="Guess"
action="#{game.check}" disabled="#{game.number eq game.guess}"/>
</div>
<div>
Modified:
examples/trunk/jsf2/src/main/java/org/jboss/webbeans/examples/numberguess/Game.java
===================================================================
---
examples/trunk/jsf2/src/main/java/org/jboss/webbeans/examples/numberguess/Game.java 2009-03-27
22:00:49 UTC (rev 2242)
+++
examples/trunk/jsf2/src/main/java/org/jboss/webbeans/examples/numberguess/Game.java 2009-03-28
14:54:09 UTC (rev 2243)
@@ -7,6 +7,8 @@
import javax.annotation.PostConstruct;
import javax.context.SessionScoped;
import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.inject.AnnotationLiteral;
import javax.inject.Current;
@@ -91,4 +93,16 @@
this.number = manager.getInstanceByType(Integer.class, new
AnnotationLiteral<Random>(){});
}
+ public void validateNumberRange(FacesContext context, UIComponent toValidate, Object
value)
+ {
+ int input = (Integer) value;
+
+ if (input < smallest || input > biggest)
+ {
+ ((UIInput)toValidate).setValid(false);
+
+ FacesMessage message = new FacesMessage("Invalid guess");
+ context.addMessage(toValidate.getClientId(context), message);
+ }
+ }
}
Modified:
examples/trunk/numberguess/src/main/java/org/jboss/webbeans/examples/numberguess/Game.java
===================================================================
---
examples/trunk/numberguess/src/main/java/org/jboss/webbeans/examples/numberguess/Game.java 2009-03-27
22:00:49 UTC (rev 2242)
+++
examples/trunk/numberguess/src/main/java/org/jboss/webbeans/examples/numberguess/Game.java 2009-03-28
14:54:09 UTC (rev 2243)
@@ -7,6 +7,8 @@
import javax.annotation.PostConstruct;
import javax.context.SessionScoped;
import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.inject.AnnotationLiteral;
import javax.inject.Current;
@@ -91,4 +93,16 @@
this.number = manager.getInstanceByType(Integer.class, new
AnnotationLiteral<Random>(){});
}
+ public void validateNumberRange(FacesContext context, UIComponent toValidate, Object
value)
+ {
+ int input = (Integer) value;
+
+ if (input < smallest || input > biggest)
+ {
+ ((UIInput)toValidate).setValid(false);
+
+ FacesMessage message = new FacesMessage("Invalid guess");
+ context.addMessage(toValidate.getClientId(context), message);
+ }
+ }
}
Modified: examples/trunk/tomcat/WebContent/home.xhtml
===================================================================
--- examples/trunk/tomcat/WebContent/home.xhtml 2009-03-27 22:00:49 UTC (rev 2242)
+++ examples/trunk/tomcat/WebContent/home.xhtml 2009-03-28 14:54:09 UTC (rev 2243)
@@ -20,9 +20,9 @@
<div>
Your guess:
- <h:inputText id="inputGuess" value="#{game.guess}"
required="true" size="3" disabled="#{game.number eq
game.guess}">
- <f:validateLongRange maximum="#{game.biggest}"
minimum="#{game.smallest}"/>
- </h:inputText>
+ <h:inputText id="inputGuess" value="#{game.guess}"
required="true" size="3" disabled="#{game.number eq
game.guess}"
+ validator="#{game.validateNumberRange}">
+ </h:inputText>
<h:commandButton id="GuessButton" value="Guess"
action="#{game.check}" disabled="#{game.number eq game.guess}"/>
</div>
<div>
Modified:
examples/trunk/tomcat/src/main/java/org/jboss/webbeans/examples/numberguess/Game.java
===================================================================
---
examples/trunk/tomcat/src/main/java/org/jboss/webbeans/examples/numberguess/Game.java 2009-03-27
22:00:49 UTC (rev 2242)
+++
examples/trunk/tomcat/src/main/java/org/jboss/webbeans/examples/numberguess/Game.java 2009-03-28
14:54:09 UTC (rev 2243)
@@ -7,6 +7,8 @@
import javax.annotation.PostConstruct;
import javax.context.SessionScoped;
import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.inject.AnnotationLiteral;
import javax.inject.Current;
@@ -91,4 +93,16 @@
this.number = manager.getInstanceByType(Integer.class, new
AnnotationLiteral<Random>(){});
}
+ public void validateNumberRange(FacesContext context, UIComponent toValidate, Object
value)
+ {
+ int input = (Integer) value;
+
+ if (input < smallest || input > biggest)
+ {
+ ((UIInput)toValidate).setValid(false);
+
+ FacesMessage message = new FacesMessage("Invalid guess");
+ context.addMessage(toValidate.getClientId(context), message);
+ }
+ }
}
Show replies by date