You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Markos Charatzas <xa...@forthnet.gr> on 2005/02/08 09:19:23 UTC

Struts & Velocity

Hi all,

Im just trying to get my head around this. Struts is meant to work with
actions. You create the mappings of the actions in the struts-config.xml and
define things like action handlers, forwards, etc.

Suppose I use Velocity to render the view.

Is there a standar place in struts or anywhere else that I can populate the
velocity context? (Doing it through request.put() of course)

My problem comes when I need to change the Locale for a page which fires up a
LocaleAction class which then renders the page Ive specified *but* without
the velocity context being populated since all the logic to populate the
context is defined in a different class.

In Turbine for example there is method which gets called and serves for
populating the context.

Thanks for your input.
Markos Charatzas

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


Re: Struts & Velocity

Posted by Markos Charatzas <xa...@forthnet.gr>.
Peter, you are 100% right that it should belong there. Actually the way I see 
it is that as ActionServlet handles Actions so VelocityViewServlet should 
handle Views! :) 

> Perhaps we will implement it ourselves actually since we are moving into
> the Chinese market this year.
Well that is why they call it OpenSource I guess :)

Nathan, Im aware of VelocityViewServlet and that is what I use :) but its good 
that you mentioned it to avoid misunderstanding.


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


Re: Language Tranlation Problem

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Gagan,

> I Have some XML file, which contains the template for emails (different xml file for different language).
> 
> Lets say a Japanese, French and English..XML file with proper encoding...
> 
> these templates have some velocity variable that would be populated at runtime... (and email is to be send in alll the languages to different user)
> 
> Lets say there is field to enter the name on the web page..
> user enter "test"...
> 
> this will work fine on English Template..
> but wat abt the other templates(Japanese & French)..
> 
> How can i get the user entered value ("test" in this case)  to get converted into other lang..?
> I hope i m bit clear...
> u have any idea???

Usually, I would use ResourceBundles for i18n issues.
cf. http://java.sun.com/j2se/1.5.0/docs/guide/intl/index.html

I've also heard that XML itself has a "lang" attribute, but I don't
know how it's used.

## If you're trying to translate the user's input, I would look for a
web service that provides translations.  :)

Best regards,
-- Shinobu

--
Shinobu Kawai <sh...@gmail.com>

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


Language Tranlation Problem

Posted by Gagan 007 <ga...@yahoo.com>.
HI all, 

PLease solve this problem

I Have some XML file, which contains the template for emails (different xml file for different language).
 
Lets say a Japanese, French and English..XML file with proper encoding...
 
these templates have some velocity variable that would be populated at runtime... (and email is to be send in alll the languages to different user)
 
 
Lets say there is field to enter the name on the web page.. 
user enter "test"...
 
this will work fine on English Template..
but wat abt the other templates(Japanese & French)..
 
 
How can i get the user entered value ("test" in this case)  to get converted into other lang..?
I hope i m bit clear...
u have any idea???

 

		
---------------------------------
Do you Yahoo!?
 Yahoo! Search presents - Jib Jab's 'Second Term'

Language Tranlation Problem

Posted by Gagan 007 <ga...@yahoo.com>.
HI all, 

PLease solve this problem

I Have some XML file, which contains the template for emails (different xml file for different language).
 
Lets say a Japanese, French and English..XML file with proper encoding...
 
these templates have some velocity variable that would be populated at runtime... (and email is to be send in alll the languages to different user)
 
 
Lets say there is field to enter the name on the web page.. 
user enter "test"...
 
this will work fine on English Template..
but wat abt the other templates(Japanese & French)..
 
 
How can i get the user entered value ("test" in this case)  to get converted into other lang..?
I hope i m bit clear...
u have any idea???

 

		
---------------------------------
Do you Yahoo!?
 Yahoo! Search presents - Jib Jab's 'Second Term'

Re: Struts & Velocity

Posted by Nathan Bubna <nb...@gmail.com>.
just to make sure you guys know, the VelocityServlet is deprecated and
should be removed following the release of Velocity 1.5.  it's
replacement is the VelocityViewServlet in the VelocityTools project. 
so if you have ideas for improvements or contributions, be sure to
make them regarding that servlet.  :)

