jford       2004/04/08 20:01:02

  Added:       tutorial/xdocs/9 advanced.xml deploy.xml actions.xml
                        events.xml
  Log:
  Finished conversion of Chapter 9
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed/tutorial/xdocs/9/advanced.xml
  
  Index: advanced.xml
  ===================================================================
  <?xml version="1.0"?>
  <!--
  Copyright 2004 The Apache Software Foundation
  
  Licensed 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.
  -->
  <document>
  
    <properties>
      <author email="[EMAIL PROTECTED]">David Sean Taylor</author>
      <title>Advanced Parameters</title>
    </properties>
  
  <body>
  
  <section name="Advanced Parameters">
  
  <subsection name="Database Connection Pool">
  
  <p>
  By default, the database browser portlet uses the default Torque data source and 
connection pool. To select another connection pool,  add the <b>poolname</b> parameter 
to your portlet�s registry entry:
  </p>
  
  <p>
  <source>
  <![CDATA[
  <!-- to use an alternate torque pool, set this parameter -->
  <parameter name="poolname" value="otherpool" hidden="true"/>
  ]]>
  </source>
  </p>
  
  <p>
  The name of the pool must match the name of the data source in the 
<b>Torque.properties</b> file. 
  See the <a 
href="http://jakarta.apache.org/turbine/torque/jdbc2pool-howto.html";>Torque 
documentation</a> for details on configuring data sources.
  </p>
  
  </subsection>
  
  <subsection name="User Objects">
  
  <p>
  There may be times when you need to attach additional information to each row in the 
browser. 
  For example, you are implementing a tree view over a joined database query, and you 
need to track whether a row is expanded or contracted to show the detail lines. 
  The state of each row can be attached to the row with User Objects. 
  A user object can be any Java class. 
  The user object can also be accessed in your Velocity template.       
  </p>
  
  <p>
  The class name of the user object is specified with the <b>user-object-types</b> 
parameter,  a comma separated list of Java class names. 
  For each row in result set, a new class of this type is created and attached to the 
browser row.
  </p>
  
  <p>
  <source>
  <![CDATA[
  <parameter name="user-object-types"
  value="com.bluesunrise.jportal.modules.actions.portlets.ExampleBrowserItem" 
hidden="true"/>
  
  <parameter name="user-object-names" value="userObject" hidden="true"/>
  ]]>
  </source>
  </p>
  
  </subsection>
  
  </section>
  </body>
  </document>
  
  
  1.1                  jakarta-jetspeed/tutorial/xdocs/9/deploy.xml
  
  Index: deploy.xml
  ===================================================================
  <?xml version="1.0"?>
  <!--
  Copyright 2004 The Apache Software Foundation
  
  Licensed 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.
  -->
  <document>
  
    <properties>
      <author email="[EMAIL PROTECTED]">David Sean Taylor</author>
      <title>Deploy</title>
    </properties>
  
  <body>
  
  <section name="Deploy">
  
  <p>
  To deploy the system, type:
  </p>
  
  <p>
  <source>
  <![CDATA[
  ant deploy         (or hotdeploy) 
  ]]>
  </source>
  </p>
  
  <p>
  Use hotdeploy if you have already deployed the system once. This simply saves some 
time in packaging the JPortal deployment. Next point your browser at:
  </p>
  
  <p>
  <a 
href="http://localhost:8080/jportal/portal";>http://localhost:8080/jportal/portal</a>
  </p>
  
  <p>
  The Tutorial 9 examples are found under the "Advanced Tutorials" menu selection.
  </p>
  
  </section>
  </body>
  </document>
  
  
  1.1                  jakarta-jetspeed/tutorial/xdocs/9/actions.xml
  
  Index: actions.xml
  ===================================================================
  <?xml version="1.0"?>
  <!--
  Copyright 2004 The Apache Software Foundation
  
  Licensed 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.
  -->
  <document>
  
    <properties>
      <author email="[EMAIL PROTECTED]">David Sean Taylor</author>
      <title>Linking to Actions</title>
    </properties>
  
  <body>
  
  <section name="Linking to Actions">
  
  <p>
  Database browsers can be used in combination with edit forms to create a complete 
database maintenance portlet application. Links can be made to another pane on the 
current page, or to another page in the portal. 
  </p>
  
  <p>
  A Database Browser portlet supports row links and table links. Row links are applied 
