The handleActionBean tag 

Overview 

Category

initialise() behaviour

execute() behaviour

Fetcher

·         Do nothing

·         Check that sufficient data has been supplied to get the data (normally primary key of data to load). If not throw a FatalException.

·         Fetch the required data and make it available via getters. Throwing a FatalException if there is a problem.

Adder

·         Initialise the bean with suitable default data.

·         Validate the data on the bean, throwing a ValidationException if invalid data is found.

·         Try and add the data throwing a DuplicateDataException or ActionBeanException if there is a problem.

Updater

·         Check that sufficient data has been supplied to get the data (normally primary key of data to load). If not throw a FatalException.

·         Fetch the required data and make it available via getters. Throwing a FatalException if there is a problem.

·         Validate the data on the bean, throwing a ValidationException if invalid data is found.

·         Try and update the data throwing a DuplicateDataException, ConcurrencyException or ActionBeanException if there is a problem.

Deleter

·         Check that sufficient data has been supplied to get the data (normally primary key of data to load). If not throw a FatalException.

·         Fetch the required data and make it available via getters. Throwing a FatalException if there is a problem.

·         Try and delete the data throwing a ConcurrencyException or ActionBeanException if there is a problem.

Tag Usage 

This tag has the following usage: 

<jee:handleActionBean name="beanInstanceName" result=" script var. name for error bean"
[executeOn="parameter to execute on"]
[redirectUrl="url to redirect to after successful execute"] />

name – The name of the bean to work with. This bean must implement the ActionBean interface.

result – This is the name scripting variable to which the action bean error bean is bound. See Constants & JavaBeans section.

executeOn – The name of execute parameter. If this parameter is not null in the request object, then the tag calls the execute() method on the specified bean. Otherwise it calls the initialise() method. If this value is not set for the tag, the tag will always call the execute() method on the specified bean, when the tag processed.

redirectUrl – This is the URL to which the users browser is redirected to after the execute() method is successfully called.

Example 

The following code shows an example of using this tag: 

<%@ taglib uri="jeenius" prefix="jee" %>
<jsp:useBean id="cd" class="example.CDUpdater" scope="session"/> <jee:setAllProperties name="cd"/>   <jee:handleActionBean name="cd" result="error" executeOn="btnOk" redirectUrl="view_cds.jsp" />   <html>
 <head>
   <title>Update CD</title>
 </head>
 <body>
  <p>Make changes to the data as required and click on the
     <i>Ok</i> button.
  </p>
  <p><jsp:getProperty name="error" property="message"/></p>   <p>
  <form method="POST">
   <input type="hidden" name="id" value="<jsp:getProperty    name="cd" property="id"/>">       ID: <jsp:getProperty name="cd" property="id"/><br>      Title: <input type="text" name="title" size="20"
   value="<jsp:getProperty name="cd" property="title"/>"><br>      Artist: <input type="text" name="artist" size="20"
   value="<jsp:getProperty name="cd" property="artist"/>"><br>      <input type="submit" name="btnOk" value="Ok">
  </form>
  </p>
 </body>
</html>
If this page was named update_cd.jsp then it could be called using /update_cd.jsp?id=123456. This would display the update CD page displaying the data for the CD with and ID of 123456.