You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jo...@apache.org on 2004/02/18 20:58:17 UTC

cvs commit: cocoon-2.1/src/blocks/ojb/samples/woody employee.js employee.xml employee_template.xml success.xsp

joerg       2004/02/18 11:58:17

  Modified:    src/blocks/ojb/samples/woody employee.js employee.xml
                        employee_template.xml success.xsp
  Log:
  extended the sample so that you can see the values from the database
  
  Revision  Changes    Path
  1.11      +8 -9      cocoon-2.1/src/blocks/ojb/samples/woody/employee.js
  
  Index: employee.js
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/ojb/samples/woody/employee.js,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- employee.js	16 Feb 2004 19:49:00 -0000	1.10
  +++ employee.js	18 Feb 2004 19:58:17 -0000	1.11
  @@ -1,16 +1,15 @@
   cocoon.load("resource://org/apache/cocoon/woody/flow/javascript/woody2.js");
   
   function employeeform_jdo(form) {
  -
  -	// Get OJB factory
  -   	var factory = cocoon.getComponent(Packages.org.apache.cocoon.ojb.jdo.components.JdoPMF.ROLE);
  +    // Get OJB factory
  +    var factory = cocoon.getComponent(Packages.org.apache.cocoon.ojb.jdo.components.JdoPMF.ROLE);
   
       // Create a empty Bean
       var bean = new Packages.org.apache.cocoon.ojb.samples.bean.Employee();
       var dao = new Packages.org.apache.cocoon.ojb.samples.EmployeeDAO();
   
  -	// Fill some initial data to the bean
  -	bean.setId(1);
  +    // Fill some initial data to the bean
  +    bean.setId(1);
       // Load bean based on the given PrimaryKey
       dao.retrieve(bean, factory);
   
  @@ -19,12 +18,12 @@
       // Let woody handle the form
       form.showForm("jdo/woody/employee-form-display");
       // Update the Bean based on user input
  -	form.save(bean);
  +    form.save(bean);
   
       // Update Bean in Database
  -	dao.update(bean, factory);
  -	// Clean up the operation
  -	cocoon.releaseComponent(factory);
  +    dao.update(bean, factory);
  +    // Release the factory
  +    cocoon.releaseComponent(factory);
   
       // Send response to the user
       cocoon.request.setAttribute("employeeform", form.getWidget());
  
  
  
  1.6       +12 -25    cocoon-2.1/src/blocks/ojb/samples/woody/employee.xml
  
  Index: employee.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/ojb/samples/woody/employee.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- employee.xml	28 Nov 2003 17:37:33 -0000	1.5
  +++ employee.xml	18 Feb 2004 19:58:17 -0000	1.6
  @@ -49,39 +49,26 @@
    Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
    Software Foundation, please see <http://www.apache.org/>.
   -->
  +<wd:form xmlns:wd="http://apache.org/cocoon/woody/definition/1.0" xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
   
  -<!--
  - * Employee Definition
  - *
  - * @author <a href="mailto:antonio@apache.org>Antonio Gallardo</a>
  - * @version CVS $Revision$ $Date$
  --->
  -<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="id" required="true">
  -        <wd:label>ID :</wd:label>
  -        <wd:datatype base="integer">
  -        <!-- <wd:validation>
  -                <wd:range min="20"/>
  -            </wd:validation> -->
  -        </wd:datatype>
  +      <wd:label>ID</wd:label>
  +      <wd:datatype base="integer"/>
       </wd:field>
   
       <wd:field id="name" required="true">
  -        <wd:label>Name :</wd:label>
  -        <wd:datatype base="string">
  -            <wd:validation>
  -                <wd:length min="5"/>
  -            </wd:validation>
  -        </wd:datatype>
  +      <wd:label>Name</wd:label>
  +      <wd:datatype base="string">
  +        <wd:validation>
  +          <wd:length min="5"/>
  +        </wd:validation>
  +      </wd:datatype>
       </wd:field>
   
       <wd:field id="department_id">
  -        <wd:label>deparment ID :</wd:label>
  -        <wd:datatype base="integer">
  -        </wd:datatype>
  +      <wd:label>Department ID</wd:label>
  +      <wd:datatype base="integer"/>
       </wd:field>
     </wd:widgets>
   
  
  
  
  1.2       +5 -5      cocoon-2.1/src/blocks/ojb/samples/woody/employee_template.xml
  
  Index: employee_template.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/ojb/samples/woody/employee_template.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- employee_template.xml	28 Sep 2003 04:31:11 -0000	1.1
  +++ employee_template.xml	18 Feb 2004 19:58:17 -0000	1.2
  @@ -60,9 +60,9 @@
     <title>Employee</title>
     <content>
       <wt:form-template action="#{$continuation/id}.continue" method="POST">
  -        <wt:widget-label id="id"/><wt:widget id="id"/><br/><br/>
  -        <wt:widget-label id="name"/><wt:widget id="name"/><br/><br/>
  -        <wt:widget-label id="department_id"/><wt:widget id="department_id"/><br/><br/>
  +        <wt:widget-label id="id"/>: <wt:widget id="id"/><br/><br/>
  +        <wt:widget-label id="name"/>: <wt:widget id="name"/><br/><br/>
  +        <wt:widget-label id="department_id"/>: <wt:widget id="department_id"/><br/><br/>
           <input type="submit"/>
       </wt:form-template>
     </content>
  
  
  
  1.3       +53 -21    cocoon-2.1/src/blocks/ojb/samples/woody/success.xsp
  
  Index: success.xsp
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/ojb/samples/woody/success.xsp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- success.xsp	16 Feb 2004 19:49:00 -0000	1.2
  +++ success.xsp	18 Feb 2004 19:58:17 -0000	1.3
  @@ -1,25 +1,57 @@
   <?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>employee form result</title>
  -        <content>
  -            <xsp:logic>
  -                Form form = (Form)request.getAttribute("employeeform");
  -                Field fid = (Field)form.getWidget("id");
  -                Field fname = (Field)form.getWidget("name");
  -                Field fdepartment_id = (Field)form.getWidget("department_id");
  -            </xsp:logic>
  -
  -            id:<xsp:expr>fid.getValue()</xsp:expr>
  -            <br/>
  -            Name:<xsp:expr>fname.getValue()</xsp:expr>
  -            <br/>
  -            Department id:<xsp:expr>fdepartment_id.getValue()</xsp:expr>
  -        </content>
  -    </page>
  +  <xsp:structure>
  +    <xsp:include>org.apache.cocoon.ojb.jdo.components.JdoPMF</xsp:include>
  +    <xsp:include>org.apache.cocoon.ojb.samples.EmployeeDAO</xsp:include>
  +    <xsp:include>org.apache.cocoon.ojb.samples.bean.Employee</xsp:include>
  +    <xsp:include>org.apache.cocoon.woody.formmodel.*</xsp:include>
  +  </xsp:structure>
  +
  +  <page>
  +    <title>Storing employee in database succeeded.</title>
  +    <content>
  +      <xsp:logic>
  +        Form form = (Form)request.getAttribute("employeeform");
  +        Field fid = (Field)form.getWidget("id");
  +        Field fname = (Field)form.getWidget("name");
  +        Field fdepartment_id = (Field)form.getWidget("department_id");
  +      </xsp:logic>
  +      <p>The values of the form:</p>
  +      ID: <xsp:expr>fid.getValue()</xsp:expr>
  +      <br/>
  +      Name: <xsp:expr>fname.getValue()</xsp:expr>
  +      <br/>
  +      Department ID: <xsp:expr>fdepartment_id.getValue()</xsp:expr>
  +
  +      <hr/>
  +
  +      <p>The values retrieved from the database:</p>
  +      <xsp:logic>
  +        JdoPMF factory = null;
  +        Employee bean = null;
  +        try {
  +            factory = (JdoPMF)manager.lookup(JdoPMF.ROLE);
  +
  +            bean = new Employee();
  +            EmployeeDAO dao = new EmployeeDAO();
  +
  +            bean.setId(((Integer)fid.getValue()).intValue());
  +            dao.retrieve(bean, factory);
  +        } catch (ComponentException ce) {
  +            throw new ProcessingException("Could not lookup JDO PersistanceManagerFactory", ce);
  +        } finally {
  +            if (factory != null) {
  +                manager.release(factory);
  +            }
  +        }
  +      </xsp:logic>
  +      ID: <xsp:expr>bean.getId()</xsp:expr>
  +      <br/>
  +      Name: <xsp:expr>bean.getName()</xsp:expr>
  +      <br/>
  +      Department ID: <xsp:expr>bean.getDepartmentId()</xsp:expr>
  +
  +    </content>
  +  </page>
   </xsp:page>