You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Onur Tokan <ot...@gmail.com> on 2005/12/08 09:51:14 UTC

What is wrong with this code

Hi,

I have a problem about creating dynamic HtmlDataTable component. The
following code renders only the column's facets. NOT the CONTENTS...
Thanks...

HtmlDataTable dataTable = new HtmlDataTable();
for (int i = 1; i <= 10 i++)
{
	UIColumn column = new UIColumn();
	HtmlOutputText header = new HtmlOutputText();
	header.setValue("Column Header"+i);
	column.setHeader(header);
	for (int j = 1; j <= 100 j++)
	{
		HtmlOutputText rowText = new HtmlOutputText();
		rowText.setValue("Row:"+j+"Column:"+i);
		column.getChildren().add(rowText);
	}
	dataTable.getChildren().add(column);

}
return dataTable;

Re: What is wrong with this code

Posted by Onur Tokan <ot...@gmail.com>.
No Enrique, it's not the point. I am creating a vector of these
components and I am using FacesContext over vector. I think the
problem is about HtmlDataTable component, any ideas please...

On 12/8/05, Enrique Medina <e....@gmail.com> wrote:
> Try not to create the components through the "new" mechanism, but using
> FacesContext.getApplication.createComponent...
>
> 2005/12/8, Onur Tokan < otokan@gmail.com>:
> > Hi,
> >
> > I have a problem about creating dynamic HtmlDataTable component. The
> > following code renders only the column's facets. NOT the CONTENTS...
> > Thanks...
> >
> > HtmlDataTable dataTable = new HtmlDataTable();
> > for (int i = 1; i <= 10 i++)
> > {
> >         UIColumn column = new UIColumn();
> >         HtmlOutputText header = new HtmlOutputText();
> >         header.setValue("Column Header"+i);
> >         column.setHeader(header);
> >         for (int j = 1; j <= 100 j++)
> >         {
> >                 HtmlOutputText rowText = new HtmlOutputText();
> >                 rowText.setValue("Row:"+j+"Column:"+i);
> >                 column.getChildren().add(rowText);
> >         }
> >         dataTable.getChildren().add(column);
> >
> > }
> > return dataTable;
> >
>
>

Re: What is wrong with this code

Posted by Enrique Medina <e....@gmail.com>.
Try not to create the components through the "new" mechanism, but using
FacesContext.getApplication.createComponent...

2005/12/8, Onur Tokan <ot...@gmail.com>:
>
> Hi,
>
> I have a problem about creating dynamic HtmlDataTable component. The
> following code renders only the column's facets. NOT the CONTENTS...
> Thanks...
>
> HtmlDataTable dataTable = new HtmlDataTable();
> for (int i = 1; i <= 10 i++)
> {
>         UIColumn column = new UIColumn();
>         HtmlOutputText header = new HtmlOutputText();
>         header.setValue("Column Header"+i);
>         column.setHeader(header);
>         for (int j = 1; j <= 100 j++)
>         {
>                 HtmlOutputText rowText = new HtmlOutputText();
>                 rowText.setValue("Row:"+j+"Column:"+i);
>                 column.getChildren().add(rowText);
>         }
>         dataTable.getChildren().add(column);
>
> }
> return dataTable;
>

Re: What is wrong with this code

Posted by Volker Weber <us...@weber-oldenburg.de>.
Hi,

Simon Kitching wrote:
> Onur Tokan wrote:
> 
>> I have a problem about creating dynamic HtmlDataTable component. The
>> following code renders only the column's facets. NOT the CONTENTS...
>> Thanks...
>>
>> HtmlDataTable dataTable = new HtmlDataTable();
>> for (int i = 1; i <= 10 i++)
>> {
>>     UIColumn column = new UIColumn();
>>     HtmlOutputText header = new HtmlOutputText();
>>     header.setValue("Column Header"+i);
>>     column.setHeader(header);
>>     for (int j = 1; j <= 100 j++)
>>     {
>>         HtmlOutputText rowText = new HtmlOutputText();
>>         rowText.setValue("Row:"+j+"Column:"+i);
>>         column.getChildren().add(rowText);
>>     }
>>     dataTable.getChildren().add(column);
>>
>> }
>> return dataTable;
> 
> 
> It looks ok to me.

To me not, but i am not sure what you want do achieve.

creating a column,
creating a outputText as header and add it to the column.

and now create 100 outputText and add them as child to the column ?

This did not create a 100 row table!

> 
> One things you should do is explicitly assign an id to each component
> you create. All programmatically-created components should do this. And
> of course you need to invent some id-generator code to ensure that the
> assigned ids are all unique. However I doubt that this is the cause of
> your problem...
> 
> Regards,
> 
> Simon
> 

