cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guy McArthur <>
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() { = (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;
<%-- 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:template match="game" mode="initial">
     Hit Next to begin the game or Quit to close.
        <input type="submit" name="action" value="Next"/>
        <input type="submit" name="action" value="Quit"/>

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

     Guess again.

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

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

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

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.     <>

To unsubscribe, e-mail:     <>
For additional commands, e-mail:   <>

View raw message