On Wed, 09 Feb 2005 12:09:52 +1300, Peter Harrison
<pe...@nothingbutnet.co.nz> wrote:
> On Tue, 2005-02-08 at 17:54 +0200, Markos Charatzas wrote:
> 
> > I didnt put it correct. I dont mean that the LocaleAction renders the page, I
> > mean first calling LocaleAction *and* then rendering the page. So the
> > question is when to call request.put().
> >
> > At the moment I found a solution by declaring a global forward which always
> > calls the associated action with a given page (passed as a parameter) which
> > handles the "request.put" in the "execute" method.
> >
> > However, Im not 100% sure its the right way since I would imagine an Action
> > class would only handle all the business logic to prepare the objects for
> > request.put and not actually making it.
> 
> To be honest I think that this should go into VelocityServlet - or a
> child of it. I'm not sure this exists yet, but it shouldn't be very
> difficult. I've seen a few people asking about it - but no code yet.
> 
> Perhaps we will implement it ourselves actually since we are moving into
> the Chinese market this year.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

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


Re: Struts & Velocity

Posted by Peter Harrison <pe...@nothingbutnet.co.nz>.
On Tue, 2005-02-08 at 17:54 +0200, Markos Charatzas wrote:

> I didnt put it correct. I dont mean that the LocaleAction renders the page, I 
> mean first calling LocaleAction *and* then rendering the page. So the 
> question is when to call request.put().
> 
> At the moment I found a solution by declaring a global forward which always 
> calls the associated action with a given page (passed as a parameter) which 
> handles the "request.put" in the "execute" method.
> 
> However, Im not 100% sure its the right way since I would imagine an Action 
> class would only handle all the business logic to prepare the objects for 
> request.put and not actually making it.

To be honest I think that this should go into VelocityServlet - or a
child of it. I'm not sure this exists yet, but it shouldn't be very
difficult. I've seen a few people asking about it - but no code yet.

Perhaps we will implement it ourselves actually since we are moving into
the Chinese market this year.


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


Re: Struts & Velocity

Posted by Markos Charatzas <xa...@forthnet.gr>.
Thanks for your input!
>
> The easy way is to use the Velocity Servlet in velocity tools. By mapping
> say any "vm" file to the servlet you can process vm files. And yes, putting
> the data in the request or the session will make it available to the view.
> There isn't anywhere else really.
>

Yeah thats what im doing :D

>
> The exception is where method calls are made directly from the Velocity I
> suppose. Perhaps I'm dumb - but why is an action - the LocaleAction
> rendering anything? Shouldn't that be the job of Velocity?

I didnt put it correct. I dont mean that the LocaleAction renders the page, I 
mean first calling LocaleAction *and* then rendering the page. So the 
question is when to call request.put().

At the moment I found a solution by declaring a global forward which always 
calls the associated action with a given page (passed as a parameter) which 
handles the "request.put" in the "execute" method.

However, Im not 100% sure its the right way since I would imagine an Action 
class would only handle all the business logic to prepare the objects for 
request.put and not actually making it.

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


Re: Struts & Velocity

Posted by Peter Harrison <pe...@nothingbutnet.co.nz>.
On Tuesday 08 February 2005 21:19, Markos Charatzas wrote:
> Hi all,
>
> Im just trying to get my head around this. Struts is meant to work with
> actions. You create the mappings of the actions in the struts-config.xml
> and define things like action handlers, forwards, etc.
>
> Suppose I use Velocity to render the view.
>
> Is there a standar place in struts or anywhere else that I can populate the
> velocity context? (Doing it through request.put() of course)

The easy way is to use the Velocity Servlet in velocity tools. By mapping say 
any "vm" file to the servlet you can process vm files. And yes, putting the 
data in the request or the session will make it available to the view. There 
isn't anywhere else really.

> My problem comes when I need to change the Locale for a page which fires up
> a LocaleAction class which then renders the page Ive specified *but*
> without the velocity context being populated since all the logic to
> populate the context is defined in a different class.

Not sure I understand - populating the Velocity context is done by the 
VelocityServlet (of various flavours) from the request attributes and session 
attributes. Therefore all you actions must have occured prior to handing off 
to the view. 

The exception is where method calls are made directly from the Velocity I 
suppose. Perhaps I'm dumb - but why is an action - the LocaleAction rendering 
anything? Shouldn't that be the job of Velocity?

> In Turbine for example there is method which gets called and serves for
> populating the context.
>
> Thanks for your input.
> Markos Charatzas
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org

-- 
Peter Harrison
Managing Director
Nothing But Net Limited

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