You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Bill Lynch <bi...@jivesoftware.com> on 2002/06/17 01:08:36 UTC

LookupDispatchAction comments

All,

I've been reading through Chuck Cavaness's excellent online book and I came
across a section about the LookupDispatchAction class in Chapter 5 (page
26). As I understand it, the LookupDispatchAction class uses the value of a
specified parameter to determine what method of a specified Action will be
called. My question is - isn't this problematic with internationalized
content? For example, if the value of my submit button is "Add Item To Cart"
(keyed from "add.item.cart"), and if the user is using a Japanese locale,
the value of the submit button will have non-ascii characters in it. I
believe for a GET, all URLs have to be in the ASCII format, so the value
received from the submit button will be different that the value from the
resource bundle. Is this really the case? I'm not sure if browsers will do
an ASCII encoding.

I ask because I noticed this in one of my apps (a non-struts app -- for
now). Specifically, I noticed that if you have multiple submit buttons on an
HTML page:

<input type="submit" name="foo1" value="Bar 1">
<input type="submit" name="foo2" value="Bar 2">
<input type="submit" name="foo3" value="Bar 3">

If the user clicks the foo2 button, only that submit button is included in
the URL:

site.com/app?foo2=Bar%202&param1=value1....

So instead of using the same name for all 3 submit buttons I use different
ones then check for the existence of them in the request:

boolean isFoo1 = request.getParameter("foo1") != null;
boolean isFoo2 = request.getParameter("foo2") != null;
...

This works regardless of the value of the foo1 button. (I don't know if this
is true across all browsers but it works in Netscape/Mozilla & IE.

Any comments?

Sorry if this has been asked before.

Cheers,
--Bill


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: LookupDispatchAction comments

Posted by Bill Lynch <bi...@jivesoftware.com>.
Erik,

> > Right, it was the reverse lookup using the text that I thought
> would fail
> > with internationalized values (like Japanese text). The value from the
> > submit button (a parameter) will be different than the value in the
> resource
> > bundle file because the browser won't submit the non-ascii text. In that
> > case, the lookup will fail. Have you ever noticed this to be a problem?
>
> Ah, I see what you mean.  If the browser does not send what matches the
> resource file, then there is definitely a problem that
> LookupDispatchAction
> can do nothing about.

Yep, that's it exactly. And you're right, the way LDA works there's nothing
it can do about it, save some JavaScript hackery.

You might want to mention this caveat in the javadocs since developers
should consider it if their site is internationalized.

Thanks for your time,
--Bill


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: LookupDispatchAction comments

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
----- Original Message -----
From: "Bill Lynch" <bi...@jivesoftware.com>

> Right, it was the reverse lookup using the text that I thought would fail
> with internationalized values (like Japanese text). The value from the
> submit button (a parameter) will be different than the value in the
resource
> bundle file because the browser won't submit the non-ascii text. In that
> case, the lookup will fail. Have you ever noticed this to be a problem?

Ah, I see what you mean.  If the browser does not send what matches the
resource file, then there is definitely a problem that LookupDispatchAction
can do nothing about.

I've not seen this as I do not currently work on localized applications,
everything has been English.

    Erik



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: LookupDispatchAction comments

Posted by Bill Lynch <bi...@jivesoftware.com>.
Erik,

Thanks for the explanations - comments below:

> > called. My question is - isn't this problematic with internationalized
> > content? For example, if the value of my submit button is "Add Item To
> Cart"
> > (keyed from "add.item.cart"), and if the user is using a
> Japanese locale,
> > the value of the submit button will have non-ascii characters in it.
>
> LDA uses the key, not the text.  It uses the text to reverse
> lookup the key,
> since submitting a button submits its text.

Right, it was the reverse lookup using the text that I thought would fail
with internationalized values (like Japanese text). The value from the
submit button (a parameter) will be different than the value in the resource
bundle file because the browser won't submit the non-ascii text. In that
case, the lookup will fail. Have you ever noticed this to be a problem?

> > I ask because I noticed this in one of my apps (a non-struts app -- for
> > now). Specifically, I noticed that if you have multiple submit
> buttons on
> an
> > HTML page:
> >
> > <input type="submit" name="foo1" value="Bar 1">
> > <input type="submit" name="foo2" value="Bar 2">
> > <input type="submit" name="foo3" value="Bar 3">
> >
> > So instead of using the same name for all 3 submit buttons I
> use different
> > ones then check for the existence of them in the request:
> >
> > boolean isFoo1 = request.getParameter("foo1") != null;
> > boolean isFoo2 = request.getParameter("foo2") != null;
>
> Yup, you could easily do this in Struts yourself, although I don't believe
> there is anything built-in to handle this any cleaner than the code you
> provided.

Cool, thanks.

> My reservation about LookupDispatchAction comes after seeing it abused in
> the project I created it for.  It was designed for situations
> where a single
> form is submitted by multiple buttons.  But lots of "screen" in our system
> have multiple buttons, yet not all buttons need to submit a form.  Folks
> have coded actions that use LDA when it was unnecessary, and this
> causes the
> system to be confusing to work with as the "controller" moves
> down into the
> actions to a large extent.  I would highly recommend against using LDA
> unless you really need it.  Its a hammer for a very specific
> nail, and works
> great in those cases.  Use it when not needed and you're only asking for
> headaches or confusion later.

That's kinda what I thought. Thanks for the info!

Regards,
--Bill


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: LookupDispatchAction comments

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
LookupDispatchAction (LDA) was my creation and so I'll respond....

----- Original Message -----
From: "Bill Lynch" <bi...@jivesoftware.com>
> called. My question is - isn't this problematic with internationalized
> content? For example, if the value of my submit button is "Add Item To
Cart"
> (keyed from "add.item.cart"), and if the user is using a Japanese locale,
> the value of the submit button will have non-ascii characters in it.

LDA uses the key, not the text.  It uses the text to reverse lookup the key,
since submitting a button submits its text.

> I ask because I noticed this in one of my apps (a non-struts app -- for
> now). Specifically, I noticed that if you have multiple submit buttons on
an
> HTML page:
>
> <input type="submit" name="foo1" value="Bar 1">
> <input type="submit" name="foo2" value="Bar 2">
> <input type="submit" name="foo3" value="Bar 3">
>
> So instead of using the same name for all 3 submit buttons I use different
> ones then check for the existence of them in the request:
>
> boolean isFoo1 = request.getParameter("foo1") != null;
> boolean isFoo2 = request.getParameter("foo2") != null;

Yup, you could easily do this in Struts yourself, although I don't believe
there is anything built-in to handle this any cleaner than the code you
provided.

The nice thing about LDA is you simply code the key/method mappings, and the
methods you want invoked.

> This works regardless of the value of the foo1 button. (I don't know if
this
> is true across all browsers but it works in Netscape/Mozilla & IE.

It would work across all browsers.  There is nothing wrong with doing it
your way.

My reservation about LookupDispatchAction comes after seeing it abused in
the project I created it for.  It was designed for situations where a single
form is submitted by multiple buttons.  But lots of "screen" in our system
have multiple buttons, yet not all buttons need to submit a form.  Folks
have coded actions that use LDA when it was unnecessary, and this causes the
system to be confusing to work with as the "controller" moves down into the
actions to a large extent.  I would highly recommend against using LDA
unless you really need it.  Its a hammer for a very specific nail, and works
great in those cases.  Use it when not needed and you're only asking for
headaches or confusion later.

    Erik



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>