You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Biesbrock, Kevin" <Bi...@aoins.com> on 2011/04/19 19:43:35 UTC

Struts2/Velocity Integration

I am having a difficult time finding documentation on how to integrate
Struts 2 and Velocity.  Can the Struts2 community offer any aid?  I'm
asking here first because it was recommended I use Velocity by a member
of this group.

I found the Velocity taglib that seems like it would be exactly what I'm
looking for but it appears to only be supported in Struts1?  'what I'm
looking for' is this:

I'm working on a legacy system that is built on jsp.  In one of the jsps
I need to include a velocity template.  The template does not require
access to any dynamic data.

Please help point me in the right direction.
 
d[-_-]b \m/
Beez


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts2/Velocity Integration

Posted by "Biesbrock, Kevin" <Bi...@aoins.com>.
From: Dave Newton [mailto:davelnewton@gmail.com] Tuesday, April 19, 2011
3:06 PM
> You'd create a tag; there aren't any out-of-the-box in S2, although
there might be a third-party taglib that'd do it. It's really, really
easy.

Okay.  Just not something I've done previously.  No better time to
learn!

Thank you for your patience! 

Sincerely,
Beez


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts2/Velocity Integration

Posted by Dave Newton <da...@gmail.com>.
You'd create a tag; there aren't any out-of-the-box in S2, although
there might be a third-party taglib that'd do it. It's really, really
easy.

Dave

On Tue, Apr 19, 2011 at 3:03 PM, Biesbrock, Kevin
<Bi...@aoins.com> wrote:
> Now we're narrowing in:
>
>> <v:renderTemplate template="theTemplate.vm"/>
>
> Do I need to create my own taglib for 'v'?  There seems to be little
> documentation with regard to this for Struts2 and Velocity.  But this is
> the very thing I would like to accomplish.  Or perhaps I'm overlooking
> it; could you point to documentation for this?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts2/Velocity Integration

Posted by "Biesbrock, Kevin" <Bi...@aoins.com>.
Now we're narrowing in:

> <v:renderTemplate template="theTemplate.vm"/>

Do I need to create my own taglib for 'v'?  There seems to be little
documentation with regard to this for Struts2 and Velocity.  But this is
the very thing I would like to accomplish.  Or perhaps I'm overlooking
it; could you point to documentation for this?


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts2/Velocity Integration

Posted by Dave Newton <da...@gmail.com>.
On Tue, Apr 19, 2011 at 2:50 PM, Biesbrock, Kevin wrote:
> One option, I gather, is the same
> thing Eric suggested -- render the template in the action class and put
> the result into a string for the view to pull using <s:property.../>.
> Is that correct?

Yeah, although I'd just use JSTL ${whatever}

> What about the "simple tag" concept?  How would I implement that in my
> view?  That's the solution I was hoping to find; as I feel it's more
> MVC-compliant.

<v:renderTemplate template="theTemplate.vm"/> or whatever.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts2/Velocity Integration

Posted by "Biesbrock, Kevin" <Bi...@aoins.com>.
From: Dave Newton [mailto:davelnewton@gmail.com] Tuesday, April 19, 2011
2:41 PM
>The response was embedded/implied; if there's no data model at all then
it doesn't matter if you have a simple 
>tag around template rendering or within the action itself. Going
through an entire request process is unnecessary.

I understand that point.  I apologize, but I'm a little unclear as to
what you're actually suggesting I do.  One option, I gather, is the same
thing Eric suggested -- render the template in the action class and put
the result into a string for the view to pull using <s:property.../>.
Is that correct?

What about the "simple tag" concept?  How would I implement that in my
view?  That's the solution I was hoping to find; as I feel it's more
MVC-compliant.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts2/Velocity Integration

Posted by Dave Newton <da...@gmail.com>.
On Tue, Apr 19, 2011 at 2:34 PM, Biesbrock, Kevin wrote:
> There was no response to that and I didn't want to specifically call you
> out for a response because I recognize that you're a developer, too, and
> are busy with your own shtuff.

The response was embedded/implied; if there's no data model at all
then it doesn't matter if you have a simple tag around template
rendering or within the action itself. Going through an entire request
process is unnecessary.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts2/Velocity Integration

Posted by "Biesbrock, Kevin" <Bi...@aoins.com>.
From: Dave Newton [mailto:davelnewton@gmail.com] Tuesday, April 19, 2011
2:18 PM
> we just discussed this topic within the last few days.

If you're referring to my previous question, that was never resolved.
It was left with:

> From: Dave Newton [mailto:davelnewton@gmail.com] 
>> Do the templates use the same models as the web layer?

> Actually, it would have been good to note that the contact information
is hard-coded.  So there is no need for a model.  
> I literally just need to include a block of html-/css-formatted text
[in both a class and a jsp].

There was no response to that and I didn't want to specifically call you
out for a response because I recognize that you're a developer, too, and
are busy with your own shtuff.

----------------

From: Eric Lentz [mailto:Eric.Lentz@sherwin.com] Tuesday, April 19, 2011
1:55 PM
> render the Velocity template within [a facade].

Sounds like my original thought -- something like this:
<action name="getTemplate_*">
	<result
type="velocity">/WEB-INF/myVelocityTemplates/{1}.vm</result>
</action>

----------------

From: Martin Gainty [mailto:mgainty@hotmail.com] Tuesday, April 19, 2011
2:01 PM
> can you confirm these entries in your struts webapp?

Confirmed.  I have not yet tried the facade method mentioned above.  I
originally saw that as an option but didn't know if there was a better
way e.g., the VelocityViewTag -- which only appears to be supported with
Struts1 (perhaps replaced by the velocity return type in Struts2?).

Thank you, gentlemen, for your time and timely responses.

Sincerely,
-Beez


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts2/Velocity Integration

Posted by Dave Newton <da...@gmail.com>.
Check back in the list; we just discussed this topic within the last few days.

Dave

On Tue, Apr 19, 2011 at 1:55 PM, Eric Lentz <Er...@sherwin.com> wrote:
>> I'm working on a legacy system that is built on jsp.  In one of the jsps
>> I need to include a velocity template.  The template does not require
>> access to any dynamic data.
>
> Struts lets you use Velocity instead of JSPs as an option. Using JSPs
> *and* Velocity isn't an out-of-the-box type of thing, I don't believe.
> What I might consider, and there might be a better way, would be to use a
> String type field in my action, render the Velocity template within the
> action (or in a facade, helper or extended class) and assign that output
> to the String. Then, in the JSP, use a <s:property > where the name of it
> is the String that you assigned the output from Velocity. That should just
> dump everything that was rendered from the template.
>
> Make sense? Other people with better ideas?
>
> - Eric

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts2/Velocity Integration

Posted by Eric Lentz <Er...@sherwin.com>.
> I'm working on a legacy system that is built on jsp.  In one of the jsps
> I need to include a velocity template.  The template does not require
> access to any dynamic data.

Struts lets you use Velocity instead of JSPs as an option. Using JSPs 
*and* Velocity isn't an out-of-the-box type of thing, I don't believe. 
What I might consider, and there might be a better way, would be to use a 
String type field in my action, render the Velocity template within the 
action (or in a facade, helper or extended class) and assign that output 
to the String. Then, in the JSP, use a <s:property > where the name of it 
is the String that you assigned the output from Velocity. That should just 
dump everything that was rendered from the template.

Make sense? Other people with better ideas?

- Eric