You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Andreas Zeller - zit-systems <an...@zit-systems.de> on 2006/01/17 21:20:42 UTC

myFaces and dynamic table model

Hi there,

I have been working with myFaces for the past few weeks and tried to
implement a product management tool.

Works as follows:

It displays and html table with several columns, that should as well be
removable and movable. I managed to implement sorting with
commandSortHeader and inline-editing, using the column Tag.

But I am a little confused using the columns tag. How can I, for
instance, set a single column not rendered? If I set the rendered
attribute, I thought it might affect only a single column, but the
moment I set the rendered attribute, it disable the entire set of columns.

Anyway, I now decided to remove the columns from the model and remove
the data instead of disabling them, but somehow I now get an
IndexOutOfBoundsException that I didn't manage to get rid of yet.

My question would be, if anybody already has such a table model as a
reference. I already took a look at the examples at irian.at, but the
only dynamic model doesn't actually move and remove columns but fill
them dynamically with random numbers, not exactly with values.

If anyone has an example for that, I'd be glad if he or she might want
to share it with me.

Andreas

Re: myFaces and dynamic table model

Posted by Mike Kienenberger <mk...@gmail.com>.
> - Your data model, where columns can be marked disabled.

Oops.  The disabled marking would really be in your adaptor class, not
in your raw data model.  Stream of conciousness typing error.

On 1/17/06, Mike Kienenberger <mk...@gmail.com> wrote:
> Well, I'd base it on the Swing Table model rather than inventing this
> all from scratch.
>
> You actually need two models:
> - Your data model, where columns can be marked disabled.
> - Your column view model, which only contains the columns in the
> rendering order.
>
> So your data model has 1,2,3,4,5 and your column view model (which is
> the backing model for t:columns) might contain 3,1,5.   You'll
> probably also want some view-to-model adaptor class that can get from
> a column view model index to a data model index, and vice-versa.  That
> way you keep your data model pure from view abstractions, and the JSF
> backing model is still in the format expected by dataTable.
>
> If you get all of this working, it'd be a great contribution to MyFaces.
>
> On 1/17/06, Andreas Zeller - zit-systems <an...@zit-systems.de> wrote:
> >  My idea was as follows:
> >
> >  Add a remove button like "-", arrows for moving columns from left to right
> > all inside a panelgroup in the table header.
> >
> >  Columns have IDs, that's how I identify them. For each ID there's a
> > position. I store these values inside a Map<String,Integer>.
> >
> >  When building the actual table Model, I store the values inside a List at
> > specific positions... First of all, I have to fill the model with
> > dummy-values so I can set specific positions, because a List doesn't like
> > any value being set at index X, when it is empty. So I need to fill it up
> > with some crap and remove the crap after building it.
> >
> >  A more elegant way would of course be getting rid of the dummy values, but
> > I don't see any elegant way to do this, because any "packing" method I was
> > thinking about would screw up my model. For example: If I have 5 columns and
> > I disable column #3. It should draw column 1, 2, 4, 5. Wouldn't be too bad
> > if column #3 was appended when I put it back in, but I need to update the
> > entire model including the stored data, instead of just having it "disabled"
> > and leave the data inside the bean, where it belongs...
> >
> >  See my problem?
> >
> >  Andreas
> >
> >
> >
> >  Mike Kienenberger wrote:
> >  On 1/17/06, Andreas Zeller - zit-systems <an...@zit-systems.de>
> > wrote:
> >
> >
> >  Thanks for the quick reply. I already tried that, unfortunately I just get
> > empty columns, with not text at all, it doesn't actually remove the column.
> >
> >  Yeah, you're right. That'd leave empty columns
> >
> >
> >
> >  I'd be really glad if there were some kind of a straight forward example.
> >
> >  Someone must have done something like this by now, hasn't anyone?
> >
> >  I don't think so. It was considered pretty innovative to have the
> > ability to have the number of columns be dynamic. I haven't heard of
> > anyone trying to add or remove columns afterward yet.
> >
> > Changing the backing model for t:columns sounds like the way to go.
> > You're going to have to work through whatever bugs that might entail
> > though. At what point in the jsf lifecycle are you trying to change
> > the column model? I'd say you can only change it in invoke
> > application. Changing it before updateModel or after renderResponse
> > is probably going to fail because other code depends on those column
> > numbers remaining constant.
> >
> >
> >
> >
> >
>

Re: myFaces and dynamic table model

Posted by Mike Kienenberger <mk...@gmail.com>.
Well, I'd base it on the Swing Table model rather than inventing this
all from scratch.

You actually need two models:
- Your data model, where columns can be marked disabled.
- Your column view model, which only contains the columns in the
rendering order.

