You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Chris Searle <ch...@empolis.no> on 2004/03/11 10:36:37 UTC

Converting an existing struts/tiles to struts/tiles/velocity

Am using the velocity struts tools to migrate existing struts/tiles
apps over to velocity.

It seems to be going quite well - but I can't figure out the last bit.

The tiles part of the system has at least 4 parts per screen:

1) The tiles definition in XML

2) The layout file

3) Tiles with content

4) The root JSP file.


The definition


<tiles-definitions>
  <definition name=".default" path="/script/layout/main.vm">
    <put name="page.title" value="Default Page Title here" />
    <put name="header" value="/script/tiles/header.vm" />
    <put name="menu" value="/menu.do" />
    <put name="body" value="/script/tiles/content.vm" />
  </definition>
</tiles-definition


You can see from the definition that I've already converted the layout
to velocity and the tiles objects to velocity (with the use of the
velocity struts tools).

The bit I can't see is how to convert the top level JSPs (the ones
that the struts actions actually point to). These are very simple ones
that basically override some tiles attributes - here's an example JSP
that overwrites the page title and which tile to use for the body:



<%@ taglib uri="/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/struts-bean-el.tld" prefix="bean" %>

<tiles:insert definition="rsc.default" flush="true">
  <tiles:put name="page.title"><bean:message key='links.default.title'/></tiles:put>
  <tiles:put name="body" value="/script/tiles/links.vm"/>
</tiles:insert>



I can't figure out how to convert this to velocity with the struts
tools - or even if it's possible to do so. 

If we were writing from scratch then I'd probably take a different
approach - but with a large number of files to convert I'm looking for
the simplest conversion :-)

Any ideas as to the best approach?

-- 
Chris Searle
chris@empolis.no


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


Re: Converting an existing struts/tiles to struts/tiles/velocity

Posted by "Marino A. Jonsson" <ma...@hotmail.com>.
The input parameter for validated actions is presumably the name of the
tiles definition that assembles the form-page - i.e.

<action path="/displayForm"
    type="org.apache.struts.actions.ForwardAction"
    parameter="some.form"/>

<action path="/submitForm"
    type="org.apache.struts.actions.ForwardAction"
    validate="true"
    input="some.form"
    parameter="some.result"/>

where some.form and some.result are tiles-definitions.

cheers,
Marin�

"Chris Searle" <ch...@empolis.no> wrote in message
news:lgoer2sei4.fsf@montgomery.empolis.no...
> >>>>> "Marino" == Marino A Jonsson <ma...@hotmail.com> writes:
>
>     Marino> If I understand you correctly, this would be a good way to
>     Marino> go: Discard the top level JSPs and put all the defnitions
>     Marino> into tiles-conf.xml - then let the definitions from the
>     Marino> top level JSPs extend the default definition (or any other
>     Marino> definition) like so:
>
>     Marino> Then, let the struts-action point straight to the
>     Marino> definition, i.e.:
>
>     Marino> <action path="/rsc"
>     Marino> type="org.apache.struts.actions.ForwardAction"
>     Marino> parameter="rsc.default"/>
>
> Looks good. I'll give it a try. I guess the only thing I'm confused
> over is if I use this approach what should I set the input parameter
> to on validator actions ? Currently they point back to the top level
> JSPs.
>
> I'll get a copy of the examples too - thanks for the hint :-)
>
> -- 
> Chris Searle
> chris@empolis.no




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


Re: Converting an existing struts/tiles to struts/tiles/velocity

Posted by Chris Searle <ch...@empolis.no>.
>>>>> "Marino" == Marino A Jonsson <ma...@hotmail.com> writes:

    Marino> If I understand you correctly, this would be a good way to
    Marino> go: Discard the top level JSPs and put all the defnitions
    Marino> into tiles-conf.xml - then let the definitions from the
    Marino> top level JSPs extend the default definition (or any other
    Marino> definition) like so:

    Marino> Then, let the struts-action point straight to the
    Marino> definition, i.e.:

    Marino> <action path="/rsc"
    Marino> type="org.apache.struts.actions.ForwardAction"
    Marino> parameter="rsc.default"/>

