How do I access data in a given column in a selected row in a table?

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

How do I access data in a given column in a selected row in a table?

by Ted Byers :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I followed the example of a table that supports selection of multiple rows in a table provided by Winston Prakash in his blog.

I have a command button with the following handler:

    public String button1_action() {
        String msg = new String("");
        com.sun.data.provider.RowKey[] selectedRowKeys = getTable1().getTableRowGroupChild().getSelectedRowKeys();
        for(int i=0; i< selectedRowKeys.length; i++){
            int rowId = Integer.parseInt(selectedRowKeys[i].getRowId()) + 1;
            //info("Row " + rowId  + " is selected");
            msg += new String("Row " + rowId  + " is selected");
        }
        getSelectionsDisplayTextArea().setText(msg);
        return null;
    }

However, I do not need the integer represented by rowID.  I need the data in the third and fourth columns in each of the selected rows.  I see this data being accessed in the JSP file, but I need to access it from the page bean so I can place the data in a map in the session bean, so it can be used in another page.

I took a look at selectedRowKeys[i], but it did not have any obvious members that seemed likely to provide access to this data.

How do I get at the data from specific columns in each of the selected rows in the table?

Thanks

Ted

Re: How do I access data in a given column in a selected row in a table?

by Rick Fincher :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Ted,

I do something very similar in the following code.  I build a string to
e-mail to somebody when selections are made from a table and the user
asks for more info.  You use the selected rowKeys to pull data from the
dataProvider by the field name in the database.

This is assuming you are using a data provider to populate the table

String stockNum;
        String weight ,color ;
        String message = "";
        RowKey[] rkArray = tableRowGroup1.getSelectedRowKeys();
        RowKey tmpRk;

        for (int i = 0; i < rkArray.length; i++) {
            tmpRk = rkArray[i];

            stockNum = stockDataProvider.getValue("STOCK_NUMBER",
tmpRk).toString();
            weight = stockDataProvider.getValue("WEIGHT", tmpRk).toString();
            color = stockDataProvider.getValue("COLOR", tmpRk).toString();

            message += stockNum + ", " + weight + " pounds, Color: " +
color+ "\n";
        }

        getSessionBean1().setMailMessage(message);
        getSessionBean1().setMailMessageReady(true);

Rick

Ted Byers wrote:

> I followed the example of a table that supports selection of multiple rows in
> a table provided by Winston Prakash in his blog.
>
> I have a command button with the following handler:
>
>     public String button1_action() {
>         String msg = new String("");
>         com.sun.data.provider.RowKey[] selectedRowKeys =
> getTable1().getTableRowGroupChild().getSelectedRowKeys();
>         for(int i=0; i< selectedRowKeys.length; i++){
>             int rowId = Integer.parseInt(selectedRowKeys[i].getRowId()) + 1;
>             //info("Row " + rowId  + " is selected");
>             msg += new String("Row " + rowId  + " is selected");
>         }
>         getSelectionsDisplayTextArea().setText(msg);
>         return null;
>     }
>
> However, I do not need the integer represented by rowID.  I need the data in
> the third and fourth columns in each of the selected rows.  I see this data
> being accessed in the JSP file, but I need to access it from the page bean
> so I can place the data in a map in the session bean, so it can be used in
> another page.
>
> I took a look at selectedRowKeys[i], but it did not have any obvious members
> that seemed likely to provide access to this data.
>
> How do I get at the data from specific columns in each of the selected rows
> in the table?
>
> Thanks
>
> Ted
>  


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