ugo         2003/11/03 15:17:41

  Modified:    src/blocks/woody/samples/flow woody_flow_example.js
               src/blocks/woody/samples sitemap.xmap
  Added:       src/blocks/woody/samples/forms countryselector_template.xml
                        countryselector_success.xsp
                        countryselector_form.xml
  Log:
  Added a sample showing how to change a selection list inside an event handler 
using an in-memory collection.
  
  Revision  Changes    Path
  1.1                  
cocoon-2.1/src/blocks/woody/samples/forms/countryselector_template.xml
  
  Index: countryselector_template.xml
  ===================================================================
  <?xml version="1.0"?>
  <page xmlns:wt="http://apache.org/cocoon/woody/template/1.0"; 
xmlns:wi="http://apache.org/cocoon/woody/instance/1.0";>
    <title>Country selector</title>
    <para>This example illustrates how you can programmatically update the
      content of a selection list using a collection built in the flow.</para>
    <para>
      This sample illustrates event-handling in Woody and how selection lists 
can be changed
      programmatically.
    </para>
    <para>
      Event-handlers are defined in the form definition to update the selection 
lists and set
      the comment text below the table. This requires only a few lines of 
server-side JavaScript.
      Selection widgets also have a "submit-on-change" attribute set in the 
form template so that
      changes are considered immediately by the server.
    </para>
    <para>
      See "countryselector_form.xml" and "countryselector_template.xml" to see 
how this is done.
    </para>
    <content>
      <wt:form-template action="countryselector" method="POST">
        <wt:continuation-id/>
        <table border="1">
          <tr>
            <td valign="top"><wt:widget-label id="us-nonus"/></td>
            <td valign="top">
              <wt:widget id="us-nonus">
                <wi:styling submit-on-change="true"/>
              </wt:widget>
            </td>
          </tr>
          <tr>
            <td valign="top"><wt:widget-label id="country"/></td>
            <td valign="top">
              <wt:widget id="country">
                <wi:styling submit-on-change="true"/>
              </wt:widget>
            </td>
          </tr>
        </table>
  
        <br/>
        <wt:widget id="message"/>
        <br/>
        <br/>
        
        <input type="submit"/>
      </wt:form-template>
    </content>
  </page>
  
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/samples/forms/countryselector_success.xsp
  
  Index: countryselector_success.xsp
  ===================================================================
  <?xml version="1.0"?>
  <xsp:page language="java"
    xmlns:xsp="http://apache.org/xsp";>
  
    <xsp:structure>
      <xsp:include>org.apache.cocoon.woody.formmodel.*</xsp:include>
    </xsp:structure>
  
    <page>
      <title>Country selector result</title>
      <content>
        <xsp:logic>
          // get reference to form and some of the widgets on it
          Form form = (Form)request.getAttribute("countryselectorform");
          Field usnonus = (Field)form.getWidget("us-nonus");
          Field country = (Field)form.getWidget("country");
        </xsp:logic>
  
        You selected: <xsp:expr>usnonus.getValue()</xsp:expr>,
        country/state <xsp:expr>country.getValue()</xsp:expr>
      </content>
    </page>
  </xsp:page>
  
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/samples/forms/countryselector_form.xml
  
  Index: countryselector_form.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  <!-- form used to illustrate programmatic changing of listbox content via the 
