You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Alan Chaney <al...@compulsivecreative.com> on 2009/09/29 18:46:29 UTC

T5: Newbie

I'm a complete newbie to T5. I need to develop my own component to go 
into a page. Could someone please direct me to an example on the web.

The component is very simple - it will just inject HTML from an external
source.

Thanks

Alan Chaney

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


Re: T5: Newbie

Posted by Alan Chaney <al...@compulsivecreative.com>.
Thanks Thiago - thanks for the pointers and the clues. I now seem to be 
on the right track...

Regards

Alan Chaney

Thiago H. de Paula Figueiredo wrote:
> Em Tue, 29 Sep 2009 13:46:29 -0300, Alan Chaney 
> <al...@compulsivecreative.com> escreveu:
> 
>> I'm a complete newbie to T5. I need to develop my own component to go 
>> into a page. Could someone please direct me to an example on the web.
>>
>> The component is very simple - it will just inject HTML from an external
>> source.
> 
> Writing components in T5 is very simple. A good source of examples is 
> http://jumpstart.doublenegative.com.au:8080/jumpstart/.
> 
> In your case, you need to pull HTML from an external source. For this, I 
> recommend Apache HttpClient. Once you have the needed HTML in a String, 
> you'll need to write it to the output. This is done using a 
> MarkupWriter. This is a component I use in my projects. Look at it to 
> see how you can use a MarkupWriter. You'll need to use 
> MarkupWriter.writeRaw() instead of write(), as the latter encodes the 
> strings (< into &lt;, etc).
> 
> public class Message {
> 
>     /**
>      * Message to be shown.
>      */
>     @Parameter(required = true)
>     private String message;
>     @BeforeRenderTemplate
>     public boolean render(MarkupWriter writer) {
>        
>         if (message != null && message.trim().length() > 0) {
>            
>             writer.element("div", "class", "t-crud-message");
>            
>             writer.element("p");
>             writer.write(message);
>             writer.end(); // p
>            
>             writer.end(); // div
>            
>         }
>        
>         return false;
>        
>     }
> 
> }
> 

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


Re: T5: Newbie

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Tue, 29 Sep 2009 13:46:29 -0300, Alan Chaney  
<al...@compulsivecreative.com> escreveu:

> I'm a complete newbie to T5. I need to develop my own component to go  
> into a page. Could someone please direct me to an example on the web.
>
> The component is very simple - it will just inject HTML from an external
> source.

Writing components in T5 is very simple. A good source of examples is  
http://jumpstart.doublenegative.com.au:8080/jumpstart/.

In your case, you need to pull HTML from an external source. For this, I  
recommend Apache HttpClient. Once you have the needed HTML in a String,  
you'll need to write it to the output. This is done using a MarkupWriter.  
This is a component I use in my projects. Look at it to see how you can  
use a MarkupWriter. You'll need to use MarkupWriter.writeRaw() instead of  
write(), as the latter encodes the strings (< into &lt;, etc).

public class Message {

	/**
	 * Message to be shown.
	 */
	@Parameter(required = true)
	private String message;
	@BeforeRenderTemplate
	public boolean render(MarkupWriter writer) {
		
		if (message != null && message.trim().length() > 0) {
			
			writer.element("div", "class", "t-crud-message");
			
			writer.element("p");
			writer.write(message);
			writer.end(); // p
			
			writer.end(); // div
			
		}
		
		return false;
		
	}

}

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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