Regards
  Volker
-- 
Don't answer to From: address!
Mail to this account are droped if not recieved via mailinglist.
To contact me direct create the mail address by
concatenating my forename to my senders domain.

Re: What is wrong with this code

Posted by Onur Tokan <ot...@gmail.com>.
Yes Volker,

It's exacly the way I wanna do. I want to display 100 rows, 10 columns
table with header on each column.

Supposed to see the following result.

------------------------------------------------------------------------
Column Header 1 # Column Header 2  ... 10 columns here
-----------------------------------------------------------------------------------
Column Row 1     #  Column Row 1




                100 rows here





-------------------------------------------------------------------------------------

What do you think the problem is about?

Regards,

Onur

On 12/8/05, Volker Weber <us...@weber-oldenburg.de> wrote:
> Hi,
>
> Onur Tokan wrote:
> > Thank you simon,
> >
> > I've already tried to set unique id. I think we are missing something.
> > Maybe expert team members may show the way to do it. I've read all the
> > forum postings before asking here. There is no exact answer about this
> > topic. Maybe UIData component doesn't not support dynamic columns. Is
> > it madatory to set DataModel attribute of UIData.
>
> It is mandatory to set the value of UIData to a List, Array, ResultSet
> or DataModel valueBinding, from this are the rows build.
>
> >
> > Best regards,
> >
> > Onur
>
> regards
>  Volker
> --
> Don't answer to From: address!
> Mail to this account are droped if not recieved via mailinglist.
> To contact me direct create the mail address by
> concatenating my forename to my senders domain.
>

Re: What is wrong with this code

Posted by Volker Weber <us...@weber-oldenburg.de>.
Hi,

Onur Tokan wrote:
> Thank you simon,
> 
> I've already tried to set unique id. I think we are missing something.
> Maybe expert team members may show the way to do it. I've read all the
> forum postings before asking here. There is no exact answer about this
> topic. Maybe UIData component doesn't not support dynamic columns. Is
> it madatory to set DataModel attribute of UIData.

It is mandatory to set the value of UIData to a List, Array, ResultSet
or DataModel valueBinding, from this are the rows build.

> 
> Best regards,
> 
> Onur

regards
  Volker
-- 
Don't answer to From: address!
Mail to this account are droped if not recieved via mailinglist.
To contact me direct create the mail address by
concatenating my forename to my senders domain.

Re: What is wrong with this code

Posted by Simon Kitching <sk...@obsidium.com>.
Hi Onur,

Having dynamic columns, and setting the DataModel are two unrelated 
issues. The first controls the "width" of the table. The second controls 
its "height" (ie the number of rows rendered).

Even when all the columns have only static text the table will still 
render the number of rows corresponding to the number of objects in the 
DataModel.

If you aren't providing a data model to the table, then that would 
explain why your table only has headers! Without a datamodel, how is the 
table supposed to know how many rows to render?

Regards,

Simon,

Onur Tokan wrote:
> Thank you simon,
> 
> I've already tried to set unique id. I think we are missing something.
> Maybe expert team members may show the way to do it. I've read all the
> forum postings before asking here. There is no exact answer about this
> topic. Maybe UIData component doesn't not support dynamic columns. Is
> it madatory to set DataModel attribute of UIData.
> 
> Best regards,
> 
> Onur
> 
> On 12/8/05, Simon Kitching <sk...@obsidium.com> wrote:
>> Onur Tokan wrote:
>>> I have a problem about creating dynamic HtmlDataTable component. The
>>> following code renders only the column's facets. NOT the CONTENTS...
>>> Thanks...
>>>
>>> HtmlDataTable dataTable = new HtmlDataTable();
>>> for (int i = 1; i <= 10 i++)
>>> {
>>>       UIColumn column = new UIColumn();
>>>       HtmlOutputText header = new HtmlOutputText();
>>>       header.setValue("Column Header"+i);
>>>       column.setHeader(header);
>>>       for (int j = 1; j <= 100 j++)
>>>       {
>>>               HtmlOutputText rowText = new HtmlOutputText();
>>>               rowText.setValue("Row:"+j+"Column:"+i);
>>>               column.getChildren().add(rowText);
>>>       }
>>>       dataTable.getChildren().add(column);
>>>
>>> }
>>> return dataTable;
>> It looks ok to me.
>>
>> One things you should do is explicitly assign an id to each component
>> you create. All programmatically-created components should do this. And
>> of course you need to invent some id-generator code to ensure that the
>> assigned ids are all unique. However I doubt that this is the cause of
>> your problem...
>>
>> Regards,
>>
>> Simon
>>
> 
> 


Re: What is wrong with this code

