tapestry-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <ivan.georg...@iginex.com>
Subject Add paremeter in For type component
Date Tue, 02 Jan 2007 22:11:45 GMT
Hi all,

I am quite new to tapestry. I am trying to run a simple menu. It is made
with links and sublinks - when user click links, the sublinks are shown
below the lhe parent link. I was wondering if I can pass a paremeter
with the current link evaluated to the 'sublinks' component so in my
Home.java the method should be getSublinks(String currentLink). 


Here is the current code - all sublinks are displayed for each link: 

Home.page

<page-specification>
	<property name="aLink"/>
	<property name="aSublink"/>
	
	<component id="links" type="For">
		<binding name="source" value="links"/>
		<binding name="value" value="aLink"/>
		<binding name="element" value="literal:tr"/>
	</component>
	
	<component id="sublinks" type="For">
		<binding name="source" value="sublinks"/>
		<binding name="value" value="aSublink"/>
		<binding name="element" value="literal:tr"/>
	</component>
	
	<component id="linkName" type="Insert">
		<binding name="value" value="aLink"/>
	</component>
	
	<component id="sublinkName" type="Insert">
		<binding name="value" value="aSublink"/>
	</component>
	
	<component id="detailsLink" type="DirectLink">
		<binding name="listener"
value="listener:onClickDetailsLink"/>		
		<binding name="parameters" value="aLink"/>
	</component>		
	
	<component id="subDetailsLink" type="DirectLink">
		<binding name="listener"
value="listener:onClickDetailsLink"/>		
	</component>		
	
</page-specification>


----

Home.html

<html>
<head>
<title>TestLinks</title>
</head>
<body>
	<table border="1">		
		<tr jwcid="links">
			<td colspan=2>
				<a href="" jwcid="detailsLink"><span
jwcid="linkName">Link</span></a>
			</td>			
			<tr jwcid="sublinks">				
				<td></td>
				<td>
					<a href=""
jwcid="subDetailsLink"><span jwcid="sublinkName">SubLink</span></a>
				</td>			
			</tr>
		</tr>		
	</table>
</body>
</html>

----

Home.java

public abstract class Home extends BasePage {
	
	@InjectPage("Home")
	public abstract Home getHome();
	
	@Persist("client")
	public abstract String getSelected();
	public abstract void setSelected(String selected);	

	public void onClickDetailsLink(String selected) {
		setSelected(selected);		
		getHome();
	}
	
	public Collection getLinks() {
		ArrayList<String> list = new ArrayList<String>();
		list.add("Link1");
		list.add("Link2");			
		return list;
	}
	
	public Collection getSublinks() {		
		if (getSelected() != null) {	
			
			if (getSelected().equals("Link1")) {
				ArrayList<String> list = new
ArrayList<String>();
				list.add("SubLink1");

				list.add("SubLink2");
				return list;
			}
			if (getSelected().equals("Link2")) {
				ArrayList<String> list = new
ArrayList<String>();
				list.add("SubLink3");

				list.add("SubLink4");
				return list;
			}		
		}
		
		return new ArrayList<String>();
	}
}

Thanks in advance,

Regards,


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


Mime
View raw message