So your data model has 1,2,3,4,5 and your column view model (which is
the backing model for t:columns) might contain 3,1,5.   You'll
probably also want some view-to-model adaptor class that can get from
a column view model index to a data model index, and vice-versa.  That
way you keep your data model pure from view abstractions, and the JSF
backing model is still in the format expected by dataTable.

If you get all of this working, it'd be a great contribution to MyFaces.

On 1/17/06, Andreas Zeller - zit-systems <an...@zit-systems.de> wrote:
>  My idea was as follows:
>
>  Add a remove button like "-", arrows for moving columns from left to right
> all inside a panelgroup in the table header.
>
>  Columns have IDs, that's how I identify them. For each ID there's a
> position. I store these values inside a Map<String,Integer>.
>
>  When building the actual table Model, I store the values inside a List at
> specific positions... First of all, I have to fill the model with
> dummy-values so I can set specific positions, because a List doesn't like
> any value being set at index X, when it is empty. So I need to fill it up
> with some crap and remove the crap after building it.
>
>  A more elegant way would of course be getting rid of the dummy values, but
> I don't see any elegant way to do this, because any "packing" method I was
> thinking about would screw up my model. For example: If I have 5 columns and
> I disable column #3. It should draw column 1, 2, 4, 5. Wouldn't be too bad
> if column #3 was appended when I put it back in, but I need to update the
> entire model including the stored data, instead of just having it "disabled"
> and leave the data inside the bean, where it belongs...
>
>  See my problem?
>
>  Andreas
>
>
>
>  Mike Kienenberger wrote:
>  On 1/17/06, Andreas Zeller - zit-systems <an...@zit-systems.de>
> wrote:
>
>
>  Thanks for the quick reply. I already tried that, unfortunately I just get
> empty columns, with not text at all, it doesn't actually remove the column.
>
>  Yeah, you're right. That'd leave empty columns
>
>
>
>  I'd be really glad if there were some kind of a straight forward example.
>
>  Someone must have done something like this by now, hasn't anyone?
>
>  I don't think so. It was considered pretty innovative to have the
> ability to have the number of columns be dynamic. I haven't heard of
> anyone trying to add or remove columns afterward yet.
>
> Changing the backing model for t:columns sounds like the way to go.
> You're going to have to work through whatever bugs that might entail
> though. At what point in the jsf lifecycle are you trying to change
> the column model? I'd say you can only change it in invoke
> application. Changing it before updateModel or after renderResponse
> is probably going to fail because other code depends on those column
> numbers remaining constant.
>
>
>
>
>

Re: myFaces and dynamic table model

Posted by Andreas Zeller - zit-systems <an...@zit-systems.de>.
My idea was as follows:

Add a remove button like "-", arrows for moving columns from left to
right all inside a panelgroup in the table header.

Columns have IDs, that's how I identify them. For each ID there's a
position. I store these values inside a Map<String,Integer>.

When building the actual table Model, I store the values inside a List
at specific positions... First of all, I have to fill the model with
dummy-values so I can set specific positions, because a List doesn't
like any value being set at index X, when it is empty. So I need to fill
it up with some crap and remove the crap after building it.

A more elegant way would of course be getting rid of the dummy values,
but I don't see any elegant way to do this, because any "packing" method
I was thinking about would screw up my model. For example: If I have 5
columns and I disable column #3. It should draw column 1, 2, 4, 5.
Wouldn't be too bad if column #3 was appended when I put it back in, but
I need to update the entire model including the stored data, instead of
just having it "disabled" and leave the data inside the bean, where it
belongs...

See my problem?

Andreas


Mike Kienenberger wrote:

>On 1/17/06, Andreas Zeller - zit-systems <an...@zit-systems.de> wrote:
>  
>
>> Thanks for the quick reply. I already tried that, unfortunately I just get
>>empty columns, with not text at all, it doesn't actually remove the column.
>>    
>>
>
>Yeah, you're right.  That'd leave empty columns
>
>  
>
>> I'd be really glad if there were some kind of a straight forward example.
>>
>> Someone must have done something like this by now, hasn't anyone?
>>    
>>
>
>I don't think so.  It was considered pretty innovative to have the
>ability to have the number of columns be dynamic.   I haven't heard of
>anyone trying to add or remove columns afterward yet.
>
>Changing the backing model for t:columns sounds like the way to go.  
>You're going to have to work through whatever bugs that might entail
>though.   At what point in the jsf lifecycle are you trying to change
>the column model?  I'd say you can only change it in invoke
>application.   Changing it before updateModel or after renderResponse
>is probably going to fail because other code depends on those column
>numbers remaining constant.
>
>
>  
>


