You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Mike Kienenberger <mk...@gmail.com> on 2005/04/28 23:23:05 UTC

Creating a HtmlDataTable(like) with a dynamic number of columns and rows

I could use some advice.

I need a component that can have a dynamic number of rows and columns,
preferably with HtmlSelectBooleanCheckbox controls in each cell, and
the control in the cell needs to know what object-backed column it is
in so it can get/set values based on both the row and column.  
Getting the row object is easy enough via HtmlDataTable.getRowData().

Currently, I've written some ugly hack code that subclasses
HtmlSelectBooleanCheckbox to store a "context" column object, reads a
delegate object out of the "valueSource" ValueBinding, and overrides
getValue() to call "valueSource".getValueFor(contextObject).  I also
override saveState/restoreState to save both parameters.

I then manually add columns containing
ContextProvidingHtmlSelectBooleanCheckbox objects to an HtmlDataTable
and set a ValueChangeListener (along with "valueSource") so I can be
notified when the data changes.

And this ugly hack works somewhat.  (I still have the problem where
after the page is redisplayed, the initial values of all of the
Checkboxes are lost, but I'll probably figure out that issue
eventually.)

However, this can't be the best way to handle a variable-width HtmlDataTable.

Is my only other solution to create a custom HtmlDataTable component
from scratch?  Or is there an easier solution I'm overlooking?  
Having a control that supports N x M data manupulation seems like
pretty basic functionality.

Thanks,

-Mike

Re: How to set JSF component properties before JSF is loaded?

Posted by Mike Kienenberger <mk...@gmail.com>.
I'm also a newbie, but I believe you do this as follows:

          <h:dataTable id="table"
binding="#{backingBeanClassInstance.dataTable}"

public class BackingBeanClass
{
    private HtmlDataTable dataTable;
    public HtmlDataTable getRelationshipDataTable()
    {
        return this.dataTable;
    }
    public void setDataTable(HtmlDataTable dataTable)
    {
        this.dataTable= dataTable;
        
        // perform any initialization
        // note that this will be called on every request,
        // so this initialization may have already run once before.
    }
}

I've used this method to dynamically add columns to an empty HtmlDataTable.

On 4/29/05, Lking <lk...@yahoo.com.br> wrote:
> Hi all,
> 
>     As a newbie in JSF and MyFaces I'm wondering how to set some component
> property before JSF page is loaded.
> 
>     I have a page with a DataTable and before it's shown I'd like to change
> some properties like the columns and based on a criteria I'd like to set the
> rendered property of some commandButton as well. There's properties will
> always be the same so I set those in the page itself. But others are going
> to be changed the first time the page is loaded. I tried the constructor but
> it didn't worked out because all components were still "null" and they will
> remain until I invoke the first action.
> 
>     At the moment I only got it changing all my get methods checking... if
> (component == null) component = new HtmlDataTable();.. but it doesn't seem
> to be what I want because all the properties I set in the page were lost...
> 
>     Has anyone a way to solve it?
> 
> Thanks and sorry for my english,
> Lkin.
> 
>

How to set JSF component properties before JSF is loaded?

Posted by Lking <lk...@yahoo.com.br>.
Hi all,

    As a newbie in JSF and MyFaces I'm wondering how to set some component 
property before JSF page is loaded.

    I have a page with a DataTable and before it's shown I'd like to change 
some properties like the columns and based on a criteria I'd like to set the 
rendered property of some commandButton as well. There's properties will 
always be the same so I set those in the page itself. But others are going 
to be changed the first time the page is loaded. I tried the constructor but 
it didn't worked out because all components were still "null" and they will 
remain until I invoke the first action.

    At the moment I only got it changing all my get methods checking... if 
(component == null) component = new HtmlDataTable();.. but it doesn't seem 
to be what I want because all the properties I set in the page were lost...

    Has anyone a way to solve it?


Thanks and sorry for my english,
Lkin. 



Re: Creating a HtmlDataTable(like) with a dynamic number of columns and rows

Posted by Sean Schofield <se...@gmail.com>.
Take a look at the simple examples webapp.  You will find it in the
latest CVS code (or get the latest nightly build.)  There is an
example there that uses x:dataTable, x:columns and x:dataScroller
together.  I believe this achieves what you want.

It took a little while to figure out how these components worked
together but they are pretty powerful.

HTH,

sean

On 4/28/05, Mike Kienenberger <mk...@gmail.com> wrote:
> I could use some advice.
> 
> I need a component that can have a dynamic number of rows and columns,
> preferably with HtmlSelectBooleanCheckbox controls in each cell, and
> the control in the cell needs to know what object-backed column it is
> in so it can get/set values based on both the row and column.
> Getting the row object is easy enough via HtmlDataTable.getRowData().
> 
> Currently, I've written some ugly hack code that subclasses
> HtmlSelectBooleanCheckbox to store a "context" column object, reads a
> delegate object out of the "valueSource" ValueBinding, and overrides
> getValue() to call "valueSource".getValueFor(contextObject).  I also
> override saveState/restoreState to save both parameters.
> 
> I then manually add columns containing
> ContextProvidingHtmlSelectBooleanCheckbox objects to an HtmlDataTable
> and set a ValueChangeListener (along with "valueSource") so I can be
> notified when the data changes.
> 
> And this ugly hack works somewhat.  (I still have the problem where
> after the page is redisplayed, the initial values of all of the
> Checkboxes are lost, but I'll probably figure out that issue
> eventually.)
> 
> However, this can't be the best way to handle a variable-width HtmlDataTable.
> 
> Is my only other solution to create a custom HtmlDataTable component
> from scratch?  Or is there an easier solution I'm overlooking?
> Having a control that supports N x M data manupulation seems like
> pretty basic functionality.
> 
> Thanks,
> 
> -Mike
>