Selection of rows in webuijsf:table?

View: New views
8 Messages — Rating Filter:   Alert me  

Selection of rows in webuijsf:table?

by Ted Byers :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I haven't found this in a FAQ yet, but then maybe I haven't found the right FAQ.

In the properties of an instance of webuijsf:table, I see there are options to add selection and deselection buttons.  This table has a data provider that obtains data from a database, so the numbers of rows varies from instance to instance.  One of the columns, though, is an ID unique within the DB.

There is also a combobox on the page, and the contents of the table are determined by what is selected in the combobox.

I have two questions regarding making this work.

1) How do I tell this JSF table that it is supposed to support selection of rows? (multiple rows, possibly separated by other rows that are NOT selected)  Of course, seleced rows ought to be visually distinct from rows that are not selected.

2) I will be adding a button that basically says tell the session bean about the rows that are selected, so the session bean will know everything that has been selected for each item in the combobox that has ever been selected (within the session that is).  In the event handler, how do I make an array of strings that includes the ID I mentioned about for each row that has been selected?  I DID notice a number of javascript event handlers that could be defined, but I do not see how they would be able to determine which row had been selected or retrieve data from a specific cell, especially when the table's data changes from one time to another (e.g. depending on what item has been selected from the combobox).

A little enlightenment would be appreciated.

BTW: this is with NetBeans 6.1, with the latest JDK+J2EE

Thanks

Ted

Re: Selection of rows in webuijsf:table?

by Rick Fincher :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Ted,

The easiest way to do this is to create a column with a checkbox for the
user to check if they want to select the row.  You can use styles to
change the text or background colors of the selected row if you like.

You bind the selected state of the checkbox to a local boolean
property.  That property's getter reads the state of the checkbox from a
data structure in the Session Bean.

I used a map in the code below.   I also wrote a clearCheckboxes()
method to set the map to false in the session bean.  It's handy to call
that in an !isPostback() conditional if you want to clear all the checks
at first rendering.  You may prefer to have the checks survive until the
next table rendering, so don't clear it in that case.

All the "!clearCheckboxes" logic is from a boolean I created that can be
set in the session bean to clear the checkboxes if the user likes.  That
is separate from the logic above.

See Winston's blog at:
http://blogs.sun.com/winston/entry/multiple_selection_table1

Rick

/**
     * Holds value of property checkBoxSelectChecked.
     */
    private boolean checkBoxSelectChecked;

    /**
     * Getter for property checkBoxSelectChecked.
     * @return Value of property checkBoxSelectChecked.
     */
    public boolean isCheckboxSelectChecked() {
        boolean bVal;
        String sn = (String)
getValue("#{currentRow.value['STOCK_NUMBER']}");

        Boolean isChecked = (Boolean)
getSessionBean1().getCheckBoxSelectedMap().get(sn);

        if (isChecked != null) {
            bVal = isChecked.booleanValue();
            return bVal;
        } else {
            return false;
        }
    }

    /**
     * Setter for property checkBoxSelectChecked.
     * @param certIconVisible New value of property checkBoxSelectChecked.
     */
    public void setCheckboxSelectChecked(boolean b) {
        String sn = (String)
getValue("#{currentRow.value['STOCK_NUMBER']}");

        if (!clearCheckboxes) {
            getSessionBean1().getCheckBoxSelectedMap().put(sn, new
Boolean(b));
        } else {
            getSessionBean1().getCheckBoxSelectedMap().put(sn, new
Boolean(false));
        }
    }


Ted Byers wrote:

