Tips for using AndroMDA bpm4struts

This section provides you with some pointers that might prove helpful when using AndroMDA with the bpm4struts cartridge.

Naming Conventions

Give good names to all the elements you model, try to give names that uniquely identify the element in its context. For example, instead of calling an action state 'login' you might consider using 'enter name and password' instead. The same goes for controllers and use-cases. The better names you give, the less ambiguity you will have in the long run.

Code Regeneration

The power of AndroMDA is apparent when you will need to apply changes to your model and regenerate the set of code files. Using bpm4struts these files comprise Java classes as well as properties files and JSPs.

You will not want to lose your changes to the generated code, to ensure this the cartridges have been designed never to overwrite the implementation classes and files. On the other hand you will most probably want to see the most recent changes in the model reflected in the code.

For classes this is not a problem because the cartridges generating them will provide you with an implementation class that will only be written when it does not yet exist. Subsequent changes during generation will be reflected automatically in the abstract parent classes. The implementation classes extending them will require a manual update.

The copy-over feature

So what about JSPs ? The most efficient and effective way of maintaining manually edited changes in JSP files seems to be to copy the generated JSPs into your source directory (and subsequently adding it to your Control Versioning System), making your changes and copying them over the generated ones prior to building the WAR bundle.

If you have generated your project build structure using andromdapp:generate you will have a section in /web/maven.xml that is commented out, it is a preGoal to war:init, just uncomment it in order to have files in /web/src/jsp copied over the existing ones in the .war bundle.

JavaScript

JavaScript can greatly improve a web application's look and feel, the bpm4struts cartridge generates a few common routines that can be used in the pages. The files containing these routines have a .js extension and can be found in the set of generated pages, typically /web/target/src/layout.

Let us know if you think more JavaScript should be added, just supply us with the ones you would like to see in there.

Dynamic Content

The Action States page explained how you can take control of the HTTP response to return anything you like back to the browser. Nice to know is that you can also use this feature to send downloadable content so the browser will prompt you with a download dialog instead of trying to render everything on screen.

Here's an example that will prompt for PDF download, notice how the preferred file name has been specified:


Validation of numbers when using Strings

Because Bpm4Struts will automatically provide validation for any modeled numeric type (i.e. a modeled datatype::Integer will be validated that the field is indeed a valid integer value) it saves you a lot of trouble right? Well, this is all great unless of course you don't want the annoying 0 that Struts likes to provide as the default when no value as been entered.

So how do you get the great default validation and yet avoid the default zero you ask? Very easy: just continue to model the parameters as a number (i.e. datatype::Integer for example), then within a customized Java mappings file for the Bpm4Struts namespace just map this number type to a java.lang.String. For example, here we add the mapping for datatype::Integer


<mappings name="Java">
    ...
    <mapping>
        <from>datatype::Integer</from>
        <to>java.lang.String</to>
    </mapping>
    ...
</mappings>

and then specify the mapping in the bpm4struts namespace, like so:

<namespace name="bpm4struts">
    <properties>
         ...
         <property name="languageMappingsUri">file:${maven.conf.dir}/mappings/JavaMappings.xml</property>
         ...
    </properties>
</namespace>

Performance

You might want to turn on the JSP precompilation feature, it will compile your JSPs into Java files and compile those into Java classes. Since this is done during the build process the Web container will not need to lose time compiling your JSP pages at runtime. Additionally you will find any compilation errors that might occur. It has shown that performance increases by a factor 10 when accessing the pages for the first time, in all other cases performance is the same.

To enable jsp precompilation simply go into your andromdapp:generate generated project, open the /web/project.properties file and make sure the precompileJsps property has been set to true.

Troubleshooting

Precompilation

In some cases it is known precompiled applications to intermittently throw exceptions on Windows machines. This is a known issue and is related to the Windows operating system not allowing file names to be longer than 255 characters. When you precompile JSPs, and the resulting classes are stored deep into the EAR, into the WAR, into the WEB-INF/classes subdirectory. Windows might not be able to properly resolve them if the fully qualified path to the file is longer than 255 characters, the path will silently be truncated and the Java VM will report it was unable to find the class.

This problem cannot be solved, but a few workarounds exist:

  • Move the deployment directory closer to the root of the drive
  • Shorten the name of the JSP page on which the loading fails
  • Explode the contents of the EAR and the WAR, this can be done automatically for you if you set the explodeOnDeploy property to true in /app/project.properties. The next time you deploy using the maven deploy goal, a directory containing everything be deployed instead of a single EAR bundle.
  • Move to a Unix-based system, such as Linux.

Compatibility

Although most applications are perfectly portable across different containers it might happen that some specific feature needs special attention.

An example is WebSphere which requires the web.xml to contain an id attribute for most elements, Resin on the other hand can get into trouble this way. This example can be configured using the generateWebXmlIds namespace property.

Bpm4Struts generates code that is compliant to the J2EE v1.4 and Struts 1.2.x specifications. You will need Java 1.4 or higher to be able to run the generated applications.