Looks good. I'll give it a try. I guess the only thing I'm confused
over is if I use this approach what should I set the input parameter
to on validator actions ? Currently they point back to the top level
JSPs.

I'll get a copy of the examples too - thanks for the hint :-)

-- 
Chris Searle
chris@empolis.no


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


Re: Converting an existing struts/tiles to struts/tiles/velocity

Posted by "Marino A. Jonsson" <ma...@hotmail.com>.
If I understand you correctly, this would be a good way to go:

Discard the top level JSPs and put all the defnitions into tiles-conf.xml -
then let the definitions from the top level JSPs extend the default
definition (or any other definition) like so:

<tiles-definitions>
  <definition name=".default" path="/script/layout/main.vm">
    <put name="page.title" value="Default Page Title here" />
    <put name="header" value="/script/tiles/header.vm" />
    <put name="menu" value="/menu.do" />
    <put name="body" value="/script/tiles/content.vm" />
  </definition>
</tiles-definition

<tiles:insert definition="rsc.default" extends=".default">
   <tiles:put name="page.title">links.default.title</tiles:put>
   <tiles:put name="body" value="/script/tiles/links.vm"/>
</tiles:insert>


Then, let the struts-action point straight to the definition, i.e.:

<action path="/rsc"
            type="org.apache.struts.actions.ForwardAction"
            parameter="rsc.default"/>


To retrieve the page.title value (i.e. links.default.title) from the
message-resources in a Velocity page you want to use the MessageTool with
the TilesTool like so:

$text.get($tiles.getAttribute("page.title"))


Velocity Tools 1.1 rc1 comes with some handy tiles examples that cover this
approach very well - check them out :)

cheers,
Marin�


"Chris Searle" <ch...@empolis.no> wrote in message
news:lg65dbu3mi.fsf@montgomery.empolis.no...
>
> Am using the velocity struts tools to migrate existing struts/tiles
> apps over to velocity.
>
> It seems to be going quite well - but I can't figure out the last bit.
>
> The tiles part of the system has at least 4 parts per screen:
>
> 1) The tiles definition in XML
>
> 2) The layout file
>
> 3) Tiles with content
>
> 4) The root JSP file.
>
>
> The definition
>
>
> <tiles-definitions>
>   <definition name=".default" path="/script/layout/main.vm">
>     <put name="page.title" value="Default Page Title here" />
>     <put name="header" value="/script/tiles/header.vm" />
>     <put name="menu" value="/menu.do" />
>     <put name="body" value="/script/tiles/content.vm" />
>   </definition>
> </tiles-definition
>
>
> You can see from the definition that I've already converted the layout
> to velocity and the tiles objects to velocity (with the use of the
> velocity struts tools).
>
> The bit I can't see is how to convert the top level JSPs (the ones
> that the struts actions actually point to). These are very simple ones
> that basically override some tiles attributes - here's an example JSP
> that overwrites the page title and which tile to use for the body:
>
>
>
> <%@ taglib uri="/struts-tiles.tld" prefix="tiles" %>
> <%@ taglib uri="/struts-bean-el.tld" prefix="bean" %>
>
> <tiles:insert definition="rsc.default" flush="true">
>   <tiles:put name="page.title"><bean:message
key='links.default.title'/></tiles:put>
>   <tiles:put name="body" value="/script/tiles/links.vm"/>
> </tiles:insert>
>
>
>
> I can't figure out how to convert this to velocity with the struts
> tools - or even if it's possible to do so.
>
> If we were writing from scratch then I'd probably take a different
> approach - but with a large number of files to convert I'm looking for
> the simplest conversion :-)
>
> Any ideas as to the best approach?
>
> -- 
> Chris Searle
> chris@empolis.no




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


Re: Converting an existing struts/tiles to struts/tiles/velocity

