Child pages
  • Using Struts and XWork with JSP 2.0 and JSTL 1.1
Skip to end of metadata
Go to start of metadata

S2/X1 and its taglib is oriented towards OGNL, which is using a value stack
for all action properties. These values are not direct available for the
expression language of JSP2/JSTL1.1.

However, it's easy to populate the request
attribute set, with all gettable properties of an action object. You need to provide
an interceptor that does the job, by register a PreResultListener which is
invoked after the return of Action.execute() but before the rendering of the result .

The interceptor below is using Jakarta BeanUtils. It first extracts all getters
of the current action, invokes them one at the time and stores the values into a map.
Then it iterates over the map and populates the request attribute set.
The double iteration is not needed, it's just there for clarity.

class ActionPropertyExportInterceptor

Don't forget to declare the interceptor in your struts.xml file and insert it
into your interceptor stack.

struts.xml snippet

Your action need to provide getters for all properties that should be exported into the
request attribute set.

class ViewUser

The User class might look like this

class User

Finally, using the samples above you can write your JSP2 page like this.


Displaying validation errors with JSTL

  • No labels