flow model -->
  <wd:form
    xmlns:wd="http://apache.org/cocoon/woody/definition/1.0";
    xmlns:i18n="http://apache.org/cocoon/i18n/2.1";>
  
        <wd:widgets>
        
          <wd:field id="us-nonus" required="true">
            <wd:label>Residence:</wd:label>
            <wd:datatype base="string"/>
            <wd:selection-list>
              <wd:item value="">
                <wd:label>Select where you live</wd:label>
              </wd:item>
              <wd:item value="us">
                <wd:label>In the U.S. of America</wd:label>
              </wd:item>
              <wd:item value="non-us">
                <wd:label>Outside the U.S. of America</wd:label>
              </wd:item>
            </wd:selection-list>
            <wd:on-value-changed>
              <javascript>
                java.lang.System.err.println("Residence changed from " + 
event.oldValue + " to " + event.newValue);
                var value = event.source.value;
                var typewidget = event.source.parent.getWidget("country");
                if (value == "us") {
                  typewidget.setSelectionList(states, "key", "value");
                }
                else if (value == "non-us") {
                typewidget.setSelectionList(countries, "key", "value");
              }
              else {
                      // Reset the value (will clear validation error)
                      event.source.setValue(null);
                      // Set an empty selection list
                      typewidget.setSelectionList(new 
Packages.org.apache.cocoon.woody.datatype.EmptySelectionList("Select a maker 
first"));
                }
                // Always set the type value to null. Note that it will also 
fire an event on the "type"
                // widget if it already had a value.
                typewidget.setValue(null);
              </javascript>
            </wd:on-value-changed>
          </wd:field>
        
          <wd:field id="country" required="true">
            <wd:label>State/Country:</wd:label>
            <wd:datatype base="string"/>
            <wd:selection-list>
              <wd:item value="">
                <wd:label>Select U.S./non-U.S. first</wd:label>
              </wd:item>
            </wd:selection-list>
            <wd:on-value-changed>
              <javascript>
                var value = event.source.value;
                if (value != null) {
                  event.source.parent.getWidget("message").setValue("So you 
live in  " + value + " ?");
                } else {
                  // Reset value
                  event.source.value = null;
                }
              </javascript>
            </wd:on-value-changed>
          </wd:field>
        
          <wd:output id="message">
            <wd:datatype base="string"/>
          </wd:output>
  
        </wd:widgets>
  </wd:form>
  
  
  
  1.7       +18 -0     
cocoon-2.1/src/blocks/woody/samples/flow/woody_flow_example.js
  
  Index: woody_flow_example.js
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/woody/samples/flow/woody_flow_example.js,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- woody_flow_example.js     25 Sep 2003 17:37:30 -0000      1.6
  +++ woody_flow_example.js     3 Nov 2003 23:17:41 -0000       1.7
  @@ -37,6 +37,24 @@
       cocoon.sendPage("carselector-success");
   }
   
  +var states = [
  +    { key: "AL", value: "Alabama" },
  +    { key: "AK", value: "Alaska" },
  +    { key: "WY", value: "Wyoming" }
  +];
  +
  +var countries = [
  +    { key: "ad", value: "Andorra, Principality of" },
  +    { key: "zw", value: "Zimbabwe" }
  +];
  +
  +function selectCountry() {
  +    var form = new Form("forms/countryselector_form.xml");
  +    form.showForm("countryselector-view");
  +    cocoon.request.setAttribute("countryselectorform", form.getWidget());
  +    cocoon.sendPage("countryselector-success");
  +}
  +
   function determineLocale() {
       var localeParam = cocoon.request.get("locale");
       if (localeParam != null && localeParam.length > 0) {
  
  
  
  1.22      +47 -0     cocoon-2.1/src/blocks/woody/samples/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/samples/sitemap.xmap,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- sitemap.xmap      1 Nov 2003 11:25:54 -0000       1.21
  +++ sitemap.xmap      3 Nov 2003 23:17:41 -0000       1.22
  @@ -343,6 +343,53 @@
          </map:transform>
          <map:serialize/>
        </map:match>
  +
  +     <!--
  +         | Country selector sample.
  +         -->
  +
  +     <map:match pattern="countryselector">
  +       <map:select type="request-method">
  +         <map:when test="GET">
  +           <map:call function="selectCountry"/>
  +         </map:when>
  +         <map:when test="POST">
  +           <map:call continuation="{request-param:continuation-id}"/>
  +         </map:when>
  +         <map:otherwise>
  +           <!-- todo: do something here -->
  +         </map:otherwise>
  +       </map:select>
  +     </map:match>
  +     
  +     <map:match pattern="countryselector-view">
  +       <map:generate src="forms/countryselector_template.xml"/>
  +       <map:transform type="woody"/>
  +       <map:transform type="i18n">
  +         <map:parameter name="locale" value="en-US"/>
  +       </map:transform>
  +       <map:transform 
src="context://samples/common/style/xsl/html/simple-page2html.xsl">
  +         <map:parameter name="contextPath" value="{request:contextPath}"/>
  +         <map:parameter name="servletPath" value="{request:servletPath}"/>
  +         <map:parameter name="sitemapURI" value="{request:sitemapURI}"/>
  +         <map:parameter name="file" value="forms/registration_success.xsp"/>
  +         <map:parameter name="remove" value="{0}"/>
  +       </map:transform>
  +       <map:transform src="resources/woody-samples-styling.xsl"/>
  +       <map:serialize/>
  +     </map:match>
  +     
  +     <map:match pattern="countryselector-success">
  +       <map:generate type="serverpages" 
src="forms/countryselector_success.xsp"/>
  +       <map:transform 
src="context://samples/common/style/xsl/html/simple-page2html.xsl">
  +         <map:parameter name="contextPath" value="{request:contextPath}"/>
  +         <map:parameter name="servletPath" value="{request:servletPath}"/>
  +         <map:parameter name="sitemapURI" value="{request:sitemapURI}"/>
  +         <map:parameter name="file" value="forms/registration_success.xsp"/>
  +         <map:parameter name="remove" value="{0}"/>
  +       </map:transform>
  +       <map:serialize/>
  +     </map:match>
        
        <map:match pattern="resources/**">
          <map:read src="{0}"/>
  
  
  

Reply via email to