Need a bit more info: do you know how to render an individual item? That is, is 
this component supposed to generically render any type of item? In any event, 
here's a quick sketch of how to go about what you want (untested code :), 
assuming you want to easily override the default rendering...

MyComponent.java:

@Parameter(required=true, allowNull=false)
private List<?> items;

@Parameter("block:defaultBlock")
private Block itemBlock;

@Parameter
@Property
private Object item; //currently rendering item

public String getHeader() {
//in reality, you should have a case for 0 items, as well, but this meets the 
requirements of your description.
   return items.size()==1?"This is the item":"These are the items";
}



MyComponent.tml:

<!-- fancy html goes here--> 
<div class="fancycontainer">
  <div class="header">${header}</div>
  <ul>
    <li t:type="loop" source="items" value=inherit:item"><t:delegate 
to="itemBlock"/></li>
  </ul>
  <t:block id="defaultBlock">
<!-- fall back on the object's toString() method... -->
    ${item}
  </t:block>
</div>
      

No you can use your component as:

.tml:
<t:mycomponent items="myitems" item="anitem">
  <p:itemBlock>
    ${anitem.prop1} - ${anitem.prop2}
  </p:itemBlock>
</t:mycomponent>

.java:

@Property
private MyItem anitem;

The one thing the above doesn't handle is if the item should render itself or 
not. You can get that by moving the loop declaration in the template:
  <t:loop source="items" value="inherit:item">
    <t:if test="item.shouldRender">
      <li><t:delegate to="itemBlock"/></li>
    </t:if>     
  </t:loop>

Cheers,

Robert

On Feb 1, 2012, at 2/112:28 PM , Tim wrote:

> How easy is this to do?
> 
> I want a component that displays, with attractive html such as in a border or 
> something, a group of items.  I'm thinking each item should be a component 
> itself, but correct me if I'm wrong there.  If there are more than one item 
> to be rendered, the main component should display a heading "These are the 
> items", and if only one, then it should say "This is the item.".  And if 
> there are none that should be rendered, then the component should not render 
> at all.
> 
> Oh, and each item has a parameter that might cause it to not render itself.  
> So the main component needs to know how many will be rendered, not just how 
> many there are in the .tml file.
> 
> Right now I'm staring at the code of the class AbstractConditional, in the 
> beginRender method, hoping to find some inspiration.  But maybe someone on 
> this list has a better idea.  Anyone?
> 
> Thanks.
> 
> --
> Tim Koop
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
> 


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

Reply via email to