<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<xsp:page xmlns:xsp="http://apache.org/xsp"
          xmlns:xsp-formval="http://apache.org/xsp/form-validator/2.0"
          xmlns:esql="http://apache.org/cocoon/SQL/v2">
<document>
  <header>
    <title>Employee</title>
  </header>
  <body>
    <s1 title="Create an Employee">
      <form handler="create-empl.html">
        <p>
          You can create an employee by typing in the
          name and pressing the "submit" button.
        </p>
        <p>
          Name: <text name="name" size="30" required="true"/><br />
	  <xsp-formval:on-toosmall name="name">
	    Name must be at least 5 characters
	  </xsp-formval:on-toosmall>
	  <xsp-formval:on-toolarge name="name">
	    Name must be less than 64 characters
	  </xsp-formval:on-toolarge>
	</p>
        <p>
          Department:
          <select name="department">
            <esql:connection>

              <!-- declare the connection pool we are using -->
              <esql:pool>personnel</esql:pool>

              <!-- query execution blocks can be repeated -->
              <esql:execute-query>

                <!-- Find all departments and order them -->
                <esql:query>
                  SELECT id, name
                  FROM department ORDER BY name
                </esql:query>

               <!-- What to do with the results -->
                <esql:results>
                  <!--
                       A successful query that returns results
                       executes this block.  You can also embed
                       more "execute-query" blocks inside the
                       row-results.  That way you can have queries
                       that filter information based on the results
                       of other queries.
                  -->
                  <esql:row-results>
                    <option>
                      <xsp:attribute name="value"><esql:get-string column="id"/></xsp:attribute>
                      <esql:get-string column="name"/>
                    </option>
                  </esql:row-results>
                  <!--
                       Other result types are "no-results" and
                       "error-results".  A successful query that
                       does not return results (an empty resultset)
                       will use the XML embedded in the "no-results"
                       section.  An unsuccessful query that throws
                       an exception will use the XML embedded in
                       the "error-results" section.
                  -->
                </esql:results>
              </esql:execute-query>
            </esql:connection>
          </select><br/>
	  <xsp-formval:on-null name="department">
	    You must select a department
	  </xsp-formval:on-null>
	</p>
        <submit name="Create Employee"/>
        <note>
          * These fields are required.
        </note>
      </form>
    </s1>
  </body>
</document>
</xsp:page>

