to the main page about the tutorial  INTERACTIVE WEB SERVICES WITH JAVA back up next

PowerForms in JWIG

PowerForms can be run as a stand-alone tool, but is also integrated into JWIG, as shown in this example:

import dk.brics.jwig.runtime.*;
     
public class PowerFreebie extends Service {

    public class HowMany extends Session {
	
	static final int MAX = 5;
	
	XML templateAsk = [[ 
            <html><body><form>
              How many free T-shirts do you want?
              <input name="amount" type="text"/>
              <input name="continue" type="submit"/>
            </form></body></html> 
        ]];
     
        XML templateReply = [[ 
            <html><body>
              You will receive <[amount]> k00l T-shirts any day now...
            </body></html>
        ]];
         
        XML format = [[ 
            <powerforms>
              <constraint field="amount">
                <regexp pattern=[pattern]/>
              </constraint>
            </powerforms>
        ]];
	
	public void main() {
	    show templateAsk powerforms format<[pattern="<1-"+MAX+">"];
	    int amount = Integer.parseInt(receive amount);
	    exit templateReply<[amount=amount];
	}
    }
}

Notable points:

back COPYRIGHT © 2002-2003 ANDERS MØLLER & MICHAEL I. SCHWARTZBACH next