on December 3, 2004 by pat in technology, Comments (3)

Struts LookupDispatchAction

I started investingating struts yesterday and found it somewhat frustrating. one of the things I wanted to do was have submit buttons that have the same name, but have the request handler detect which button was pressed.. clearly you can do this using javascript.. but some browsers may have javascript disabled.

The Jakarta Struts project promises this capability using their framework. One of the helper action classes was the LookupDispatchAction, but using it wasn’t as straightforward as I hoped. Essentially I wanted to create a simple forward/back wizard that would submit a post inbetween pages. The LookupDispatchAction class behaves similarly to how HTML radio buttons work, where you have a similar group name, but each property has a different value (e.g. young, old, dead). In my case, my group was called “direction” with submit values of “next”, “back”, and “cancel”

Without going through all the gory details, I’ve provided the source on how to do this. After googling around I couldn’t find any concrete samples, other than code snippets that left me wondering like, “should I still provide the execute(…) method in my LookupDispatchAction subclass because none of my direction methods were being invoked.” I kept getting errors like: “Request[/step1] does not contain handler parameter named ‘direction’. This may be caused by whitespace in the label text”

I also placed an entry in tss, without much luck.

Anyway, here’s the code. It’s the complete web application including the humongous 2Mb struts libs. (I’m using struts 1.24) I have build scripts for both tomcat 4.1x and tomcat 5.5x

3 Comments

  1. semaj

    June 19, 2007 @ 5:09 pm

    Patrick,

    Thanks for the post.

    i want to ask you some questions regarding the wizard…

    1. I removed the actionform from session when the user clicks the cancel or finish button. How can we remove it if the user does not click the buttons and navigates to some other pages?

    2. How can I prevent the user to access next step if he/she has not completed the first step?

    Any idea??

    Thanks,
    semaj

  2. patrick

    June 21, 2007 @ 2:53 pm

    Semaj,

    Regarding 1 – you’ll have to have a javascript onEvent handler

    OR

    you’ll have to modify the navigation buttons to modify the action to reflect your desired result.

    Regarding 2 – This can be done in a variety of ways using javascript, JSP, or just rely on the Struts framework event handler. I would opt for the latter. Read up on the Struts event handling.

  3. Google Me

    July 26, 2008 @ 9:25 am

    Don’t use “do” as parameter name in an action, because “do” is a reserved word in Javascript.

    In short, both:

    document.forms[0].do.value = “save”

    do not work!

Leave a comment

XHTML: Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>