My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
DirectoryOfBricks  
A directory of HTML bricks, available out of the box.
Updated Sep 26, 2009 by dha...@gmail.com

Core Bricks

These come part of the core distribution:

Brick Name Description Self Rendering?+ Example
@ShowIf Hides or shows annotated tag content No @ShowIf(1+1 == 2)<p>yes!</p>
@Repeat Repeats annotated tag content over provided collection No @Repeat(items=movies, var="movie")
@TextField A simple textbox with a property binding Yes @TextField(myName)<input/>
@Require Indicates the annotated tag must be rendered in <head> of target page No See below
@Include Includes any 'called-with' bricks in the embedded brick No See below

+ Self rendering bricks will ignore the HTML tag they annotate

Examples

This section provides a bit more detail on how to use these bricks.

Repeat brick

This brick is perfect for projecting a template fragment across a collection. Let's say you have a List<Movie> movies in your page class, and you want to print them out in an unordered list:

<ul>
    @Repeat(items=movies, var="movie")
    <li>${movie.name}</li>
</ul>

For the scope of the repetition, movie becomes the context. In order to access the outer page object, you must use the scope variable pageVar. For example:

<ul>
    @Repeat(items=movies, var="movie", pageVar="actor")
    <li>${actor.name} starring in ${movie.name}</li>
</ul>

The pageVar (if left out) will default to page. Nesting repeat bricks results in dynamic scoping of pageVar.

The repeat brick can repeat over any subtype of java.util.Collection.

Require brick

The require brick is basically useful in embedding pages that have a javascript, css or other external dependency that must be included in the target page. For instance, let's say you have a script called ajax.js which provides some ajax functionality that you use in your page:

<html>
    <head>
        <script type="text/javascript" src="ajax.js"> </script>
    </head>

    <body>
        <!-- some cool ajax stuff here -->
    </body>
</html>

Now you can wrap this brick and reuse it in any of your pages using the @EmbedAs annotation on your java page classes. Learn how to do this in EmbeddingBricks. But this does not give us the linked script (remember anything outside <body> is discarded when embedding).

So to get around that we use the @Require annotation as follows:

<html>
    <head>
        @Require
        <script type="text/javascript" src="ajax.js"> </script>
    </head>

    ...

This tells Sitebricks to render the <script> tag in the <head> of any pages that embed this page. Sitebricks is also smart enough to remove multiple occurrences of the same @Require brick (matched by string equality), so you don't render duplicates when embedding a brick multiple times in the same page. This is known as tag interning.

Comment by frederic...@gmail.com, Oct 6, 2009

Any thought for a 'select' brick ? Would be glad to code one :)

Comment by willem.s...@gmail.com, Apr 4, 2010

Can you access the @Repeat index variable? How would you use the @Repeat construct when there's no tag to annotate? eg iterate a list in a javascript function

Comment by ajes...@gmail.com, May 2, 2010

N00b question - any tutorials/examples on how to use the @Include tag?


Sign in to add a comment
Powered by Google Project Hosting