to a particular database row in the browser. Table links are actions that do not apply 
to any particular row. Using the default template, the row links are displayed at the 
end of each row as shown here we have two links: Edit, Delete.
  </p>
  
  <p>
  <img border="0" width="553" height="49" src="../images/image056.jpg"/>
  </p>
  
  <p>
  The table links are displayed at the bottom of the portlet. Here we have one link: 
Add.
  </p>
  
  <p>
  <img border="0" width="553" height="28" src="../images/image058.jpg"/>
  </p>
  
  <p>
  Links are configured in the registry. 
  The <b>row-link-ids</b> parameter is a comma separated list of localised string ids. 
  These ids are looked up in the resource bundle, and displayed as hyperlinks. 
  The <b>row-link-types</b> determine the type of link. 
  They are also comma separated. Valid values are:
  </p>
  
  <p>
  <ul>
  <li>1. pane</li>
  <li>2. psml</li>
  </ul>
  </p>
  
  <p>
  The pane link will go to another pane in your current PSML resource. 
  Here you can place an edit form for entering the values of the selected record.
  </p>
  
  <p>
  The row-link-types specifies the name of the resource. 
  With a pane link type, it identifies the name of the pane. 
  The pane name can also be a portlet. 
  When used with the psml link type, it specifies the name of  a PSML resource.
  </p>
  
  <p>
  <source>
  <![CDATA[
  <parameter name="row-link-ids" value="EDIT,DELETE" hidden="true"/>
  
  <parameter name="row-link-types" value="pane,pane" hidden="true"/>
  
  <parameter name="row-link-targets" value="CoffeesForm,CoffeesForm"
  
             hidden="true"/>
  
  ...
  ]]>
  </source>
  </p>
  
  <p>
  To add a new record to the database, the Add link is provided using table links. 
  The <b>table-link-ids</b> parameter is a comma separated list of localised string 
ids. These ids are looked up in the resource bundle, and displayed as hyperlinks. 
  The <b>table-link-types</b> determine the type of link. They are also comma 
separated. Valid values are:
  </p>
  
  <p>
  <ul>
  <li>3. pane</li>
  <li>4. psml</li>
  </ul>
  </p>
  
  <p>
  The pane link will go to another pane in your current PSML resource. Here you can 
place an edit form for entering the values of a new record.
  </p>
  
  <p>
  The <b>table-link-types</b> specifies the name of the resource. With a pane link 
type, it identifies the name of the pane. The pane name can also be a portlet. When 
used with the psml link type, it specifies the name of  a PSML resource.
  </p>
  
  <p>
  <source>
  <![CDATA[
  <parameter name="table-link-ids" value="ADD" hidden="true"/>
  
  <parameter name="table-link-types" value="pane" hidden="true"/>
  
  <parameter name="table-link-targets" value="CoffeesForm"
  
              hidden="true"/>
  ]]>
  </source>
  </p>
  
  </section>
  </body>
  </document>
  
  
  1.1                  jakarta-jetspeed/tutorial/xdocs/9/events.xml
  
  Index: events.xml
  ===================================================================
  <?xml version="1.0"?>
  <!--
  Copyright 2004 The Apache Software Foundation
  
  Licensed 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.
  -->
  <document>
  
    <properties>
      <author email="[EMAIL PROTECTED]">David Sean Taylor</author>
      <title>Implementing the Action Events</title>
    </properties>
  
  <body>
  
  <section name="Implementing the Action Events">
  
  <p>
  The action events link to a data entry form for entering Coffee records. 
  The form supports Add, Edit and Delete modes. Here we see edit mode:
  </p>
  
  <p>
  <img border="0" width="350" height="271" src="../images/image060.jpg"/>
  </p>
  
  <p>
  This portlet is also a Velocity Portlet. Like all Velocity portlets, it has a 
templates and an action.
  </p>
  
  <p>
  <source>
  <![CDATA[
  <parameter name="template" value="coffees-form" hidden="true"/>
  
  <parameter name="action" value="portlets.TutorialCoffeesAction" />
  ]]>
  </source>
  </p>
  
  <p>
  The form posts back to itself by default.
  </p>
  
  <p>
  <source>
  <![CDATA[
  <form method="post" action="$jslink.setAction("portlets.TutorialCoffeesAction")">
  ]]>
  </source>
  </p>
  
  <p>
  An action event is connected to the button:
  </p>
  
  <p>
  <source>
  <![CDATA[
  <input type="submit" name="eventSubmit_doUpdate" value="Save"/>
  ]]>
  </source>
  Form values are entered with the standard Jetspeed data entry macros. 
  See the tutorial on <a href="../7/events.html">Action Events</a> for more 