Re: myFaces and dynamic table model

Posted by Mike Kienenberger <mk...@gmail.com>.
On 1/17/06, Andreas Zeller - zit-systems <an...@zit-systems.de> wrote:
>  Thanks for the quick reply. I already tried that, unfortunately I just get
> empty columns, with not text at all, it doesn't actually remove the column.

Yeah, you're right.  That'd leave empty columns

>  I'd be really glad if there were some kind of a straight forward example.
>
>  Someone must have done something like this by now, hasn't anyone?

I don't think so.  It was considered pretty innovative to have the
ability to have the number of columns be dynamic.   I haven't heard of
anyone trying to add or remove columns afterward yet.

Changing the backing model for t:columns sounds like the way to go.  
You're going to have to work through whatever bugs that might entail
though.   At what point in the jsf lifecycle are you trying to change
the column model?  I'd say you can only change it in invoke
application.   Changing it before updateModel or after renderResponse
is probably going to fail because other code depends on those column
numbers remaining constant.

Re: myFaces and dynamic table model

Posted by Andreas Zeller - zit-systems <an...@zit-systems.de>.
Hey Mike,

Thanks for the quick reply. I already tried that, unfortunately I just
get empty columns, with not text at all, it doesn't actually remove the
column.

I'd be really glad if there were some kind of a straight forward example.

Someone must have done something like this by now, hasn't anyone?

Andreas

Mike Kienenberger wrote:

>Perhaps instead of setting rendered=false for your column, try setting
>it for the component inside your column.
>
>On 1/17/06, Andreas Zeller - zit-systems <an...@zit-systems.de> wrote:
>  
>
>>Hi there,
>>
>>I have been working with myFaces for the past few weeks and tried to
>>implement a product management tool.
>>
>>Works as follows:
>>
>>It displays and html table with several columns, that should as well be
>>removable and movable. I managed to implement sorting with
>>commandSortHeader and inline-editing, using the column Tag.
>>
>>But I am a little confused using the columns tag. How can I, for
>>instance, set a single column not rendered? If I set the rendered
>>attribute, I thought it might affect only a single column, but the
>>moment I set the rendered attribute, it disable the entire set of columns.
>>
>>Anyway, I now decided to remove the columns from the model and remove
>>the data instead of disabling them, but somehow I now get an
>>IndexOutOfBoundsException that I didn't manage to get rid of yet.
>>
>>My question would be, if anybody already has such a table model as a
>>reference. I already took a look at the examples at irian.at, but the
>>only dynamic model doesn't actually move and remove columns but fill
>>them dynamically with random numbers, not exactly with values.
>>
>>If anyone has an example for that, I'd be glad if he or she might want
>>to share it with me.
>>
>>Andreas
>>
>>    
>>
>
>
>  
>


Re: myFaces and dynamic table model

Posted by Mike Kienenberger <mk...@gmail.com>.
Perhaps instead of setting rendered=false for your column, try setting
it for the component inside your column.

On 1/17/06, Andreas Zeller - zit-systems <an...@zit-systems.de> wrote:
> Hi there,
>
> I have been working with myFaces for the past few weeks and tried to
> implement a product management tool.
>
> Works as follows:
>
> It displays and html table with several columns, that should as well be
> removable and movable. I managed to implement sorting with
> commandSortHeader and inline-editing, using the column Tag.
>
> But I am a little confused using the columns tag. How can I, for
> instance, set a single column not rendered? If I set the rendered
> attribute, I thought it might affect only a single column, but the
> moment I set the rendered attribute, it disable the entire set of columns.
>
> Anyway, I now decided to remove the columns from the model and remove
> the data instead of disabling them, but somehow I now get an
> IndexOutOfBoundsException that I didn't manage to get rid of yet.
>
> My question would be, if anybody already has such a table model as a
> reference. I already took a look at the examples at irian.at, but the
> only dynamic model doesn't actually move and remove columns but fill
> them dynamically with random numbers, not exactly with values.
>
> If anyone has an example for that, I'd be glad if he or she might want
> to share it with me.
>
> Andreas
>

Re: myFaces and dynamic table model

Posted by Andreas Zeller - zit-systems <an...@zit-systems.de>.
Hi Simon,

I am already using the columns tag. I'm just not getting my model to do
what I want to do. I'd be glad to have a look at your renderer. Would
probably be a good idea to try something else.

You mentioned using the columns tag. If you have a simple example for
exactly that purpose which doesn't use a custom renderer but a sample
backing bean for the columns tag, that'd be like perfect.

I have absolutely no clue how to get the column order back into the view
without messing up the entire model, without using dummy values and so
on. I would just like to store the order and redraw the model.