> I haven't found this in a FAQ yet, but then maybe I haven't found the right
> FAQ.
>
> In the properties of an instance of webuijsf:table, I see there are options
> to add selection and deselection buttons.  This table has a data provider
> that obtains data from a database, so the numbers of rows varies from
> instance to instance.  One of the columns, though, is an ID unique within
> the DB.
>
> There is also a combobox on the page, and the contents of the table are
> determined by what is selected in the combobox.
>
> I have two questions regarding making this work.
>
> 1) How do I tell this JSF table that it is supposed to support selection of
> rows? (multiple rows, possibly separated by other rows that are NOT
> selected)  Of course, seleced rows ought to be visually distinct from rows
> that are not selected.
>
> 2) I will be adding a button that basically says tell the session bean about
> the rows that are selected, so the session bean will know everything that
> has been selected for each item in the combobox that has ever been selected
> (within the session that is).  In the event handler, how do I make an array
> of strings that includes the ID I mentioned about for each row that has been
> selected?  I DID notice a number of javascript event handlers that could be
> defined, but I do not see how they would be able to determine which row had
> been selected or retrieve data from a specific cell, especially when the
> table's data changes from one time to another (e.g. depending on what item
> has been selected from the combobox).
>
> A little enlightenment would be appreciated.
>
> BTW: this is with NetBeans 6.1, with the latest JDK+J2EE
>
> Thanks
>
> Ted
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Parent Message unknown Re: Selection of rows in webuijsf:table?

by HandyGeek :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Have you seen these two articles?  Hopefully they'll give you some insight:
http://blogs.sun.com/winston/entry/single_selectable_row_table_component
http://blogs.sun.com/divas/entry/using_checkboxes_in_a_table

Best, David
 -------------- Original message ----------------------
From: Ted Byers <r.ted.byers@...>

>
> I haven't found this in a FAQ yet, but then maybe I haven't found the right
> FAQ.
>
> In the properties of an instance of webuijsf:table, I see there are options
> to add selection and deselection buttons.  This table has a data provider
> that obtains data from a database, so the numbers of rows varies from
> instance to instance.  One of the columns, though, is an ID unique within
> the DB.
>
> There is also a combobox on the page, and the contents of the table are
> determined by what is selected in the combobox.
>
> I have two questions regarding making this work.
>
> 1) How do I tell this JSF table that it is supposed to support selection of
> rows? (multiple rows, possibly separated by other rows that are NOT
> selected)  Of course, seleced rows ought to be visually distinct from rows
> that are not selected.
>
> 2) I will be adding a button that basically says tell the session bean about
> the rows that are selected, so the session bean will know everything that
> has been selected for each item in the combobox that has ever been selected
> (within the session that is).  In the event handler, how do I make an array
> of strings that includes the ID I mentioned about for each row that has been
> selected?  I DID notice a number of javascript event handlers that could be
> defined, but I do not see how they would be able to determine which row had
> been selected or retrieve data from a specific cell, especially when the
> table's data changes from one time to another (e.g. depending on what item
> has been selected from the combobox).
>
> A little enlightenment would be appreciated.
>
> BTW: this is with NetBeans 6.1, with the latest JDK+J2EE
>
> Thanks
>
> Ted
> --
> View this message in context:
> http://www.nabble.com/Selection-of-rows-in-webuijsf%3Atable--tp18721092p18721092
> .html
> Sent from the Visual Web - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Selection of rows in webuijsf:table?

by Rick Fincher :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Ted,

Also note:  you don't have to use phaseListeners.

Rick

Ted Byers wrote:

> I haven't found this in a FAQ yet, but then maybe I haven't found the right
> FAQ.
>
> In the properties of an instance of webuijsf:table, I see there are options
> to add selection and deselection buttons.  This table has a data provider
> that obtains data from a database, so the numbers of rows varies from
> instance to instance.  One of the columns, though, is an ID unique within
> the DB.
>
> There is also a combobox on the page, and the contents of the table are
> determined by what is selected in the combobox.
>
> I have two questions regarding making this work.
>
> 1) How do I tell this JSF table that it is supposed to support selection of
> rows? (multiple rows, possibly separated by other rows that are NOT
> selected)  Of course, seleced rows ought to be visually distinct from rows
> that are not selected.
>
> 2) I will be adding a button that basically says tell the session bean about
> the rows that are selected, so the session bean will know everything that
> has been selected for each item in the combobox that has ever been selected
> (within the session that is).  In the event handler, how do I make an array
> of strings that includes the ID I mentioned about for each row that has been
> selected?  I DID notice a number of javascript event handlers that could be
> defined, but I do not see how they would be able to determine which row had
> been selected or retrieve data from a specific cell, especially when the
> table's data changes from one time to another (e.g. depending on what item
> has been selected from the combobox).
>
> A little enlightenment would be appreciated.
>
> BTW: this is with NetBeans 6.1, with the latest JDK+J2EE
>
> Thanks
>
> Ted
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Selection of rows in webuijsf:table?