information on programming data entry forms and with Velocity macros and input fields.
  </p>
  
  <p>
  <source>
  <![CDATA[
        <tr>
  
          #formCell ("Brand of Coffee" "coffeeName" $!coffee.CoffeeName)
  
        </tr>
  
        <tr>
  
          #formCell ("Supplier Id" "supplierId" $!coffee.SupplierId)
  
        </tr>
  
        <tr>
  
          #formCell ("Unit Price" "price" $!coffee.Price)
  
        </tr>
  
        <tr>
  
          #formCell ("Sales Tax" "sales" $!coffee.Sales)
  
        </tr>
  
        <tr>
  
          #formCell ("Total Price" "total" $!coffee.Total)
  
        </tr>
  ]]>
  </source>
  </p>
  
  <p>
  Finally we have an action event (<b>TutorialCoffeesAction</b>) that stores the row 
to the database.
  </p>
  
  <p>
  <source>
  <![CDATA[
  public void doUpdate(RunData rundata, Context context) throws Exception
  {
          Coffees coffee = null;
          Connection con = null;
  
          try
          {
              con = Torque.getConnection();
              coffee = (Coffees)rundata.getUser().getTemp(SESSION_COFFEE);
  
              if(coffee == null)
              {
                  Log.error(NO_CURRENT_REC);
                  rundata.setMessage(NO_CURRENT_REC);
                  return;
              }
  
              rundata.getParameters().setProperties(coffee);
              validate(coffee);
              coffee.save(con);
              con.commit();
  
              returnToBrowser(rundata, true);
          }
          catch (Exception e)
          {
              Log.error("error in saving coffee: " + e);
              rundata.setMessage(e.toString());
  
              if (con != null)
              {
                  con.rollback();
              }
          }
          finally
          {
              try
              {
                  Torque.closeConnection(con);
              }
              catch (Exception e)
              {}
          }
      }
  ]]>
  </source>
  </p>
  
  <p>
  The update method is used by both Add and Update modes. 
  Take note of the usage of Torque's object-relational programming model. 
  The objects can store themselves. 
  The Coffees objects were automatically generated for you as a task in the tutorials 
ant build. 
  First we get a connection:
  </p>
  
  <p>
  <source>
  <![CDATA[
  con = Torque.getConnection();
  ]]>
  </source>
  </p>
  
  <p>
  then get the object from the session, which was placed there when the link was 
clicked on from the database browser.
  </p>
  
  <p>
  <source>
  <![CDATA[
  coffee = (Coffees)rundata.getUser().getTemp(SESSION_COFFEE);
  ]]>
  </source>
  </p>
  
  <p>
  The parameter parser will automatically populate any bean, as long as the names of 
the inputs on the HTML form match (case-insensitive) the names of the properties on 
the bean.
  </p>
  
  <p>
  <source>
  <![CDATA[
  rundata.getParameters().setProperties(coffee);
  ]]>
  </source>
  </p>
  
  <p>
  We then validate and save the input, finally committing it:
  </p>
  
  <p>
  <source>
  <![CDATA[
                validate(coffee);
  
          coffee.save(con);
  
          con.commit();
  ]]>
  </source>
  </p>
  
  <p>
  If there is an error, we store the error message for later retrieval from our 
template:
  </p>
  
  <p>
  <source>
  <![CDATA[
  rundata.setMessage(e.toString());
  ]]>
  </source>
  </p>
  
  <p>
  <source>
  <![CDATA[
          #if ($data.Message)
        <tr>
          <td colspan="2">
            <table bgcolor="red">
              <tr>
                <td>
                  $data.Message
                </td>
              </tr>
            </table>
          </td>
        </tr>
        #end
  ]]>
  </source>
  </p>
  
  <p>
  Finally, we redirect to the browser on success and invalidate the browser to refresh 
and pick up the modifications:
  </p>
  
  <p>
  <source>
  <![CDATA[
     JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
     DynamicURI duri = link.getPaneByName("TutorialCoffeesBrowser");
  
     if (refresh)
     {
           duri.addQueryData(CoffeesBrowserAction.BROWSER_COMMAND, 
                      CoffeesBrowserAction.BROWSER_REFRESH);
     }
  
     rundata.setRedirectURI(duri.toString());
     JetspeedLinkFactory.putInstance(link);
  ]]>
  </source>
  </p>
  
  </section>
  </body>
  </document>
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to