AgileApps Support Wiki Pre Release

Difference between revisions of "Pages"

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
Line 314: Line 314:
====Search based on Lastname====
====Search based on Lastname====


This example performs a search action in a lookup window based on "Lastname" as the [[Record_Locator#Record_Identifier_Fields|Record Identifier Field in Record Locator]]:
This example performs a search action in a lookup window based on "Lastname" as the [[Record Identifier]]:


Add a Page:
Add a Page:
Line 330: Line 330:
#Use this file name: <tt>AccountPopupController.java</tt>
#Use this file name: <tt>AccountPopupController.java</tt>
#Use this code sample: [[AccountPopupController.java]]
#Use this code sample: [[AccountPopupController.java]]


====Search based on multiple fields====
====Search based on multiple fields====

Revision as of 22:47, 26 July 2011

Designer > Logic > Pages

A Page is a standard JSP page (JavaServer Page). It can be used to create highly customized user interface elements as well as completely independent tabs.

Learn more: Pages in the Developer Suite

In most cases, a page communicates with a worker class through a controller class. For details, see Working with Pages and Classes.

Lock-tiny.gif

Users that have the Customize Objects permission can add, edit or delete pages 

1 Designing Pages

Use HTML to create the look you want, you use a variety of dynamic display-and-interaction technologies to create the feel you want:

  • Use Java APIs to access and interact with the platform.
  • Use features from the jQuery library (javascript components, stylesheets, themes, effects, etc).
  • Add your own JavaScript code for forms and other options.
  • Use AJAX and REST to communicate with the platform in JavaScript code.
  • Upload other javascript libraries and CSS files as Static Resources and reference them in your JSP pages.

2 Using APIs

In general, the Java APIs and REST APIs provide equivalent functionality. But there are some differences, as well. So while the Java APIs are generally more convenient to use in a JSP page, you may also want to review the functionality listed in the REST API CheatSheet.

The following Java API classes are implicitly imported into pages:

Other considerations:

  • You cannot make a database connection. (Use the Java Record Handling APIs, instead.)
  • By default, the maximum number of loop iterations is 10000. (The actual value, along with other restrictions, are set using platform Governors.)

3 Managing Pages

Pages can be Added, Edited or Deleted. Before editing, a page must be checked out (Checkout), and should be checked in (Commit) after Editing.

3.1 Add a Page

To add a page:

  1. Click Designer > Logic > Pages
  2. Click the [New Page] button, and complete the following information:
    Title
    Enter a title for the page
    *.jsp extension is required
    Display with Tab Header
    Checkbox
    If checked, display the page with a tab header
  3. Enter the code in the text area
  4. Click [Save]

3.2 Edit a Page

Before editing a page, the page must be checked out. To edit a page:

  1. Click Designer > Logic > Pages
  2. Click the name of the page to edit
  3. Click the [Edit] button
  4. Edit the code in the text area
  5. Click [Save]

3.3 Checkout a Page

Before editing a page, the page must be checked out.

Learn more: Version Control

To checkout a page:

  1. Click Designer > Logic > Pages
  2. Click the name of the page to edit
  3. Click the [Checkout] button

The following actions can be taken on a page that is checked out:

  • Edit
  • Delete
  • Commit
  • Back (Cancel)

The following information is displayed when a page is checked out:

Page Information
Title
pagetitle.jsp
Display with Tab Header
Yes
Version Information
Version
4
Locked
No
Last Commit By
Elaine Yoder
Last Commit Date
01/13/2010 10:55 AM
Last Checkout By
Elaine Yoder
Last Checkout Date

3.4 Commit a Page

After editing a page, the changes should be committed to the working copy. To commit a page:

  1. After editing a page, click [Save]
  2. Click [Commit]
    The Item Type and Name cannot be modified
    Add Comments about the changes
    The following Commit Details are displayed:
    Item Type
    Page
    Item Name
    pagename.jsp
    Comment
    Description of the changes to the page
  3. Click [Save]

3.5 Delete a Page

To delete a page:

  1. Click Designer > Logic > Pages
  2. Click the name of the page to delete
  3. Click the [Delete] button to continue

4 Managing Pages in Eclipse

Use the Eclipse Plug-In to add, edit, and delete pages.

5 Invoking a Page from an Action

  1. Click Designer > Data > Objects.
  2. Click an object
  3. Click the Actions tab
  4. Click the [Add Action] button
  5. Enter a title
  6. Specify Invoke Custom Page as the Type
  7. Select a page you have defined
  8. Click [Save]

6 Invoking a Page from a URL

If you have written your page in a way that does not require a controller to display it, you can directly invoke it using:

https://www.longjump.com/networking/pages/MyJSP.jsp

If your page depends on a controller to display it, you can use this type of URL:

https://www.longjump.com/networking/controller/com/platform/{namespace}/{package}/MyService?action=doSomething

where com.platform.{namespace}.{package}.MyService is a class that implements the Controller interface and action is a parameter that you can use in the controller.

For more about controllers, see see Working with Pages and Classes.

7 Advanced Techniques

7.1 Create a Tab using Pages

See Web Tabs for information on creating tabs using pages.

7.2 Use Static Resources in Pages

See Static Resources for information on how to load image files, stylesheets, JavaScript files or compressed files as Page resources.

7.3 Share Common Libraries

The standard technique for including common libraries is to create a JSP that references them, for example, common.JSP, and then include that page in every other page:

<syntaxhighlight lang="java" enclose="div">

<%@ include file="/pages/common.JSP"%> </syntaxhighlight> A new library can then be added to every page, simply by adding it common.JSP.

8 Print Templates Using Pages

Print templates in pages can be used to print records in any object. See Print Templates for an overview of print templates in the user interface.

Examples

  • Create an Expense Report to be used in expense management application
  • Print an Employee Benefit Form

Using print templates in pages is a two-step process:

  1. Create a Page that includes the desired print formatting
  2. Create a Print Template using a Page as the template type

8.1 Create a Page

  1. Click Designer > Logic > Pages
  2. Click the [New Page] button
  3. Click the [Edit] Button
  4. Enter a Title (filename) for the print template; Include .jsp as the file extension
  5. Uncheck the Display with Tab Header checkbox
  6. Add appropriate code, as shown in the next section.
  7. Click [Save]

8.2 Get Object and Record ID from the Request Object

When a JSP Page is launched from a context that is associated with a particular object record, the request object available in the JSP page contains the identifiers needed to obtain additional information from the record, using either the REST record Resource or the Java record handling APIs.

To get all of the parameters available in the request object, and their values:

<syntaxhighlight lang="java" enclose="div">

<%

 String[] params = request.getParameterValues();
 for (int i=0; i<params.length; i++)
 {
   String paramName = params[i];
   String paramValue = request.getParameter( paramName );
 }

%> </syntaxhighlight>

To obtain a record identifier from a request object sent by the platform:

With the object ID and record ID, use the getRecord API to retrieve the record.
<syntaxhighlight lang="java" enclose="div">

<%

 String object_id = request.getParameter("object_id");
 String record_id = request.getParameter("record_id");

%> </syntaxhighlight>

Notepad.png

Note: Although the object_id is alphanumeric, it can be used in any API that requires an object name.

To obtain a record identifier from a request object sent by a Custom Action button:

This code gets the record IDs and uses the searchRecords API to retrieve the records:
<syntaxhighlight lang="java" enclose="div">

<%

 // Get the object ID and the comma separated list of record IDs
 String object_id = request.getParameter("object_id");
 String selectedRecords = request.getParameter("selectedRecords"); 
 // Break the comma-separated list into record IDs. 
 // Join them with "OR" operands for use when searching for the records
 String filterCriteria = "";
 if (selectedRecords != null)
 {
   StringTokenizer st = new StringTokenizer(selectedRecords,",");
   while (st.hasMoreTokens())
   {
     if ( !"".equals(filterCriteria.trim()))
     {
        // Criteria string isn't empty, and we're adding another expression
        // Prefix the new expression with a boolean OR operator
        filterCriteria += " OR "
     }
     filterCriteria += "record_id = "+ st.nextToken();
   }
 }
 // Use the filter criteria to fetch the selected records
 // Here, we ask for the record_id and name fields
 Result results;
 results = Functions.searchRecords(object_id , "record_id,name", filterCriteria);
 int resultCode = results.getCode();
 if (resultCode < 0)
 {
    // Error occurred
 }
 else if (resultCode == 0)
 {
   // No records found. (This situation should never occur.)
 }
 else
 {
   // Records retrieved successfully
   // Process them here
   ParametersIterator iterator = results.getIterator();
   while(iterator.hasNext())
   {
     Parameters params = iterator.next();
     String recordID = params.get("record_id");
     String recordName = params.get("name");
     // Take additional action according to your business logic
   }
 }

%> </syntaxhighlight>

8.3 Create a Print Template

This print template uses Page as the type of template, instead of HTML

  1. Click Designer > Data > Objects > {object}
  2. Add a new Print Template, select Page type and select the .jsp print template file

9 Example: Add a Contact using a Page and a Class

This example describes how to Add a Contact using a Page and Class.

9.1 Create a Page

  1. To create a page, follow the instructions at Adding a Page
  2. Copy and paste the following code into the page, and name it AddContact.jsp

<syntaxhighlight lang="java" enclose="div">


<body>

<form name = "mainForm" action="/networking/controller/com/platform/demo/samples/AddContact" method="POST">

</body> </html> </syntaxhighlight>
<LABEL for="addFirstName"> First Name: </LABEL> <INPUT type="text" id="addFirstName" name="addFirstName" value="CPFirst">
<LABEL for="addLastName"> Last Name: </LABEL> <INPUT type="text" id="addLastName" name="addLastName" value="CPLast">
<INPUT type="submit" value="Add"> <INPUT type="reset">
   </form>

9.2 Create a Class

  1. To create a class, follow the instructions at Adding a Class
  2. Copy and paste the following code into the class, and name it AddContact
<syntaxhighlight lang="java" enclose="div">

import java.util.*; import com.platform.api.*;


public class AddContact implements Controller {

 public ControllerResponse execute(HashMap params) throws Exception
 {
     String action = (String)params.get("action");
     if(action == null || action.equals(""))
     {
         Functions.debug("Action - null?");            
         action = "Add";
     }
     if(action.equals("Add"))
     {
          Functions.debug("Action - not null?" + action);
          return addContact(params);
     }
     else
     {
                             
     }
     return null;
 }
 private ControllerResponse addContact(HashMap params) 
   throws Exception
 {
     ControllerResponse cr = new ControllerResponse();
     Result result = null;
                               
     try
     {
       Parameters addOptions = Functions.getParametersInstance();
       addOptions.add("object_id", "CONTACT");
       String addFirstName = (String)params.get("addFirstName");
                   
       String addLastName = (String)params.get("addLastName");
                           
       if(addLastName != null && !addLastName.equals("") 
             && addFirstName != null && !addFirstName.equals(""))
       {
           addOptions.add("first_name", addFirstName);
                     
           addOptions.add("last_name", addLastName);
       }
       else
       {
          addOptions.add("first_name", "CPfirst"+new Date());
          addOptions.add("last_name", "CPLast" + new Date());
          addOptions.add("account_id", "1593373443");
       } 
       result = Functions.addRecord("CONTACT", addOptions);
       Functions.debug("Message:" + result.getMessage());
       cr.setData(result);
       cr.setTargetPage("AddContact.jsp");
     }
     catch(Exception e)
     {
        cr.setTargetPage("AddContact.jsp");
        cr.setMessage(e.getMessage());
               
        Functions.debug("Message:");          
     }
     return cr;
 }

} </syntaxhighlight>

Now the page is ready to be invoked from browser or web tab.

10 Pages in Lookup Fields

Lookup fields can be based on Pages, which display customized Lookup Windows. These pages are launched in the usual way, with the lookup Lookupicon.gif icon, from within a record.

When a Lookup Window search is successful, these parameters are used to identify and return Lookup Fields in Pages:

Paramter Name Description
object_id Object Type Identifier
keyword String value, entered by the user in the lookup field.

If the user types ABC in the lookup field, then the keyword is ABC.

target_field Used to store the Record Id
target_name_field Used to store the contents of the field (text string format, contents of the field)
The Lookup Field is rendered using two HTML elements:
  • target_field
  • target_name_field
See the .jsp sample code files for more information.
Considerations

10.1 Lookup Examples

10.1.1 Search based on Lastname

This example performs a search action in a lookup window based on "Lastname" as the Record Identifier:

Add a Page:

  1. From the Account object, Add a Page
  2. Use this file name: AccountPopup.jsp
  3. Use this code sample: AccountPopup.jsp

Add a AccountPopup.java Class:

  1. From the Account object, Add a Class
  2. Use this file name: AccountPopup.java
  3. Use this code sample: AccountPopup.java

Add a AccountPopupController.java Class:

  1. From the Account object, Add a Class
  2. Use this file name: AccountPopupController.java
  3. Use this code sample: AccountPopupController.java

10.1.2 Search based on multiple fields

This example performs a search action in a lookup window using Multiple Fields in the Record Locator:

Prerequisite: In the Directory object, define the Record Identifier fields to include "First name" and "Last name".

Add a Page
  1. From the Directory object, Add a Page
  2. Use this file name: DirectoryPopup.jsp
  3. Use this code sample: DirectoryPopup.jsp
Add a DirectoryPopup.java Class
  1. From the Directory object, Add a Class
  2. Use this file name: DirectoryPopup.java
  3. Use this code sample: DirectoryPopup.java
Add a DirectoryPopupController.java Class
  1. From the Directory object, Add a Class
  2. Use this file name: DirectoryPopupController.java
  3. Use this code sample: DirectoryPopupController.java

10.2 Multiple Fields in the Record Locator

If the Record Identifier is a combination fields, then it must be created by concatenating the field names.

For example, the record locator for the Employee object is a combination of First name, Last name. Then the record locator value is formed as: [First name value][space][-][space][Last name value]

First name Last Name Record Locator Value
John Smith John - Smith
Peter Peter -
Jones - Jones