Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Tip

Visit Stuts 2 Documentation for the official project documentation

...

Table of Contents
minLevel2
maxLevel2
printablefalse

...

Best practices

Should I make an action or rather link to a .jsp page ?

If you put an action configuration in your xwork.xml but don't put an action class attribute, it will default to using the ActionSupport class, which just returns SUCCESS.

...

Steps to get Struts2 sample applications to work with java 1.4.x:

Type conversion

Type conversion for a static inner class ?

Collection_inner property name = your.package.ClassName$StaticInnerClassName (notice the dollar sign between the fully qualified Class name and the static inner class)

...

How to disable Velocity template caching

The "wwclass" was the resource loader I need to change.
Here's the lines from Velocity.props:

...

How to catch Freemarker exceptions (the ugly big yellow pages)

FreeMarker delegates exception handling to so-called TemplateExceptionHandlers. By default the HTML_DEBUG_HANDLER is used (this one generates the yellow error page), but you can easily specify a different exception handler by using the setTemplateExceptionHandler method of your configuration object. FM provides some simple handlers you can use, in your case I recommend the RETHROW_HANDLER (
http://freemarker.org/docs/api/freemarker/template/TemplateExceptionHandler.html).

My s:include actions aren't processed

Did you declare the s tag library in your includes ? If I'm not mistaken, jsp includes work different from struts tags includes (struts tags process the pages before including them).

I'm using s:urlHelper in combination with the c:out tag, but it won't work !

if the url with &amp is used in the value attribute it will not work properly unless the escapeXml is set to false.

...

This interceptor will grab the query string from the request before the forward occurs and put it under the query string servlet attribute as defined in the 2.4 servlet spec. This interceptor should have no affect on other servlet containers.

See https://issues.apache.org/struts/browse/WW-1563Image Removed for more details.

...

How to disable validation on the first page load (to show a in input form)?

If you define your own stack you can exclude methods from validation by adding the excludeMethods param to both Validation and Workflow. Assuming you are using the defaultStack the the methods input, back and cancel will be ignored. Change default to action!input and declare the input method to return INPUT.

When using clientside validation, DWR states it gets No Data From Server

...

How to disable validation on any given method?

use 

@SkipValidation tag on the method.

 

ex:

Code Block

 @SkipValidation
public String logout() {...} 

 When using clientside validation, DWR states it gets No Data From Server

When using firefox if a user has focus on an input control and then clicks the submit button i get a DWR error stating that there was no data from the server.
I searched around on this group and did not see a solution. Via the DWR mailing list I found a post fromi Joe Walker stating that a workaround was to register a custom DWR error handler ..
http://getahead.ltd.uk/dwr/browser/engine/errors

Why can't I use && (=and) in my validation rules ? || (=or) does work !

You can't use && directly since the validation files have to be wellformed xml. The correct syntax would be &amp ;&amp ; (without the spaces)

Validation on individual methods

To use validation on a specific method in an action you need to call your validation file

ActionClassName-ActionName-validation.xml

Where ActionName is the value matching the name attribute of the action in the action config. Wildcard methods treats / (slashes) as - (dashes). Here is an example, if we wanted to validate only the method dir/myMethod: -

Code Block

<action name="dir/*" class="com.actions.MyAction" method="{1}">
...

We would call the validation file MyAction-dir-myMethod-validation.xml. This is because ActionClassName is MyAction and ActionName is dir/myMethod, but the / is mapped to - so it becomes dir-myMethod.

Ajax, Javascript

Datepicker i18n problems

DatePicker might have some problems in certain localised enviroments, because some of the language files included in DHTML / JavaScript Calendar are not valid (don't have some variables, for example WEEKEND definition).

...

Already fixed for 2.2.1, available via CVS HEAD:

  • sv
  • pl
  • cn

Datepicker does not allow time editing, or works with wrong date format

The trick is to format the date correctly before sending it to the datepicker, AND telling the datepicker what format you are using.

...

S2 hot-redeployment problem with Tomcat 5.5

Try to adjust your Tomcat context settings...

...

Deploying Struts/WebWork on Glassfish

One of my co-workers was deploying a forum application that uses WebWork code. He ran into some deployment and execution issues, related to the sercurity policy. If you want to deploy WebWork apps on GlassFish, you may want to read http://blogs.sun.com/roller/page/paulsen?entry=configuring_the_security_manager_in

...

Different version of a browser co-existing together

Integration

Spring Security

...