Difference between revisions of "HowTo:Create a JSP Page and Java Controller"
From AgileApps Support Wiki
imported>Aeric |
imported>Aeric |
||
Line 16: | Line 16: | ||
This diagram shows how the interactions between the JSP Page and controller class take place: | This diagram shows how the interactions between the JSP Page and controller class take place: | ||
:[[File:jsp_controller_interactions.png]] | :[[File:jsp_controller_interactions.png]] | ||
::* | ::* An HTML <tt>Form</tt> designates the location to go to when a button is pressed | ||
::* The platform creates an object when the page is visited | |||
::* All contents of the form are passed to the controller as name/value pairs, in the <tt>params</tt> | |||
::: - fields that have data in them: <tt><input type="input" ...</tt> | |||
::: - hidden data fields: <tt><input type="hidden" ...</tt> | |||
::: - the button that was pressed: <tt><input type="submit" name="..." value="..." ...</tt><br>(The value is displayed as the label, and passed as the value associated with the name.) | |||
:::* The controller's <tt>execute</tt> method returns a <tt>ControllerResponse</tt> object | |||
:::* The <tt>ControllerResponse</tt> object designates the page to go to next | |||
:::* You use its <tt>setData</tt> method to load a HashMap with values to send to the page | |||
{{#if: {{ShowWhitepapers}} | | {{#if: {{ShowWhitepapers}} | | ||
''Learn more:'' | ''Learn more:'' | ||
:* [{{DOCHOST}}/training/LongJump%20Development%20101.pdf LongJump Development 101 training slides] | :* [{{DOCHOST}}/training/LongJump%20Development%20101.pdf LongJump Development 101 training slides] | ||
}} | }} | ||
==Prerequisites== | ==Prerequisites== | ||
:* A "Mailing List" object must created, with two fields: <tt>contact_name</tt> and <tt>contact_email</tt> | :* A "Mailing List" object must created, with two fields: <tt>contact_name</tt> and <tt>contact_email</tt> |
Revision as of 00:46, 3 August 2012
For: Developers See more: |
Overview
In this guide, you create a JSP Page and a Controller Class that interact to:
- Add records to a Mailing List object
- Do a SQL search for (one or more) records
- Update records
Sample Scenario
A sample interaction scenario might look like this:
-
- The arrows going to the controller show the value of the action variable that is passed from the JSP Page.
- The arrows going to the JSP Page show the value of the control variable that is passed from the controller.
- (The names of the variables are determined by convention. They could be anything.)
Communication Mechanisms
This diagram shows how the interactions between the JSP Page and controller class take place:
-
- An HTML Form designates the location to go to when a button is pressed
- The platform creates an object when the page is visited
- All contents of the form are passed to the controller as name/value pairs, in the params
- - fields that have data in them: <input type="input" ...
- - hidden data fields: <input type="hidden" ...
- - the button that was pressed: <input type="submit" name="..." value="..." ...
(The value is displayed as the label, and passed as the value associated with the name.)- The controller's execute method returns a ControllerResponse object
- The ControllerResponse object designates the page to go to next
- You use its setData method to load a HashMap with values to send to the page
Prerequisites
- A "Mailing List" object must created, with two fields: contact_name and contact_email
Developing the Application
Create the Java class
- Follow the instructions at Add a Class to create AddUpdateController_YOURNAME
- Copy and paste the contents of AddUpdateController.java into the Class
- Save the class
Create the JSP Page
- Follow the instructions at Add a Page to create AddUpdateYOURNAME.jsp
- Copy and paste the contents of AddUpdate.jsp
- Save the JSP page
Try it Out
To test the project, visit the following URL:
- https://{yourDomain}/networking/pages/AddUpdate.jsp
(A valid username and password is required to log in to the platform.)