Archive for ‘Software Development’

Struts 2 ParametersInterceptor

Saturday, April 5th, 2008

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.

SimpleModal Contact Form (SMCF) 1.1 Released

Thursday, March 13th, 2008

SMCF 1.1 includes the following changes:

  • Fixed image pre-loading to actually pre-load ;)
  • Added new effects on form open and close
  • Added a security feature
  • Added optional subject and cc sender form elements
  • Added common classes to form elements
  • Renamed all classes and ID’s to prevent collisions
  • Added WordPress translation ability on text elements (__() and _e() functions)
  • Upgraded to SimpleModal v1.1.1 and jQuery 1.2.3
  • Moved SimpleModal and SMCF JavaScript file loading to the footer

For more information and the download, please visit the SMCF WordPress Plugin Page.

SimpleModal Contact Form (SMCF) 1.0 Released

Sunday, January 6th, 2008

SimpleModal Contact Form (SMCF) is an Ajax powered modal dialog contact form for WordPress.

The project and all of the information about it is hosted on WordPress.org.

If you have any feedback regarding the plugin, please let me know.

SimpleModal v1.1 Released

Friday, January 4th, 2008

There are three new options and the handling of data has been revamped. For more details, including documentation, demos, tests and downloads, visit the project page.

I’m finishing up a WordPress plugin based on SimpleModal, which should be ready soon. The Contact link above is powered by the new WordPress plugin.

jQuery bug - Ajax ‘no-cache’ parameter

Monday, December 3rd, 2007

In jQuery 1.2.1, when using the $.ajax function with cache: false, jQuery appends a parameter with the current timestamp to the URL. This parameter makes the URL unique and therefore prevents subsequent request from being retrieved from the browser cache.

However, the code that adds this ‘no-cache’ parameter does not check to see if it already exists and so under certain circumstances you can end up with URL’s that look like:

http://mysite.com/file.html?_=1196716041523&_=1196716462963&_=1196716464245

It certainly makes the URL unique :)

I opened a ticket and submitted a patch, which was quickly optimized by a jQuery developer, davidserduke.

It’s nice to see a project with responsive, helpful developers.

Comparison of JavaScript compression methods

Friday, November 30th, 2007

While creating the build system for our Java web application, I set out to do some benchmarking on some of the different JavaScript compression methods. When our project builds, I configured our Ant build script to create three different version of our JavaScript files; full source, minified (comments and whitespace removed), and packed (compressed).

I also configured Tomcat to use gzip compression and then ran six different test, the three version of our JavaScript files without gzip compression and the three versions with gzip compression.

I measured the load time and size using FireBug from within Firefox and recorded the following results:

Full Source Minified Packed
Without GZIP 167 KB | 329ms 95 KB | 281ms 70 KB | 313ms
With GZIP 67 KB | 297ms 48 KB | 219ms 47 KB | 312ms

Although my “tests” are very informal, I think that it is clear that the minified version with GZIP server compression offers the best results. It is only slightly larger than the packed version in size, but it loads almost 30% faster (due to the overhead of decompressing the packed version).

Struts 2 bug - s:submit tag type=button rendering

Wednesday, November 28th, 2007

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… ;)

Read the rest of this entry »

Conditional page/post navigation links in WordPress (redux)

Monday, November 19th, 2007

After more helpful input, I’ve decided to update my original solution.

Instead of overriding four WordPress functions and adding two new ones in my functions.php file, I have slimmed it down to just one:

/**
 * If more than one page exists, return TRUE.
 */
function show_posts_nav() {
	global $wp_query;
	return ($wp_query->max_num_pages > 1) ? TRUE : FALSE;
}

This function will tell me if there is more than one page…and if there is, I will show the posts navigation (next_posts_link and previous_posts_link). I updated my WordPress (index.php, archives.php and search.php) files with:

<?php if (show_posts_nav()) : ?>
<div class='navigation'>
	<span class='older'><?php next_posts_link('&laquo; Older Entries'); ?></span>
	<span class='newer'><?php previous_posts_link('Newer Entries &raquo;'); ?></span>
</div>
<?php endif; ?>

As for the single post next/previous links, I decided to remove the check because I’ll always have more than one entry.

Much cleaner and less code ;)