Posted by Mike Kienenberger <mk...@alaska.net>.
Chris Searle <ch...@empolis.no> wrote:
> The tiles part of the system has at least 4 parts per screen:
> 1) The tiles definition in XML
> 2) The layout file
> 3) Tiles with content
> 4) The root JSP file.
> 
> The definition
> 
> 
> <tiles-definitions>
>   <definition name=".default" path="/script/layout/main.vm">
>     <put name="page.title" value="Default Page Title here" />
>     <put name="header" value="/script/tiles/header.vm" />
>     <put name="menu" value="/menu.do" />
>     <put name="body" value="/script/tiles/content.vm" />
>   </definition>
> </tiles-definition


Well, I know there's a tiles tool, but I found it easiest to convert my 
struts/tiles project to struts/velocity using Ted Husted's ViewAction class. 
 ViewAction simply converts the parameters listed in the action definition 
into velocity context attributes, using the default values specified in 
global-forwards if not given.

Since at this point, the attributes are all standard velocity attributes, 
you can access them from any parsed velocity file, or even use #set to 
modify the attribute values if needed, which appears to be your current 
difficulty now.

A global find-and-replace could probably take care of your tiles definitions 
conversion.  Your jsp code in velocity templates would have to be 
reconverted in any case.

A simplified example follows.

-Mike

===================start struts-config file=================================
    <global-forwards>
        <!-- DEFAULT TEMPLATE PATHS -->
        <forward name="layout" path="/WEB-INF/layouts/gveaLayout.vm" />
        <forward name="header" path="/WEB-INF/common/header.vm" />
        <forward name="leftSideMenu" path="/WEB-INF/common/leftSideMenu.vm" 
/>
        <forward name="loginPanel" path="/WEB-INF/common/loginPanel.vm" />
        <forward name="body" path="/WEB-INF/pages/Login.vm" />
        <forward name="footer" path="/WEB-INF/common/footer.vm" />
        <forward name="Title" path="Golden Valley Electric Association - 
Online Bill Payment" />
        <forward name="IsExternal" path="true" />
    </global-forwards>
[...]
    <action-mappings>
[...]
		<action path="/vm/Tour7"
		 type="us_ok_deq_wqdata.http.ViewAction"
		 validate="false"
		 
parameter="Style;IsExternal;ShouldShowReturnToLastPageLink;Title;leftSideMenu;loginPanel;header;body;footer">

		   <forward name="IsExternal" path="true" />
		   <forward name="Title" path="DEMO - Golden Valley Electric Association - 
Online Bill Payment" />
		   <forward name="Style" path="Body { font-family:Verdana, Arial; }" />
		   <forward name="body" path="/WEB-INF/pages/Tour7.vm" />
		</action>

		<action path="/vm/AdministrativeTasks"
		 type="us_ok_deq_wqdata.http.ViewAction"
		 validate="false"
		 
parameter="ReportComponentTemplate;IsExternal;ShouldShowReturnToLastPageLink;Title;leftSideMenu;loginPanel;header;body;footer">

		   <forward name="IsExternal" path="false" />
		   <forward name="Title" path="Golden Valley Electric Association - Online 
Bill Payment" />
		   <forward name="body" path="/WEB-INF/pages/AdministrativeTasks.vm" />
		   <forward name="ReportComponentTemplate" 
path="/WEB-INF/common/ReportComponent.vm" />
		</action>
[...]
    </action-mappings>
===================end struts-config file=================================

===================start Layout.vm file=================================
<!-- <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml11/DTD/transitional.dtd" > -->
<html>
	<head>
		<title>${Title}</title>#if( $Style )
		<style>${Style}</style>#end
	</head>
	<body>
 		#parse($header)
		#if( "$IsExternal" == "true")
			#parse($loginPanel)
		#else
			#parse($leftSideMenu)
		#end
		<div class="content">
			#parse($body)
	    	#parse($footer)
		</div>
	</body>
</html>
===================end Layout.vm file=================================

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