You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Peter Donald <pe...@apache.org> on 2001/12/02 07:41:13 UTC
Struts integration?
Hiya,
I am using Struts for my cotroller portion and all is well. The one thing
that is painful is that Velocity doesn't have the kinda of inbuilt support
that JSP does because for all the tags that they have written (I am
specifically thinking about "form" integration).
Has anyone else done this integration before ? If so any tips or macros you
want to share ? ;)
--
Cheers,
Pete
*------------------------------------------------------*
| "Computers are useless. They can only give you |
| answers." - Pablo Picasso |
*------------------------------------------------------*
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Struts integration?
Posted by Ted Husted <hu...@apache.org>.
Struts developers put their own JavaBeans into the request and sessions
contexts, in the same way (I guess) that Velocity developers put
JavaBeans into the VelocityContext.
A Struts developer would then document to the page designer which
JavaBeans are in the context for them to use in a particular workflow.
Most often, the request context is used, which disappears after the page
is rendered, so the page designer is just retrieving JavaBeans. If
anything ever needs to be removed, the developer takes care of that.
There will be different perspectives on this depending on whether you
are approaching this from
+ Making Velocity templates available to Struts developers
versus
+ Making Struts available to Velocity developers
For the former, we will need to make using the standard servlet contexts
transparent.
For the latter, we will need to provide a Velocity context that a
developer can populate and send along.
And, I'm sure both will happen in the end ;-)
Tim Colson wrote:
>
> > > Hadn't thought of that. I was actually manually adding in 7
> > objects - namely
> > > "request" ---> HttpServletRequest
> > > "response" ---> HttpServletResponse
> > > "session" ---> HttpSession (if any)
>
> I'm going to ask naive questions...as if I'm a Designer:
>
> Why on earth would I need direct access to the request, response, or session
> objects? Handling the Request object directly sounds bad to me.
>
> When I get a javadoc on those things - they have all sorts of methods that
> seem dangerous. Ex. removeAttribute() setMaxInactiveInterval()
>
> Wouldn't it be better/simpler/safer if the Developer simply gave me the
> stuff I needed and no more? Is it just because the Developer is being lazy
> that s/he hasn't provided a simpler object (aka "wrapper") that gives me
> access to the things I need to render the page?
>
> I mean - sheesh, if I wanted to be confused and shoot myself in the foot,
> I'd stick to JSP. <grin>
>
> Food for thought,
> Timo
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: Struts integration?
Posted by Tim Colson <tc...@cisco.com>.
> > Hadn't thought of that. I was actually manually adding in 7
> objects - namely
> > "request" ---> HttpServletRequest
> > "response" ---> HttpServletResponse
> > "session" ---> HttpSession (if any)
I'm going to ask naive questions...as if I'm a Designer:
Why on earth would I need direct access to the request, response, or session
objects? Handling the Request object directly sounds bad to me.
When I get a javadoc on those things - they have all sorts of methods that
seem dangerous. Ex. removeAttribute() setMaxInactiveInterval()
Wouldn't it be better/simpler/safer if the Developer simply gave me the
stuff I needed and no more? Is it just because the Developer is being lazy
that s/he hasn't provided a simpler object (aka "wrapper") that gives me
access to the things I need to render the page?
I mean - sheesh, if I wanted to be confused and shoot myself in the foot,
I'd stick to JSP. <grin>
Food for thought,
Timo
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Struts integration?
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 12/2/01 10:57 AM, "Peter Donald" <pe...@apache.org> wrote:
> On Mon, 3 Dec 2001 00:12, Ted Husted wrote:
>> Geir started something here
>>
>> http://jakarta.apache.org/builds/jakarta-velocity/contrib/struts/
>>
>> and there's been some new discussion recently.
>>
>> http://www.mail-archive.com/velocity-user%40jakarta.apache.org/msg03970.htm
>> l
>>
>> I posted a follow up yesterday, but it hasn't made the archive yet.
>> (Wither eyebrowse ...)
>
> tah.
>
>> I was suggesting that VelServlet use a facade over the standard
>> requeset, session, and application contexts, to make them appear to be
>> VelocityContexts, and then chain them together, so that a requirst for
>> $foo goes first to the VelocityContext, then to the request facade, and
>> then to the sesssion and application. First one found wins. This would
>> mimic the default JSP and Struts tag extension behaviour.
>
> Hadn't thought of that. I was actually manually adding in 7 objects - namely
>
> "request" ---> HttpServletRequest
> "response" ---> HttpServletResponse
> "session" ---> HttpSession (if any)
>
> Adaptors for the property scopes (request, session, application). Basically
> they all implement get(String) -> getAttribute(String) mapping.
>
> Unfortunately I had to give them funny names so they wouldn't clash with the
> above names.
Why not just call the real methods?
>
>> OT, but have you been using the Excalibur DataSources package with
>> Struts?
>
> Nope. Why is there something wrong with it ? ;)
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Struts integration?
Posted by Peter Donald <pe...@apache.org>.
On Mon, 3 Dec 2001 00:12, Ted Husted wrote:
> Geir started something here
>
> http://jakarta.apache.org/builds/jakarta-velocity/contrib/struts/
>
> and there's been some new discussion recently.
>
> http://www.mail-archive.com/velocity-user%40jakarta.apache.org/msg03970.htm
>l
>
> I posted a follow up yesterday, but it hasn't made the archive yet.
> (Wither eyebrowse ...)
tah.
> I was suggesting that VelServlet use a facade over the standard
> requeset, session, and application contexts, to make them appear to be
> VelocityContexts, and then chain them together, so that a requirst for
> $foo goes first to the VelocityContext, then to the request facade, and
> then to the sesssion and application. First one found wins. This would
> mimic the default JSP and Struts tag extension behaviour.
Hadn't thought of that. I was actually manually adding in 7 objects - namely
"request" ---> HttpServletRequest
"response" ---> HttpServletResponse
"session" ---> HttpSession (if any)
Adaptors for the property scopes (request, session, application). Basically
they all implement get(String) -> getAttribute(String) mapping.
Unfortunately I had to give them funny names so they wouldn't clash with the
above names.
> OT, but have you been using the Excalibur DataSources package with
> Struts?
Nope. Why is there something wrong with it ? ;)
--
Cheers,
Pete
---------------------------------------------------
"Wise men don't need advice. Fools don't take it."
-Benjamin Franklin
---------------------------------------------------
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Struts integration?
Posted by Ted Husted <hu...@apache.org>.
Geir started something here
http://jakarta.apache.org/builds/jakarta-velocity/contrib/struts/
and there's been some new discussion recently.
http://www.mail-archive.com/velocity-user%40jakarta.apache.org/msg03970.html
I posted a follow up yesterday, but it hasn't made the archive yet.
(Wither eyebrowse ...)
I was suggesting that VelServlet use a facade over the standard
requeset, session, and application contexts, to make them appear to be
VelocityContexts, and then chain them together, so that a requirst for
$foo goes first to the VelocityContext, then to the request facade, and
then to the sesssion and application. First one found wins. This would
mimic the default JSP and Struts tag extension behaviour.
OT, but have you been using the Excalibur DataSources package with
Struts?
Peter Donald wrote:
>
> Hiya,
>
> I am using Struts for my cotroller portion and all is well. The one thing
> that is painful is that Velocity doesn't have the kinda of inbuilt support
> that JSP does because for all the tags that they have written (I am
> specifically thinking about "form" integration).
>
> Has anyone else done this integration before ? If so any tips or macros you
> want to share ? ;)
>
> --
> Cheers,
>
> Pete
>
> *------------------------------------------------------*
> | "Computers are useless. They can only give you |
> | answers." - Pablo Picasso |
> *------------------------------------------------------*
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Struts integration?
Posted by Ted Husted <hu...@apache.org>.
This is an important point; the thing to think about is why Struts has
the tag, and how the equivalent functionality is provided in Velocity.
If there any specific questions in this regard, I would be happy to
answer them. The Developers Guide on the Struts site has the best
overall explanation of why the various tags exist.
http://jakarta.apache.org/struts/index.html
The framework's job is to make resources available to other compopents,
as JavaBeans, and the tag extensions are just one way to expose these
beans to a HTML page. So, this should be a good fit with Velocity.
-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel +1 716 737-3463
-- http://www.husted.com/struts/
Bill Burton wrote:
> A couple of suggestions here. First, instead of writing a macro that
> attempts to encompass the entire functionality of the tag, write macro's
> for each attribute where it makes sense. For instance:
> #macro(checked $attr)
> #if ($attr)checked="true"#end
> #end
>
> <input type="radio" name="someAttribute" value="$form.someAttribute"
> #checked($form.someAttribute)>
>
> For other cases when you want to call some functionality using name=value
> parameters is to use a pattern such as this:
> $tags.someTagOpen(["name1=value1", "name2=value2", "name3=value3"])
> ...
> $tags.someTagClose()
>
> The someTagOpen method would be a context tool which parses the
> name=value's from the array and puts them into the context. To prevent
> scoping problems, there could be a stack on which to push and pop the
> Velocity context. The open tag would push a new VelocityContext onto the
> stack chaining the existing one then parsing and setting the parameters
> into the context. The close tag method would pop the VelocityContext off
> off the stack.
>
> > A successful Velocity/Struts integration will have to address this somehow,
> > but it's not the most urgent thing right now to get something going.
>
> Yes. However, some if this is just figuring out appropriate patterns of
> usage.
>
> -Bill
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Struts integration?
Posted by Bill Burton <bi...@progress.com>.
See below ...
Gabriel Sidler wrote:
>
> "Geir Magnusson Jr." wrote:
> [...]
> > > However I am wondering whether it is up to doing something like the followin
> > > more automagically. Currently I am hand munging it and it is ugly! ;)
> > >
> > > #set( $form = $session.getAttribute("selectServer") )
> > > <input type="radio" name="someAttribute" value="$form.someAttribute"
> > > #if( $form.someAttribute )
> > > checked="true"
> > > #end
> > >>
> > >
> > > Repeat this for 10 different input element types and it is getting painful ;)
> > > I haven't at looked at making a "radio" macro because I hoped someone else
> > > had and being lazy and all ... ;)
> >
> > Just write the Velocimaco :)
>
> The "radio" form tags supports 18 parameters, most of them optional. Other
> HTML form tags support even more parameters. A Velocimacro with a fixed
> parameter list is not really a practical solution ... leading us back
> to a discussion of last week...
A couple of suggestions here. First, instead of writing a macro that
attempts to encompass the entire functionality of the tag, write macro's
for each attribute where it makes sense. For instance:
#macro(checked $attr)
#if ($attr)checked="true"#end
#end
<input type="radio" name="someAttribute" value="$form.someAttribute"
#checked($form.someAttribute)>
For other cases when you want to call some functionality using name=value
parameters is to use a pattern such as this:
$tags.someTagOpen(["name1=value1", "name2=value2", "name3=value3"])
...
$tags.someTagClose()
The someTagOpen method would be a context tool which parses the
name=value's from the array and puts them into the context. To prevent
scoping problems, there could be a stack on which to push and pop the
Velocity context. The open tag would push a new VelocityContext onto the
stack chaining the existing one then parsing and setting the parameters
into the context. The close tag method would pop the VelocityContext off
off the stack.
> A successful Velocity/Struts integration will have to address this somehow,
> but it's not the most urgent thing right now to get something going.
Yes. However, some if this is just figuring out appropriate patterns of
usage.
-Bill
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: Struts integration?
Posted by Tim Colson <tc...@cisco.com>.
> The "radio" form tags supports 18 parameters, most of them optional. Other
> HTML form tags support even more parameters. A Velocimacro with a fixed
> parameter list is not really a practical solution ...
IMHO, this is a good example of why even the Struts HTML taglibs can be a
bit awkward because the tag has it's own params, as well as the standard
'html' params which it will pass through (if the case is correct).
For instance, the Struts <html:img> has a param 'name', but this overlaps
with the standard <img name="foo"> From the Struts dev guide:
--
name
The name of a JSP bean that contains a Map representing the query parameters
(if property is not specified), or a JSP bean whose property getter is
called to return a Map (if property is specified).
imageName
(a "runtime expression" ex. <%= foo.bleck() %> )
The scriptable name to be defined within this page, so that you can
reference it with intra-page scripts. In other words, the value specified
here will render a "name" element in the generated image tag.
--
While the Developer may understand this juxtaposition, the Designer is
mostly likely confused. No, I'll go as far as saying they are most certainly
confused. ;-)
Bill's suggestion makes a lot of sense. The crucial ideas:
1) the Designer only has to know standard HTML/WML/XML/Pig-Latin/???
2) the Designer can always refer to the macro to see the 'real output'
3) the Designer can change that macro's output (or use long hand if they
like)
<input type="radio" name="someAttribute" value="$form.someAttribute"
#checked($form.someAttribute)>
#macro(checked $attr)
#if ($attr)checked="true"#end
#end
I believe the key to building a better mousetrap is thinking like a Designer
when talking about the View and thinking like the Developers most of us are
when speaking of the 'Controller'.
Timo
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Struts integration?
Posted by Gabriel Sidler <si...@teamup.ch>.
"Geir Magnusson Jr." wrote:
[...]
> > However I am wondering whether it is up to doing something like the followin
> > more automagically. Currently I am hand munging it and it is ugly! ;)
> >
> > #set( $form = $session.getAttribute("selectServer") )
> > <input type="radio" name="someAttribute" value="$form.someAttribute"
> > #if( $form.someAttribute )
> > checked="true"
> > #end
> >>
> >
> > Repeat this for 10 different input element types and it is getting painful ;)
> > I haven't at looked at making a "radio" macro because I hoped someone else
> > had and being lazy and all ... ;)
>
> Just write the Velocimaco :)
The "radio" form tags supports 18 parameters, most of them optional. Other
HTML form tags support even more parameters. A Velocimacro with a fixed
parameter list is not really a practical solution ... leading us back
to a discussion of last week...
A successful Velocity/Struts integration will have to address this somehow,
but it's not the most urgent thing right now to get something going.
Gabe
--
Gabriel Sidler
Software Engineer, Eivycom GmbH, Zurich, Switzerland
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Struts integration?
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 12/2/01 10:50 AM, "Peter Donald" <pe...@apache.org> wrote:
> On Mon, 3 Dec 2001 00:07, Geir Magnusson Jr. wrote:
>> On 12/2/01 1:41 AM, "Peter Donald" <pe...@apache.org> wrote:
>>> Hiya,
>>>
>>> I am using Struts for my cotroller portion and all is well. The one thing
>>> that is painful is that Velocity doesn't have the kinda of inbuilt
>>> support that JSP does because for all the tags that they have written (I
>>> am specifically thinking about "form" integration).
>>
>> You need a tag to do
>>
>> <html>
>>
>> ?
>
> Yes <html> tags are one thing Velocity probably isn't up to doing - pity ;)
>
> However I am wondering whether it is up to doing something like the followin
> more automagically. Currently I am hand munging it and it is ugly! ;)
>
> #set( $form = $session.getAttribute("selectServer") )
> <input type="radio" name="someAttribute" value="$form.someAttribute"
> #if( $form.someAttribute )
> checked="true"
> #end
>>
>
> Repeat this for 10 different input element types and it is getting painful ;)
> I haven't at looked at making a "radio" macro because I hoped someone else
> had and being lazy and all ... ;)
Just write the Velocimaco :)
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
"Whoever would overthrow the liberty of a nation must begin by subduing the
freeness of speech." - Benjamin Franklin
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: Struts integration?
Posted by Donnie Hale <do...@haleonline.net>.
The recent discussions along these lines here have tended toward using some kind of Java object, invoked through a normal Velocity mechanism, to fill in fields and such; as opposed to using #macros. Not sure I agree, but the current #macro mechanism is a little limiting in supporting how that would work.
FWIW...
Donnie
-----Original Message-----
From: Peter Donald [mailto:peter@apache.org]
Sent: Sunday, December 02, 2001 10:50 AM
To: Velocity Users List
Subject: Re: Struts integration?
On Mon, 3 Dec 2001 00:07, Geir Magnusson Jr. wrote:
> On 12/2/01 1:41 AM, "Peter Donald" <pe...@apache.org> wrote:
> > Hiya,
> >
> > I am using Struts for my cotroller portion and all is well. The one thing
> > that is painful is that Velocity doesn't have the kinda of inbuilt
> > support that JSP does because for all the tags that they have written (I
> > am specifically thinking about "form" integration).
>
> You need a tag to do
>
> <html>
>
> ?
Yes <html> tags are one thing Velocity probably isn't up to doing - pity ;)
However I am wondering whether it is up to doing something like the followin
more automagically. Currently I am hand munging it and it is ugly! ;)
#set( $form = $session.getAttribute("selectServer") )
<input type="radio" name="someAttribute" value="$form.someAttribute"
#if( $form.someAttribute )
checked="true"
#end
>
Repeat this for 10 different input element types and it is getting painful ;)
I haven't at looked at making a "radio" macro because I hoped someone else
had and being lazy and all ... ;)
--
Cheers,
Pete
---------------------------------
I think not; therefore I ain't...
---------------------------------
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Struts integration?
Posted by Peter Donald <pe...@apache.org>.
On Mon, 3 Dec 2001 00:07, Geir Magnusson Jr. wrote:
> On 12/2/01 1:41 AM, "Peter Donald" <pe...@apache.org> wrote:
> > Hiya,
> >
> > I am using Struts for my cotroller portion and all is well. The one thing
> > that is painful is that Velocity doesn't have the kinda of inbuilt
> > support that JSP does because for all the tags that they have written (I
> > am specifically thinking about "form" integration).
>
> You need a tag to do
>
> <html>
>
> ?
Yes <html> tags are one thing Velocity probably isn't up to doing - pity ;)
However I am wondering whether it is up to doing something like the followin
more automagically. Currently I am hand munging it and it is ugly! ;)
#set( $form = $session.getAttribute("selectServer") )
<input type="radio" name="someAttribute" value="$form.someAttribute"
#if( $form.someAttribute )
checked="true"
#end
>
Repeat this for 10 different input element types and it is getting painful ;)
I haven't at looked at making a "radio" macro because I hoped someone else
had and being lazy and all ... ;)
--
Cheers,
Pete
---------------------------------
I think not; therefore I ain't...
---------------------------------
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Struts integration?
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 12/2/01 1:41 AM, "Peter Donald" <pe...@apache.org> wrote:
> Hiya,
>
> I am using Struts for my cotroller portion and all is well. The one thing
> that is painful is that Velocity doesn't have the kinda of inbuilt support
> that JSP does because for all the tags that they have written (I am
> specifically thinking about "form" integration).
You need a tag to do
<html>
?
:)
There is an ongoing thread regarding this subject... We are trying to do
what we can to support Struts users, although as it's so JSP oriented WRT
some of the tools, we are working out how to do it.
>
> Has anyone else done this integration before ? If so any tips or macros you
> want to share ? ;)
I did it once, a long time ago as a toy project to show it could be done.
Of course, it didn't get those tools that allow you to do
<html>
W/o typing '<html>' :)
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
"He who throws mud only loses ground." - Fat Albert
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>