by TedByers :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you David

Those links are, indeed, quite useful

Cheers,

Ted
HandyGeek wrote:
Have you seen these two articles?  Hopefully they'll give you some insight:
http://blogs.sun.com/winston/entry/single_selectable_row_table_component
http://blogs.sun.com/divas/entry/using_checkboxes_in_a_table

Best, David
 -------------- Original message ----------------------
From: Ted Byers <r.ted.byers@gmail.com>
>
> I haven't found this in a FAQ yet, but then maybe I haven't found the right
> FAQ.
>
> In the properties of an instance of webuijsf:table, I see there are options
> to add selection and deselection buttons.  This table has a data provider
> that obtains data from a database, so the numbers of rows varies from
> instance to instance.  One of the columns, though, is an ID unique within
> the DB.
>
> There is also a combobox on the page, and the contents of the table are
> determined by what is selected in the combobox.
>
> I have two questions regarding making this work.
>
> 1) How do I tell this JSF table that it is supposed to support selection of
> rows? (multiple rows, possibly separated by other rows that are NOT
> selected)  Of course, seleced rows ought to be visually distinct from rows
> that are not selected.
>
> 2) I will be adding a button that basically says tell the session bean about
> the rows that are selected, so the session bean will know everything that
> has been selected for each item in the combobox that has ever been selected
> (within the session that is).  In the event handler, how do I make an array
> of strings that includes the ID I mentioned about for each row that has been
> selected?  I DID notice a number of javascript event handlers that could be
> defined, but I do not see how they would be able to determine which row had
> been selected or retrieve data from a specific cell, especially when the
> table's data changes from one time to another (e.g. depending on what item
> has been selected from the combobox).
>
> A little enlightenment would be appreciated.
>
> BTW: this is with NetBeans 6.1, with the latest JDK+J2EE
>
> Thanks
>
> Ted
> --
> View this message in context:
> http://www.nabble.com/Selection-of-rows-in-webuijsf%3Atable--tp18721092p18721092
> .html
> Sent from the Visual Web - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@visualweb.netbeans.org
> For additional commands, e-mail: users-help@visualweb.netbeans.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@visualweb.netbeans.org
For additional commands, e-mail: users-help@visualweb.netbeans.org

Re: Selection of rows in webuijsf:table?

by TedByers :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you Rick

I found that quite useful.

I have done something similar, which works well for the first time the page is displayed.  However, there is a combobox on the same page that controls the contents of the table.  Every time a different item is selected from that combobox, the table gets completely different contents.

I get the following issue when I select something different from the combobox:

In the Tomcat 6.0.16 output, I see the following:
31-Jul-2008 11:27:44 AM com.sun.faces.lifecycle.LifecycleImpl phase
WARNING: executePhase(PROCESS_VALIDATIONS 3,com.sun.faces.context.FacesContextImpl@1f06804) threw exception
javax.faces.FacesException: /DailyETFreport.jsp(40,154) '#{Sessionbean1.selected}' Target Unreachable, identifier 'Sessionbean1' resolved to null

But I do not see anything in the logs or output related to the session bean not being created or available. In fact, after this error message is produced, I can go back (in the same session) and continue to use the session bean on other pages. My hunch is that the error is due to the contents of the table having been changed. I suspect that in my case, the session bean must somehow be notified that the contents of the table have been changed, the relevant data about selected items then needs to be stored in the session bean (the contents of two of the columns in the table - a ticker symbol and a company name would be enough), and the properties added above reset to appropriate default values.

