Skip to content

Commit

Permalink
WBRI-74, WBRI-77, WBRI-73
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@697 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
pmuir committed Dec 24, 2008
1 parent c72ac20 commit 475ccba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
7 changes: 5 additions & 2 deletions examples/numberguess/WebContent/home.xhtml
Expand Up @@ -11,8 +11,8 @@
<h:form id="NumberGuessMain">
<div style="color: red">
<h:messages id="messages" globalOnly="false"/>
<h:outputText id="Higher" value="Higher!" rendered="#{game.number gt game.guess}"/>
<h:outputText id="Lower" value="Lower!" rendered="#{game.number lt game.guess}"/>
<h:outputText id="Higher" value="Higher!" rendered="#{game.number gt game.guess and game.guess ne 0}"/>
<h:outputText id="Lower" value="Lower!" rendered="#{game.number lt game.guess and game.guess ne 0}"/>
</div>

<div>
Expand All @@ -26,6 +26,9 @@
</h:inputText>
<h:commandButton id="GuessButton" value="Guess" action="#{game.check}" disabled="#{game.number eq game.guess}"/>
</div>
<div>
<h:commandButton id="RestartButton" value="Reset" action="#{game.reset}" immediate="true" />
</div>
</h:form>
</ui:define>
</ui:composition>
Expand Down
@@ -1,11 +1,15 @@
package org.jboss.webbeans.examples.numberguess;


import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.webbeans.AnnotationLiteral;
import javax.webbeans.Current;
import javax.webbeans.Initializer;
import javax.webbeans.Named;
import javax.webbeans.SessionScoped;
import javax.webbeans.manager.Manager;

@Named
@SessionScoped
Expand All @@ -18,17 +22,16 @@ public class Game
private int biggest;
private int remainingGuesses;

@Current Manager manager;

public Game()
{
}

@Initializer
Game(@Random int number, @MaxNumber int maxNumber)
{
this.number = number;
this.smallest = 1;
Game(@MaxNumber int maxNumber)
{
this.biggest = maxNumber;
this.remainingGuesses = 10;
}

public int getNumber()
Expand Down Expand Up @@ -79,4 +82,13 @@ public String check()
return null;
}

@PostConstruct
public void reset()
{
this.smallest = 0;
this.guess = 0;
this.remainingGuesses = 10;
this.number = manager.getInstanceByType(Integer.class, new AnnotationLiteral<Random>(){});
}

}

0 comments on commit 475ccba

Please sign in to comment.