cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guy McArthur <g...@guymcarthur.com>
Subject web-app tutorial
Date Fri, 28 Jun 2002 22:34:21 GMT

I like some of the things in the tutorial, but I don't want to do XForms, 
or XSP, or describe form validation in XML. Just want to map requests to 
java beans. Beans set their mode (state) as a parameter to the stylesheet, 
and the stylesheet has templates for each mode. The useBean syntax of jsp 
makes it easy, but if the cocoon sitemap can do that too, eliminating the 
jsp would be good.

What would be ideal, is using JXPath and eliminating the bean marshalling 
to xml step altogether.

It seems like Actions could do this, but it's unclear....

Say for a simple example, a "guess a number" web application with one bean
and one corresponding stylesheet.

This outlines the kind of thing I'd like to be able to do.

--
public class GuessGame {
   private int target, guess, steps = 0;
   private boolean hasGuessed;
   private String action; // value of form submit

   public GuessGame() {
      this.target = (int)Math.random(100);
   }

   public void setAction(String action) {
      this.action = action;
   }
 
   public String getMode() {
      if(action.equals("Cancel")) return "cancel";
      else if(haveGuessed) {
         return (guess == target) ? "final" : "guessing";
      } else return "initial";
   }

   public int getGuess() {
      return guess;
   }
  
   public void setGuess(int guess) {
      this.guess = guess;
      haveGuessed = true;
      ++steps;
   }
}
--
<%-- Have some way to map requests to bean logic.
     With the bean data available to the stylesheet. 
  --%>
<jsp:useBean name="game" class="GuessGame" scope="session"/>
<jsp:setProperty id="game" name="*"/>

--
<xsl:stylesheet>

   <xsl:template match="game" mode="initial">
     Hit Next to begin the game or Quit to close.
     <form>
        <input type="submit" name="action" value="Next"/>
        <input type="submit" name="action" value="Quit"/>
     </form>
   </xsl:template>

   <xsl:template match="game" mode="guessing">
     Sorry! <xsl:value-of select="@guess"/> was
     <xsl:choose>
        <xsl:when test="@guess &gt; @target">
          too high.
        </xsl:when>
        <xsl:otherwise>
           too low.
        </xsl:otherwise>
     </xsl:choose>

     Guess again.

     <form>
        <input type="text" name="guess" value="{@guess}"/>
        <input type="submit" name="action" value="Next"/>
        <input type="submit" name="action" value="Quit"/>
     </form>
   </xsl:template>

   <xsl:template match="game" mode="final">
     You got it in <xsl:value-of select="@steps"/> steps!
     <form>
        <input type="submit" name="action" value="Quit"/>
     </form>
   </xsl:template>

   <xsl:template match="game" mode="quit">
      Thanks for playing.
   </xsl:template>
</xsl:stylesheet>
--

Anyways, I'd like to do something like that, but what components go in the 
middle between beans and xsl is a mystery....



---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <cocoon-users-unsubscribe@xml.apache.org>
For additional commands, e-mail:   <cocoon-users-help@xml.apache.org>


Mime
View raw message