What do you think?  Am I right?  If so, how do I do this?  If not, what would you suggest.  

I could just attack it brute force style, and put all the data in a single table, losing the combobox.  While that might be manageable while I am testing with about 225 records, we're aiming at handling 7000+ records.  You can imagine what a nightmare that would be from a usability perspective.  I think I may have no options but to use a combination of pagination and a combobox.  So the next question becomes how do you get a table that supports multiple row selection (yes I did use a phaselistener) to play nicely with both pagination AND a combox on the same page when the latter completely changes the contents of the table?  FWIW, the combobox selects records from one table in my DB based on what value the combobox holds.  It is all data from the same table (using s tored procedure that takes a category ID as an argument), and the combobox acts as a kind of filter, as it were, so we don't have to manage ALL that data on the client side at one time.

Thanks

Ted

Rick Fincher wrote:
Hi Ted,

Also note:  you don't have to use phaseListeners.

Rick

Ted Byers wrote:
> I haven't found this in a FAQ yet, but then maybe I haven't found the right
> FAQ.
>
> In the properties of an instance of webuijsf:table, I see there are options
> to add selection and deselection buttons.  This table has a data provider
> that obtains data from a database, so the numbers of rows varies from
> instance to instance.  One of the columns, though, is an ID unique within
> the DB.
>
> There is also a combobox on the page, and the contents of the table are
> determined by what is selected in the combobox.
>
> I have two questions regarding making this work.
>
> 1) How do I tell this JSF table that it is supposed to support selection of
> rows? (multiple rows, possibly separated by other rows that are NOT
> selected)  Of course, seleced rows ought to be visually distinct from rows
> that are not selected.
>
> 2) I will be adding a button that basically says tell the session bean about
> the rows that are selected, so the session bean will know everything that
> has been selected for each item in the combobox that has ever been selected
> (within the session that is).  In the event handler, how do I make an array
> of strings that includes the ID I mentioned about for each row that has been
> selected?  I DID notice a number of javascript event handlers that could be
> defined, but I do not see how they would be able to determine which row had
> been selected or retrieve data from a specific cell, especially when the
> table's data changes from one time to another (e.g. depending on what item
> has been selected from the combobox).
>
> A little enlightenment would be appreciated.
>
> BTW: this is with NetBeans 6.1, with the latest JDK+J2EE
>
> Thanks
>
> Ted
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@visualweb.netbeans.org
For additional commands, e-mail: users-help@visualweb.netbeans.org

Re: Selection of rows in webuijsf:table?

by TedByers :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Here is the next functionality I'd like to manage, if at all possible.

What I'd like to do is add a frame to the page that is tall and narrow, on the right side of the window, and have this frame contain a table with two columns.  The second column would have a chart related to the data in the first column, and the first column would have a table with one column and two rows containing a symbolb in the first row and a name in the scond row; a mini table within a table.

Now, what I would like to see happen is that when nothing is selected in my selection table, this second frame is invisible.  The moment an item is selected, the frame should appear, and remain as long as there is at least one selected item in the select table.  And when an item is selected, the symbol and name in that row ought to be placed in the first column of the next (or first) row in the table in the second frame, and a chart requested from my charting servlet, to be displayed in the second column of the same row in the table in the second frame.

1) Is this possible, without too much pain?
2) Is there a better way to maintain on a page the details of all the items that have been, and remain, selected, regardless of pagination and combobox selection issues?

Thanks

Ted

Parent Message unknown Re: Selection of rows in webuijsf:table?

by HandyGeek :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey Ted,
Have you checked out the Woodstock Wiki yet?  http://wiki.java.net/bin/view/Projects/ProjectWoodstock?skin=print
Sorry, I don't have an answer to your original question, except to point you to this site as another resource..  David

 -------------- Original message ----------------------
From: TedByers <r.ted.byers@...>
>
> Here is the next functionality I'd like to manage, if at all possible.
>
> What I'd like to do is add a frame to the page that is tall and narrow, on
<snip>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...