Posted by Mike Kienenberger <mk...@gmail.com>.
Have you looked at using <t:columns> for creating dynamic sets of
columns?   If nothing else, you can use this a reference code.

On 12/8/05, Onur Tokan <ot...@gmail.com> wrote:
> Thank you simon,
>
> I've already tried to set unique id. I think we are missing something.
> Maybe expert team members may show the way to do it. I've read all the
> forum postings before asking here. There is no exact answer about this
> topic. Maybe UIData component doesn't not support dynamic columns. Is
> it madatory to set DataModel attribute of UIData.
>
> Best regards,
>
> Onur
>
> On 12/8/05, Simon Kitching <sk...@obsidium.com> wrote:
> > Onur Tokan wrote:
> > > I have a problem about creating dynamic HtmlDataTable component. The
> > > following code renders only the column's facets. NOT the CONTENTS...
> > > Thanks...
> > >
> > > HtmlDataTable dataTable = new HtmlDataTable();
> > > for (int i = 1; i <= 10 i++)
> > > {
> > >       UIColumn column = new UIColumn();
> > >       HtmlOutputText header = new HtmlOutputText();
> > >       header.setValue("Column Header"+i);
> > >       column.setHeader(header);
> > >       for (int j = 1; j <= 100 j++)
> > >       {
> > >               HtmlOutputText rowText = new HtmlOutputText();
> > >               rowText.setValue("Row:"+j+"Column:"+i);
> > >               column.getChildren().add(rowText);
> > >       }
> > >       dataTable.getChildren().add(column);
> > >
> > > }
> > > return dataTable;
> >
> > It looks ok to me.
> >
> > One things you should do is explicitly assign an id to each component
> > you create. All programmatically-created components should do this. And
> > of course you need to invent some id-generator code to ensure that the
> > assigned ids are all unique. However I doubt that this is the cause of
> > your problem...
> >
> > Regards,
> >
> > Simon
> >
>

Re: What is wrong with this code

Posted by Onur Tokan <ot...@gmail.com>.
Thank you simon,

I've already tried to set unique id. I think we are missing something.
Maybe expert team members may show the way to do it. I've read all the
forum postings before asking here. There is no exact answer about this
topic. Maybe UIData component doesn't not support dynamic columns. Is
it madatory to set DataModel attribute of UIData.

Best regards,

Onur

On 12/8/05, Simon Kitching <sk...@obsidium.com> wrote:
> Onur Tokan wrote:
> > I have a problem about creating dynamic HtmlDataTable component. The
> > following code renders only the column's facets. NOT the CONTENTS...
> > Thanks...
> >
> > HtmlDataTable dataTable = new HtmlDataTable();
> > for (int i = 1; i <= 10 i++)
> > {
> >       UIColumn column = new UIColumn();
> >       HtmlOutputText header = new HtmlOutputText();
> >       header.setValue("Column Header"+i);
> >       column.setHeader(header);
> >       for (int j = 1; j <= 100 j++)
> >       {
> >               HtmlOutputText rowText = new HtmlOutputText();
> >               rowText.setValue("Row:"+j+"Column:"+i);
> >               column.getChildren().add(rowText);
> >       }
> >       dataTable.getChildren().add(column);
> >
> > }
> > return dataTable;
>
> It looks ok to me.
>
> One things you should do is explicitly assign an id to each component
> you create. All programmatically-created components should do this. And
> of course you need to invent some id-generator code to ensure that the
> assigned ids are all unique. However I doubt that this is the cause of
> your problem...
>
> Regards,
>
> Simon
>

Re: What is wrong with this code

Posted by Simon Kitching <sk...@obsidium.com>.
Onur Tokan wrote:
> I have a problem about creating dynamic HtmlDataTable component. The
> following code renders only the column's facets. NOT the CONTENTS...
> Thanks...
> 
> HtmlDataTable dataTable = new HtmlDataTable();
> for (int i = 1; i <= 10 i++)
> {
> 	UIColumn column = new UIColumn();
> 	HtmlOutputText header = new HtmlOutputText();
> 	header.setValue("Column Header"+i);
> 	column.setHeader(header);
> 	for (int j = 1; j <= 100 j++)
> 	{
> 		HtmlOutputText rowText = new HtmlOutputText();
> 		rowText.setValue("Row:"+j+"Column:"+i);
> 		column.getChildren().add(rowText);
> 	}
> 	dataTable.getChildren().add(column);
> 
> }
> return dataTable;

It looks ok to me.

One things you should do is explicitly assign an id to each component 
you create. All programmatically-created components should do this. And 
of course you need to invent some id-generator code to ensure that the 
assigned ids are all unique. However I doubt that this is the cause of 
your problem...

Regards,

Simon