Viewlet Framework: Creating a JSP-only Viewlet
To add a JSP-only Viewlet to an InfoGrid application, the following steps need to be performed:
- Decide on a fully-qualified name for the new Viewlet, using the reverse domain name convention as it is common for Java classes. For example, com.example.viewlet.CustomerViewlet.
- Decide on the exact criteria which types of MeshObject can be rendered by this Viewlet. For example, it may apply to any MeshObject of type com.example.models.CustomerModel/Customer, or only to a MeshObject of type com.example.models.CustomerModel/Customer whose com.example.models.CustomerModel/Customer_Balance is less than $10 while it is also related to at least one MeshObject of type com.example.models.CustomerModel/Order.
- Determine which other Viewlets this Viewlet may compete with, and decide which of them should be the default.
- In your application's ViewletFactory, encode your rule, e.g.:
if( subject.isBlessedBy( CustomerModelSubjectArea.CUSTOMER )) { ret.add( DefaultJspViewlet.choice( "com.example.viewlet.CustomerViewlet", ViewletFactoryChoice.GOOD_MATCH_QUALITY )); } - Create the JSP file with name /v/com/example/viewlet/CustomerViewlet.jsp that contains the JSP code to run when the Viewlet is run.
Within the JSP file, the following variables are pre-defined:
| Variable | Description |
| lid-appcontext | The application context, e.g. whether this is the main window or a popup. May be null. |
| Subject | The MeshObject whose URL was accessed. Always provided. |
| Viewlet | Instance of the subtype of Viewlet that backs this JSP file. Here, this is an instance of DefaultJspViewlet. Always provided. |
| ViewletState | The desired JeeViewletState. May be null. |
| ViewletStateTransition | The desired JeeViewletStateTransition. May be null. |
See also:
- Creating a custom Viewlet
- Source code to MeshWorld
- ViewletFramework.
