Eric Martin » Java http://www.ericmmartin.com Wed, 20 Jan 2010 23:54:21 +0000 http://wordpress.org/?v=2.8.6 en hourly 1 Struts 2 ParametersInterceptor http://www.ericmmartin.com/struts-2-parametersinterceptor/ http://www.ericmmartin.com/struts-2-parametersinterceptor/#comments Sat, 05 Apr 2008 15:47:28 +0000 Eric Martin http://www.ericmmartin.com/?p=39 Are your logs being filled up with errors like:

ERROR - ParametersInterceptor.setParameters(204) | ParametersInterceptor - [setParameters]: Unexpected Exception caught setting '_' on 'class com.company.web.MyAction: Error setting expression '_' with value '[Ljava.lang.String;@1491ddc'

If so, it's because Struts 2 is parsing the query string/post data and trying to "set" a value for each parameter it finds.

I'm working on an Struts 2 application utilizing the jQuery JavaScript library for the UI and the Displaytag tag library for displaying tables.

With jQuery, I'm using the "no-cache" option (cache: false) on all Ajax calls, which adds "_=timestamp" to each request. Since I don't have a property called "_" in my Action class, I get an error (mentioned above) in my logs for each request.

Same with Displaytag, except the parameters causing errors are in the form of "d-#-X", where "#" is a unique id (usually 4 or 5 digits) and "X" is either p, s or o. They are used to determine the page (p) and/or the table sort order (o for asc/desc and s for which column).

The solution: configure Struts (struts.xml) to ignore these parameters:

<interceptors>
   <interceptor-stack name="defaultStack">
      <interceptor-ref name="params">
         <!--
            Excludes the jQuery no-cache _ parameter and
            the Displaytag d-#-X parameter(s)
         -->
         <param name="excludeParams">
            _,d-\d+?-[sop]
         </param>
      </interceptor-ref>
   </interceptor-stack>
</interceptors>

If you have a different parameters that are causing problems, just put them in the excludeParams node, comma separating multiple parameters.

]]>
http://www.ericmmartin.com/struts-2-parametersinterceptor/feed/ 5
Struts 2 bug – s:submit tag type=button rendering http://www.ericmmartin.com/struts-2-bug-submit-button-tag-rendering/ http://www.ericmmartin.com/struts-2-bug-submit-button-tag-rendering/#comments Thu, 29 Nov 2007 04:29:30 +0000 Eric Martin http://www.ericmmartin.com/struts-2-bug-ssubmit-tag-typebutton-does-not-render-properly/ In Struts 2.0.11, the s:submit tag with type=button does not render properly.

While working on a project using Struts 2, I was attempting to create a HTML button that looked something like:

<button type="button" class="button positive save">
    <img src="/images/tick.png" alt="Save"> Save
</button>

I followed the Struts 2 Tag Reference for the submit tag and tried the following:

<s:submit type="button" cssClass="button positive save">
    <img src="/images/tick.png" alt="Save"> Save
</s:submit>

Instead of rendering like my example above, it looks like:

<img src="/images/tick.png" alt="Save"> Save
<button type="submit" id="test_0" value="Submit" class="button positive save">Submit</button>

Not exactly what I had in mind... ;)


At first I thought that I was just doing something wrong, so I posed a question on the mailing list. Then after searching the list some more, I found that this was, in fact, a bug and that it had been previously reported and supposedly fixed.

I checked out the Struts 2 core project and started looking around in the code. I posted some of my thoughts and ended up creating a patch that added a new s:button tag.

Struts tries to render the button tag using the same code that is used to render the input tag. The two tags share a lot in common, however, there are some important differences between them. Mainly, the input tag does not have a body and uses its value attribute for its label, whereas the button tag must have a body, which is what is used as its label. Unless you required name/value information to be sent for the button, there is no need to include either of those attributes on the button tag.

It will be interesting to see if my patch is used...either way, it was fun to dig into the Struts code and it was a good learning experience.

]]>
http://www.ericmmartin.com/struts-2-bug-submit-button-tag-rendering/feed/ 1