<?xml version="1.0" encoding="ISO-8859-1"?>

<webapp>

  <!-- define the tags that will be used in the rest of this document -->
  <tagdef name="target" class="org.webcontrol.tag.TargetTag"/>
  <tagdef name="var" class="org.webcontrol.tag.VarTag"/>
  <tagdef name="setvar" class="org.webcontrol.tag.SetVarTag"/>
  <tagdef name="forward" class="org.webcontrol.tag.ForwardTag"/>
  <tagdef name="include" class="org.webcontrol.tag.IncludeTag"/>
  <tagdef name="redirect" class="org.webcontrol.tag.RedirectTag"/>
  <tagdef name="save" class="org.webcontrol.tag.SaveTag"/>
  <tagdef name="exception" class="org.webcontrol.tag.ExceptionTag"/>
  <tagdef name="method" class="org.webcontrol.tag.method.MethodTag"/>
  <tagdef name="return" class="org.webcontrol.tag.method.ReturnTag"/>
  <tagdef name="param" class="org.webcontrol.tag.method.ParamTag"/>
  <tagdef name="if" class="org.webcontrol.tag.IfTag"/>
  <tagdef name="foreach" class="org.webcontrol.tag.ForEachTag"/>

  <target name="index" comment="Front page of site">
    <forward url="/index.jsp"/>
  </target>

  <target name="show_categories" comment="Show category list">
    <method class="joesstereohut.Category" method="getAllCategories">
      <return varname="categories" type="joesstereohut.Category[]"/>
    </method>
    <save name="categories" var="categories"/>
    <forward url="/show_categories.jsp"/>
  </target>

  <target name="show_items">
    <var name="categoryName" type="java.lang.String" value="${param:categoryName}"/>
    <exception type="java.lang.NullPointerException" page="/bad_category.jsp">
      <method class="joesstereohut.Category" method="getCategoryByName">
        <return varname="category" type="joesstereohut.Category"/>
        <param varname="categoryName"/>
      </method>
    </exception>
    <var name="items" type="java.util.List" value="${category.items}"/>
    <save name="items" var="items"/>
    <forward url="/show_items.jsp"/>
  </target>


  <!-- example with validation -->
  <target name="register">

    <exception type="org.webcontrol.exception.ValidationException" page="/register_form.jsp">
      <var name="firstName" type="java.lang.String" value="${param:firstName}" label="First Name"/>
      <var name="lastName" type="java.lang.String" value="${param:lastName}" label="Last Name"/>
      <var name="phone" type="java.lang.String" value="${param:phone}" validator="joesstereohut.PhoneValidator" label="Phone Number"/>
      <var name="email" type="java.lang.String" value="${param:email}" validator="joesstereohut.EmailValidator" label="E-mail Address"/>
    </exception>

    <method class="joesstereohut.user.UserManager" method="createUser">
      <return varname="user" type="joesstereohut.user.User"/>
      <param varname="firstName"/>
      <param varname="lastName"/>
      <param varname="phone"/>
      <param varname="email"/>
    </method>

    <save name="user" var="user" scope="session"/>

    <forward url="/registration_complete.jsp"/>

  </target>

</webapp>
