6202009 - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

6202009

Description:

6/10/09. 1. Dynamic Struts Forms. By Sharad Acharya. Cabela's Inc. 6/10/09. 2. Prerequisite. Basic understanding of Struts architecture is required. ... – PowerPoint PPT presentation

Number of Views:284
Avg rating:3.0/5.0
Slides: 28
Provided by: sharada5
Category:
Tags: cabelas

less

Transcript and Presenter's Notes

Title: 6202009


1
Dynamic Struts Forms
  • By Sharad Acharya
  • Cabelas Inc

2
Prerequisite
  • Basic understanding of Struts architecture is
    required.
  • Understanding of following J2EE elements is
    expected but not required
  • Java Server Pages
  • Servlet

3
Goals
  • Discuss and differentiate
  • Action form
  • Dyna action form
  • Map/List backed action form
  • Demonstrate working example of Map backed action
    forms

4
Struts
  • Web development framework
  • Popular trioM-V-C (architecture pattern)
  • Model Action Forms
  • View Java Server Pages
  • Controller Action Servlet

5
Struts benefits
  • Framework
  • Free
  • Active developer community
  • Vendor support

6
Struts liabilities
  • Learning curve
  • Complex
  • Stiff

7
Struts MVC
  • Action Form Model
  • (hold application data)
  • Java Server Page View
  • (process request and generate response)
  • Action Servlet Controller
  • (orchestrate execution)

8
Action Form
  • Attached to a Struts action
  • Encapsulates application data
  • Exposes properties with getters/setters
  • JSP field ? Action Form property
  • Matching HTML form properties are automatically
    populated from request

9
Action Form in action
type"AddressForm" / n-mappings typeAddressAction" name" addressForm "
ard

Name propertyname"/
valueSubmit / /
public class AddressForm extends ActionForm
String name . public String getName ()
return name public void seName
(String name) this.name name
10
Action Form
  • Implementation of Model element in MVC ()
  • One to one matching of HTML form element
  • Can be manipulated dynamically (/-)
  • Numerous attributes(-)

11
Dyna Action Form
  • Way of instructing framework to use configuration
    element for properties()
  • Avoids change in form class to add or remove
    fields ()
  • Static definitions(/-)

12
Dyna Action Form in action
type"DynaAddressForm" name"name" type"java.lang.String" /
ngs name"dynaAdrForm" path"thankyou.jsp"


Fist
Name

valueReset /
public class DynaAddressForm extends
DynaActionForm //overridden methods not
shown
13
Dyna Action Form
  • Form properties are externalized()
  • Form class is lean and clean()
  • Adding/removing fields involves change only in
    configuration element ()
  • Huge configuration file (-)
  • Error prone(-)
  • Fields can not be included/excluded dynamically(-)

14
Dynamic Form
  • List or Map backed
  • Can be manipulated before rendering()
  • A top level list or map holds rendering
    information
  • Suitable to present extremely dynamic contents()

15
Dynamic Form
  • Dynamically modifiable form fields()
  • Cleaner Form class and struts configuration
    file()
  • Form properties depend on type of collection(-)

16
A Mini Application
17
Starting Up
name"indexAction" type"form.IndexForm /
n path"/index" type"action.IndexAction"
name"indexAction" path"/address.jsp" /
Click next
to enter address

18
Setting the Map
public class IndexAction extends Action public
ActionForward execute( ActionMapping
mapping, ActionForm form, HttpServletRequest
request, HttpServletResponse response) throws
Exception request.getSession().setAttribute( "ma
p.address",mockBusinessCall()) return
mapping.findForward("success") private Map
mockBusinessCall() Map m new
LinkedHashMap() m.put("Name","John
Doe") m.put("Street","1 Wake Forest
Road") m.put("City","Raleigh") m.put("State","NC
") m.put("Zip","27604") return m
Click next
to enter address

type"action.IndexAction" name"indexAction" orward name"success" path"/address.jsp"
/
19
Displaying the Map Contents
Please enter your address action"address" id"myAddressMap" name"addressAction"
property"fields" id"addressMapKey" name"myAddressMap"
property"key / / "





public class DynamicAddressForm extends
ActionForm Map fields new LinkedHashMap() pub
lic void reset(ActionMapping arg0,
HttpServletRequest arg1) Map addressMap
(Map)arg1.getSession().getAttribute("map.address")
if(fields.isEmpty())fields.putAll(addressMap)
public Map getFields() return fields public
void setFields(Map map) fields map
type"form.DynamicAddressForm/
type"action.DynamicAddressAction" name"success" path"/thankyou.jsp" /
20
Editing Form Fields
public class DynamicAddressAction extends Action
public ActionForward execute( ActionMapping
mapping, ActionForm form, HttpServletRequest
request, HttpServletResponse response) throws
Exception DynamicAddressForm f
(DynamicAddressForm )form Map addressmap
(Map)f.getFields() return mapping.findForward("s
uccess")
type"action.DynamicAddressAction" name"success" path"/thankyou.jsp" /
21
Populating
Here are your information id"myAddressMap" name"addressAction"
property"fields" name"myAddressMap" property"key"/ name"myAddressMap" property"value"/
giciterate
Thank you.
22
Environments
  • WebSphere Application Developer (WSAD)
    Integration Edition version 5.1.1
  • WSAD 5.1.1 test environment
  • J2EE version 1.3
  • Struts 1.1

23
Known Use (1/2)
  • Harleysville Insurance (www.harleysvillegroup.com)
  • ProblemCommercial Auto application
  • Extremely dynamic content based on
  • TransactionQuote, Endorse, Inquiry
  • User roleAgents, In-houses
  • Line of BusinessAuto, Business owners

24
Known Use (2/2)
  • Harleysville Insurance (www.harleysvillegroup.com)
  • SolutionMap and List backed forms
  • Presentation layer calls business layer methods
  • Applying rules, business layer returns data
  • Forms populated using returned data
  • Presentation layer renders using such forms

25
References
  • Official Struts page
  • http//struts.apache.org
  • JavaPro online article
  • Part 1 http//www.fawcette.com/javapro/2003_11/on
    line/dynamic_sacharya_11_11_03/
  • Part 2 http//www.fawcette.com/javapro/2003_11/on
    line/dynamic_sacharya_11_17_03/

26
Feedback
  • QA on this presentation
  • Future communications
  • s.acharya_at_computer.org

27
Thank You!
  • Thank you for your participation.
  • Hope to see you in future!
Write a Comment
User Comments (0)
About PowerShow.com