You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Johan Compagner <jc...@j-com.nl> on 2001/03/16 13:50:21 UTC

BeanMessage Tag proposal

Hi,

When setting the args (arg0,arg1,arg2,arg3,arg4)
you must do this:
<bean:message key="foo.foo.foo" arg0="foo1" arg1="foo2"/>

But i think it is very rare that you know exactly at design time of the jsp
what value there must be. Because if you do then why not set it directly in
the message it self?

So it is almost any time a runtime expression.
But then i must do things like this:

<bean:define id="argstring1" value="totalautotheft"/>
<bean:define id="argstring2" value="autotheft"/>
<bean:define id="insurance" name="carinsurance" scope="session"
type="nl.topicus.thema.DynamicForm"/>
<bean:message key="prompt.advise.wacasco" arg0="<%=
insurance.getProperty(argstring1).toString() %>" arg1="<%=
insurance.getProperty(argstring2).toString() %>"/>


I must define
	<bean:define id="argstring1" value="totalautotheft"/>
because i can't do this:
	<bean:message arg0="<%= insurance.getProperty("totalautotheft").toString()
%>"

I find this a bug of the Tomcat parser if you ask me. Because if he sees
that it is a reqexpr (<%=)
then it should first find the %> before looking at the closing "!!

Because if these problems i wanted to find a solution
Why is is not possible that i get the Object[] from a name/property???
Then the BeanTag is also not limmited to only 5 args

My example for the above one:

<app:message key="prompt.advise.wacasco" (arg)name="insurance"
(arg)property="wacascoObjects"/>

and the insurance.getWacascoObjects() does return the Object[] for that
string:
object[0] = insurance.getProperty("totalautotheft");
object[1] = insurance.getProperty("autotheft");
return object;

Johan Compagner












Re: BeanMessage Tag proposal

Posted by Michael Westbay <we...@seaple.icc.ne.jp>.
Compagner-san wrote:

> When setting the args (arg0,arg1,arg2,arg3,arg4)
> you must do this:
> <bean:message key="foo.foo.foo" arg0="foo1" arg1="foo2"/>
>
> [...snip...]
>
> <bean:message key="prompt.advise.wacasco" arg0="<%=
> insurance.getProperty(argstring1).toString() %>" arg1="<%=
> insurance.getProperty(argstring2).toString() %>"/>
> 
> 
> I must define
> 	<bean:define id="argstring1" value="totalautotheft"/>
> because i can't do this:
> 	<bean:message arg0="<%= insurance.getProperty("totalautotheft").toString()
> %>"

This is exactly the problem that Pellow-san addressed with his sub-tag extentions in his message dated Wed, 14 Mar 2001 11:40:40 +1100, titled "Re: BaseFieldTag."

Yes, you will need to create your own BaseAttributeTags, but this is a very powerful method to do exactly what you want to do.

Take the above example.  It can be rewritten:

  <bean:message key="prompt.advise.wacasco">
    <bean:arg index="0"><bean:write name="insurance"
              property="totalautotheft"/></bean:arg>
    <bean:arg index="1"><bean:write name="insurance"
              property="whatever"/></bean:arg>
  </bean:message>

The bean tag will have to implement an interface that sets arg(s), the work will have to be moved from doBeginTag to doEndTag, and a ArgTag will have to be created in the light of Pellow-san's Name tag.  The changes necessary are all pretty simple.  I'm now working on creating all of my custom tags in that fassion.

Note:  The bean tag does not currently work like this.  This would be a way to extend it to cater to your needs.  We're all developers on the -dev list, right?

Hope this helps.

--
Michael Westbay
Work: Beacon-IT http://www.beacon-it.co.jp/
Home:           http://www.seaple.icc.ne.jp/~westbay
Commentary:     http://www.japanesebaseball.com/

RE: BeanMessage Tag proposal

Posted by Michael Hackett <mh...@pictorius.com>.
Johan Compagner <jc...@j-com.nl> wrote:
> because i can't do this:
> 	<bean:message arg0="<%=
> insurance.getProperty("totalautotheft").toString()
> %>"
>
> I find this a bug of the Tomcat parser if you ask me. Because
> if he sees that it is a reqexpr (<%=)
> then it should first find the %> before looking at the closing "!!

Is it the quotes inside quotes that are messing you up? Try single
quotes around the <%= %> expression, like this:

<bean:write name="editForm"
  property='<%= "components[" + index + "].description" %>'/>

That's straight out of one of my pages and it works fine. A pain, I
admit, but it works. I think I also saw a suggestion when searching the
struts-user list yesterday about leaving off the outer quotes entirely,
but that will probably only work if your result string has no spaces.
(For property, it has to, so that one's probably safe.)

However, the idea of having subtags defining or supplementing tag
attributes, which Michael Westbay mentioned, sounds very appealing. I've
often wanted to use a <bean:write> in a tag argument, but instead had to
move the value into a Java variable and use "<%= %>" for the tag
attribute. Being able to specify certain attributes, like values and
property names in subtag bodies would solve that nicely.

--
Michael Hackett
Developer, Pictorius Inc.