HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Integrating and Mapping a Web Application MVC Pattern"
Vol. 6, Issue 10, p. 30

	


 Listing 1 

public UserForm extends ActionForm { 
private String user = null; 
private String address = null; 

public getUser() { .. } 
public setuser() { .. } 
.. 
.. 

public ActionErrors validate (ActionMapping mapping, 
HttpServletRequest req) 
{ 
  ActionErrors errors = new ActionErrors(); 
  If (user == null || user.length() < 1) 
   { 
Errors.add("user", new ActionError("error.user.required")); 
  } 
  .. 
  .. 
  return errors; 
} 
} 


 Listing 2 

  <!-- Importing the tag strut tag libraries --> 
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> 
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> 

.. 
.. 

<html:form action="/SaveUserAction" focus="user"> 
<table border="0" width="100%"> 

   <tr> 
     <th align="right"> 
       <bean:message key="prompt.username"/> 
     </th> 
     <td align="left"> 
       <html:text property="user" size="16" maxlength="16"/> 
     </td> 
   </tr> 

   <tr> 
     <th align="right"> 
       <bean:message key="prompt.address"/> 
     </th> 
     <td align="left"> 
       <html:text property="address" size="16" maxlength="16"/> 
     </td> 
   </tr> 

   <tr> 
     <td align="right"> 
       <html:submit property="submit" value="Submit"/> 
     </td> 
     <td align="left"> 
       <html:reset/> 
     </td> 
   </tr> 

</table> 

</html:form> 
.. 
.. 
 Listing 3 

  public final class SaveUserAction extends Action { 
Public ActionForward perform(ActionMapping mapping, 
ActionForm form, 
HttpServletRequest req, 
HttpServletResponse res ) throws 
IOException, 

ServletException { 
ActionForward forward = null; 

UserForm userForm = (UserForm) form; 

UserDelegate userDelegate = new UserDelegate(); 

try { 
userDelegate( userForm ); 
} catch ( DelegateException e) { 
forward = mapping.findForward("failure"); 
} finally { 
if (forward == null) { 
forward = mapping.findForward("success"); 
} 
} 
return forward; 
} 


 Listing 4 

  <action-mapping> 
<action 
path="/SaveUser" 
type="com.demo.SaveUserAction" 
name="userForm" 
scope="request"/> 
<forward name="success" path="/saveSuccessful.jsp"/> 
<forward name="failure" path="/saveFailed.jsp"/> 
</action-mapping> 

 Listing 5 

  if ( childCascadeUpdate ) 
{ 
    BigDecimal addValue = new BigDecimal("0"); 
    BigDecimal subValue = new BigDecimal("0"); 
    BigDecimal delta    = new BigDecimal("0"); 

    if ((this.getInvoiceStatus()).equals("B")) 
    { 
     addValue = getTotalFinalFee(); 
    } 
    if ((this.getOldInvoiceStatus()).equals("B")) 
    { 
     subValue = getOldTotalFinalFee(); 
    } 
    delta = addValue.subtract(subValue); 
    if ( ! delta.equals(new BigDecimal("0")) ) 
    { 
     if ( !newParent.isInitialized() ) 
        newParent.setDataObject(this.getAccount()); 

     if ( ! newParent.isObjNull() ) 
   newParent.getDataObject().setAdjust("TotalBilled",delta, true); 
        } 
    } 
    return; 
} 

  
 
 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.