Method Builder

 

In this topic ...

Quick Tips

Specifying Inputs

Related Topics ...

Writing Methods

Working with XML

Processing Form Submissions

Getting and Setting Variable Values

Executing Model Actions

Generating URLs to Model Actions

Getting System Properties

Interacting with the Session

Interacting with the HTTP Request and Response

WebSphere Portlet Factory API Javadoc

The Method builder adds a Java method to the WebApp. When you regenerate or save the model, the Factory servlet creates a Java class that includes all of the Method builder calls in the model. When you run the model, the Factory servlet instantiates an object of the generated class and calls the methods on that generated object.

Use the Method builder when you want to:

  • Allow the method inputs or body to be profiled

  • Make simple calls to display pages, call methods, or execute service calls

For larger, more complex methods, you should create a Java class and the methods in a Java editor and add a Linked Java Object (LJO) builder call to your model that refers to that Java class.

See the WebSphere Portlet Factory API Javadoc for complete information about the objects and methods we can access and call when writing methods.

 

Quick Tips

  • Double-check your Java syntax in an IDE -- If you are writing an involved method, or are unsure if your syntax will compile, copy the syntax for the method into a "scratch" Java source file in your IDE and try compiling the "scratch" class.

  • Profiling method builder call inputs -- When you profile the inputs to a Method builder call, the Factory servlet generates a separate class file to the WEB-INF/work/source/genjava directory for each profile-specific implementation of the method. For example, if you profiled the Body input to the Method builder call and set the value for the Body text for two profiles, the Factory servlet generates two Java source files in the WEB-INF/work/source/genjava directory: ModelName_Profile1.java and ModelName_Profile2.java.

  • Importing classes -- The following guidelines describe the Method builder's behavior with regard to importing classes:

  • If the method requires imports and you do not specify the classes needed in the Method's Imports List value, the Java code will not compile.

  • If you add the correct classes to import, the Java code will recompile and succeed.

  • If the Method's Imports List value is removed or modified in any way, this change is not picked up.

As a result, even though the new method code does not compile, the method appears to succeed because the generated class is cached.

 

Specifying Inputs

The Method builder takes the inputs described in the table below. For help on inputs common to many or all builders such as those in the Properties and HTML Attributes input groups, see "Using the Builder Call Editor."

Input name Description
Name Enter a name for this builder call. The designer tool displays this name in the builder call list.
(optional) Arguments Array (Name, Type) Enter a name and type for each argument you want to create for the method.
Body Enter the Java code for the method. You do need to begin your code with an open curly brace "{" and a close curly brace "}".
Return Type Enter the return type for the object that the method returns (if any). Possible values include: void, String, IXml, boolean, etc.
(optional) Imports List Add any import statements for any Java classes that we need to use in your method. For example,

java.io.*

Overwriting
Rename Existing This input is useful in cases where you want to change the behavior of code that was placed in the WebApp by a high-level builder or by an Imported Model.

For example, you might want to do this if you have a Domino View & Form builder in your model, and you want to use a different class for one of the LJO's that Builder adds to the WebApp. The Domino View and Form Builder does not provide an "LJO Class Name" input. But, we can place a new LJO Builder in the model and give it the same name as that assigned by the Domino View and From Builder, thus replacing the existing LJO and specifying new class.

  • Enable - When checked, this input will cause the Builder to replace an existing WebApp object with a new object. The Builder will locate the existing WebApp object (variable, LJO, etc.), rename it, and then create a replacement object.

This input is available on the following low-level Builders that create WebApp objects: Action List, Imported Page, Linked Java Object, Linked Model, Method, Method Call, Page, Variable and Schema.