You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jun Tsai <ju...@gmail.com> on 2005/04/20 04:04:23 UTC

How to program a component?

I want to add a component into a page dynamicly.For exmaple:

Test.jwc
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE component-specification PUBLIC
  "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
  "http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
<!-- $Id$ -->

<component-specification class="synthetic.Test"
    allow-body="yes"
    allow-informal-parameters="yes">
    
    <description>add a description</description>
    
    
    
</component-specification>

Test.html
<!-- $Id$ -->
<span jwcid="$content$">
This is a test component.
   
</span>

TestPage.html
<span jwcid="@Foreach" source="ognl:blocks" value="ognl:block">
   <span jwcid="@RenderBlock" block="ognl:block">Page content goes here</span>
</span>
TestPage.page
.....
<property-specification name="block"
type="org.apache.tapestry.components.Block"/>
.....
TestPage.java
public List getBlocks(){
		List blocks=new ArrayList();
		IComponent ic=new Block();
		IResourceLocation
ir=Tapestry.getApplicationRootLocation(this.getPage().getRequestCycle()).getRelativeLocation("/WEB-INF/Test.jwc");
		IComponentSpecification
cs=this.getPage().getEngine().getSpecificationSource().getComponentSpecification(ir);
		ic.setSpecification(cs);
		blocks.add(ic);
			
		
		if (log.isDebugEnabled()) {
			log.debug("get blocks size ["+blocks.size()+"]");
		}
		
		return blocks;
	}

But it doesn't work.
I don't use tapestry example about renderblock,beacause my block is producted by
module definition and user state.
Thanks
Jun Tsai


-- 
Welcome to China Java Users Group(CNJUG).
http://cnjug.dev.java.net

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