You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by cleverpig <gr...@gmail.com> on 2009/10/19 11:44:18 UTC

T5:what can replace jsp's include tag in Tapestry?

i knew in the layout page,we can use block to implement the include
another page in layout page.

such as:
in the layout.tml:
...
            <div id="sidebar" t:type="if" test="sidebar">
                <ul>
                    <li>
                        <h2>${sidebarTitle}</h2>
                        <div class="sidebar-content">
                            <t:delegate to="sidebar"/>
                        </div>
                    </li>
                </ul>
            </div>
...

in the start.tml:
<html t:type="layout"
	title="${message:page-c01}"
	sidebarTitle="start here!"
	xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
	<t:parameter name="sidebar" >
		here is sidebar!
	</t:parameter>
</html>

so when start page displayed,the sidebar content will be given by the parameter.

but i got a deeper problem:i will added a common html code in start
and another pages,such as help link.
it sounds like include tag in jsp times.
i think it maybe can be done as what in the layout!
please give me a hand!

-- 
cleverpig(Dan)
Location: Beijing
Address: Room 4018,No.A2 South Avenue Fuxingmen Beijing,P.R.China
Zipcode: 100031
MSN: great_liudan@hotmail.com
QQ: 149291732
Skype: cleverpigatmatrix
Facebook ID:cleverpig
Blog: www.cleverpig.name
Tags: del.icio.us/cleverpig
Twitter: twitter.com/cleverpig
新浪微博: t.sina.com.cn/cleverpig
Organization: www.beijing-open-party.org
Organ@Facebook: http://www.facebook.com/group.php?gid=8159558294

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5:what can replace jsp's include tag in Tapestry?

Posted by cleverpig <gr...@gmail.com>.
thanks! Ulrich! you give a light on darkness!

i'd got the answer:make a reusable component.this is so easy in tapestry!

here is my code,share them now:
1.CommSideBar.tml:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
      <ul>
      	<li t:type="loop" source="pages" value="pageDes"
class="prop:classForPageName">
        	<t:pagelink
page="prop:pageDes.page">${pageDes.displayName}</t:pagelink>
        </li>
      </ul>
</html>

2.CommSideBar.java
package com.packtpub.t5first.components;

import java.util.ArrayList;
import java.util.List;

import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

public class CommSideBar {
	@Property
	private PageDes pageDes;
	@Inject
	private ComponentResources resources;
	@Property
	@Parameter(required=true)
	private List<PageDes> pages;
	
    public String getClassForPageName(){
    	return resources.getPageName().equalsIgnoreCase(pageDes.getPage())
             ? "current_sidebar_item"
             : "sidebar_item";
    }

}

3.put some style code on layout.css:
#sidebar DIV.sidebar-content LI.current_sidebar_item a{
    text-decoration:underline;
}

#sidebar DIV.sidebar-content LI.sidebar_item a{
    text-decoration:none;
}

4.use the CommSideBar component in Start page:
Start.class:
...
	public List<PageDes> getLinkPages(){
		List<PageDes> pages=new ArrayList<PageDes>();
		pages.add(new PageDes("another","另一页"));
		pages.add(new PageDes("scrip/create","创建纸条"));
		pages.add(new PageDes("scrip/listView","查看纸条"));
		return pages;
	}
...
start.tml:
<html t:type="layout"
	title="${message:system-name}"
	sidebarTitle="side bar"
	xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
	<t:parameter name="sidebar">
    	   <t:commSideBar pages="linkPages"></t:commSideBar>
        </t:parameter>
</html>

so here is the param-value-transform course:
1.commSideBar will get pages parameter from start;
2.and use it to construct sidebar parameter's value which will be as
layout's parameter.

thanks all of buddy from Tapestry!

On Mon, Oct 19, 2009 at 7:12 PM, Ulrich Stärk <ul...@spielviel.de> wrote:
> That's what components are used for: reusable pieces of markup and logic.
> Just build a component that's responsible for rendering out your common code
> and place that on each page where this common code shall be displayed.
>
> Cheers,
>
> Uli
>
> Am 19.10.2009 11:44 schrieb cleverpig:
>>
>> i knew in the layout page,we can use block to implement the include
>> another page in layout page.
>>
>> such as:
>> in the layout.tml:
>> ...
>>            <div id="sidebar" t:type="if" test="sidebar">
>>                <ul>
>>                    <li>
>>                        <h2>${sidebarTitle}</h2>
>>                        <div class="sidebar-content">
>>                            <t:delegate to="sidebar"/>
>>                        </div>
>>                    </li>
>>                </ul>
>>            </div>
>> ...
>>
>> in the start.tml:
>> <html t:type="layout"
>>        title="${message:page-c01}"
>>        sidebarTitle="start here!"
>>        xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
>>        <t:parameter name="sidebar" >
>>                here is sidebar!
>>        </t:parameter>
>> </html>
>>
>> so when start page displayed,the sidebar content will be given by the
>> parameter.
>>
>> but i got a deeper problem:i will added a common html code in start
>> and another pages,such as help link.
>> it sounds like include tag in jsp times.
>> i think it maybe can be done as what in the layout!
>> please give me a hand!
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
cleverpig(Dan)
Location: Beijing
Address: Room 4018,No.A2 South Avenue Fuxingmen Beijing,P.R.China
Zipcode: 100031
MSN: great_liudan@hotmail.com
QQ: 149291732
Skype: cleverpigatmatrix
Facebook ID:cleverpig
Blog: www.cleverpig.name
Tags: del.icio.us/cleverpig
Twitter: twitter.com/cleverpig
新浪微博: t.sina.com.cn/cleverpig
Organization: www.beijing-open-party.org
Organ@Facebook: http://www.facebook.com/group.php?gid=8159558294

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5:what can replace jsp's include tag in Tapestry?

Posted by Ulrich Stärk <ul...@spielviel.de>.
That's what components are used for: reusable pieces of markup and logic. Just build a component 
that's responsible for rendering out your common code and place that on each page where this common 
code shall be displayed.

Cheers,

Uli

Am 19.10.2009 11:44 schrieb cleverpig:
> i knew in the layout page,we can use block to implement the include
> another page in layout page.
> 
> such as:
> in the layout.tml:
> ...
>             <div id="sidebar" t:type="if" test="sidebar">
>                 <ul>
>                     <li>
>                         <h2>${sidebarTitle}</h2>
>                         <div class="sidebar-content">
>                             <t:delegate to="sidebar"/>
>                         </div>
>                     </li>
>                 </ul>
>             </div>
> ...
> 
> in the start.tml:
> <html t:type="layout"
> 	title="${message:page-c01}"
> 	sidebarTitle="start here!"
> 	xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
> 	<t:parameter name="sidebar" >
> 		here is sidebar!
> 	</t:parameter>
> </html>
> 
> so when start page displayed,the sidebar content will be given by the parameter.
> 
> but i got a deeper problem:i will added a common html code in start
> and another pages,such as help link.
> it sounds like include tag in jsp times.
> i think it maybe can be done as what in the layout!
> please give me a hand!
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org