To use table layout, etc., you assemble all
of them into one component hierarchy, and
then call encodeAll() on the root. These are
components where rendersChildren="true", so you can't
just render them with encodeBegin()/encodeEnd().
But these components (all the ones we
call "Html" instead of "Core") really don't abstract
you very much from the underlying HTML.
So, honestly, you might do just as well to write
ResponseWriter rw = context.getResponseWriter();
rw.startElement("table", null);
rw.startElement("tr", null);
... etc...
-- Adam
On 2/21/07, Bertrand, Shawn R <[EMAIL PROTECTED]> wrote:
Hi all,
I'd like to use the Trinidad layout components (HtmlTableLayout,
HtmlRowLayout, and HtmlCellFormat) in a custom component I've developed,
but I'm not sure how to integrate each component of the table together.
I'm sure I'm missing something basic (like linking them in parent-child
relationships), so thanks for your help in clarifying this.
I originally thought calling the encode methods would do the trick, but
output suggested that rows need to be linked to the table, and cells
need to be linked to the rows. The code I had is below.
Thanks,
Shawn
// Start JSF table layout
HtmlTableLayout tblLayout = new HtmlTableLayout();
tblLayout.setBorderWidth(0);
tblLayout.setCellPadding(3);
tblLayout.setCellSpacing(3);
tblLayout.encodeBegin(context);
// Iterate over each row
HtmlRowLayout rowLayout;
HtmlCellFormat cellFormat;
for (LabelFieldComponent comp : comps)
{
// Start row
rowLayout = new HtmlRowLayout();
rowLayout.encodeBegin(context);
// Start label cell
cellFormat = new HtmlCellFormat();
cellFormat.setHalign(comp.getLabel().getHAlign());
cellFormat.setHeight(Integer.valueOf(comp.getLabel().getHeight()).toStri
ng());
cellFormat.setWidth(Integer.valueOf(comp.getLabel().getWidth()).toString
());
cellFormat.setValign(comp.getLabel().getVAlign());
cellFormat.encodeBegin(context);
// Insert label
writer.write(comp.getLabel().getText());
// End label cell
cellFormat.encodeEnd(context);
// Start field cell
cellFormat = new HtmlCellFormat();
cellFormat.setHalign(comp.getField().getHAlign());
cellFormat.setHeight(Integer.valueOf(comp.getField().getHeight()).toStri
ng());
cellFormat.setValign(comp.getField().getVAlign());
cellFormat.encodeBegin(context);
// Insert field
writer.write(comp.getField().getHTML());
// End label cell
cellFormat.encodeEnd(context);
// End row
rowLayout = new HtmlRowLayout();
rowLayout.encodeEnd(context);
}
// Complete layout
tblLayout.encodeEnd(context);