Next step will be to access ONE row for editing. I hope, at least that
is going to be easier...

Andreas

Simon Kitching wrote:

>On Tue, 2006-01-17 at 21:20 +0100, Andreas Zeller - zit-systems wrote:
>  
>
>>Hi there,
>>
>>I have been working with myFaces for the past few weeks and tried to
>>implement a product management tool.
>>
>>Works as follows:
>>
>>It displays and html table with several columns, that should as well be
>>removable and movable. I managed to implement sorting with
>>commandSortHeader and inline-editing, using the column Tag.
>>    
>>
>
>I've implemented exactly that, with a "picklist" popup dialog to allow
>the user to select which columns are shown, and in which order.
>
>It's not possible to do this with the standard datatable, however. I
>wrote a custom subclass of t:dataTable which adds attribute
>"columnOrder". A custom renderer then filters the columns seen by the
>standard renderer.
>
>  
>
>>But I am a little confused using the columns tag. How can I, for
>>instance, set a single column not rendered? If I set the rendered
>>attribute, I thought it might affect only a single column, but the
>>moment I set the rendered attribute, it disable the entire set of columns.
>>    
>>
>
>Yep. That approach doesn't work (at least I spent a lot of time on it,
>and didn't find any way to just hide a column).
>
>  
>
>>Anyway, I now decided to remove the columns from the model and remove
>>the data instead of disabling them, but somehow I now get an
>>IndexOutOfBoundsException that I didn't manage to get rid of yet.
>>    
>>
>
>That doesn't work; removing columns has all sorts of nasty internal
>implications for the data table component. However a custom Renderer can
>effectively do this by overriding the getChildren and getChildCount
>methods to "filter out" the unwanted columns.
>
>  
>
>>My question would be, if anybody already has such a table model as a
>>reference. I already took a look at the examples at irian.at, but the
>>only dynamic model doesn't actually move and remove columns but fill
>>them dynamically with random numbers, not exactly with values.
>>    
>>
>
>I've got permission to contribute this code to MyFaces, but not enough
>time to do the actual integration just now. I can send you the code,
>though.
>
>  
>
>>If anyone has an example for that, I'd be glad if he or she might want
>>to share it with me.
>>    
>>
>
>An alternative is to use the t:columns component instead of normal
>columns, ie have a table with just one child: a t:columns. This then
>allows you to define everything very dynamically though it does move the
>definition of what columns exist into the backing bean rather than being
>in the JSP page.
>
>Regards,
>
>Simon
>
>
>
>
>  
>


Re: myFaces and dynamic table model

Posted by Simon Kitching <sk...@apache.org>.
On Tue, 2006-01-17 at 21:20 +0100, Andreas Zeller - zit-systems wrote:
> Hi there,
> 
> I have been working with myFaces for the past few weeks and tried to
> implement a product management tool.
> 
> Works as follows:
> 
> It displays and html table with several columns, that should as well be
> removable and movable. I managed to implement sorting with
> commandSortHeader and inline-editing, using the column Tag.

I've implemented exactly that, with a "picklist" popup dialog to allow
the user to select which columns are shown, and in which order.

It's not possible to do this with the standard datatable, however. I
wrote a custom subclass of t:dataTable which adds attribute
"columnOrder". A custom renderer then filters the columns seen by the
standard renderer.

> 
> But I am a little confused using the columns tag. How can I, for
> instance, set a single column not rendered? If I set the rendered
> attribute, I thought it might affect only a single column, but the
> moment I set the rendered attribute, it disable the entire set of columns.

Yep. That approach doesn't work (at least I spent a lot of time on it,
and didn't find any way to just hide a column).

> 
> Anyway, I now decided to remove the columns from the model and remove
> the data instead of disabling them, but somehow I now get an
> IndexOutOfBoundsException that I didn't manage to get rid of yet.

That doesn't work; removing columns has all sorts of nasty internal
implications for the data table component. However a custom Renderer can
effectively do this by overriding the getChildren and getChildCount
methods to "filter out" the unwanted columns.

> 
> My question would be, if anybody already has such a table model as a
> reference. I already took a look at the examples at irian.at, but the
> only dynamic model doesn't actually move and remove columns but fill
> them dynamically with random numbers, not exactly with values.

I've got permission to contribute this code to MyFaces, but not enough
time to do the actual integration just now. I can send you the code,
though.

> 
> If anyone has an example for that, I'd be glad if he or she might want
> to share it with me.

An alternative is to use the t:columns component instead of normal
columns, ie have a table with just one child: a t:columns. This then
allows you to define everything very dynamically though it does move the
definition of what columns exist into the backing bean rather than being
in the JSP page.

Regards,

Simon