jsf datatable select single row

I'm using Sun Java Studio Creator 2 Update 1 in my project. I use the datatable component (bound to database table) and need to provide the single row selection facility. I used radiobuttons in one column to enable this. The creator had inserted the following javascript in the ui:table tag.

function initAllRows() {
  var table = document.getElementById("form1:tblSpsUser");
  table.initAllRows();
}
 Then I inserted the attached code snippet in my bean class.
When I run the the application the radio selection works (I can select a single radio button). But it doesn't highlight the selected row and it also gives the following error message.

Error Message:
Line: 111
Char: 3
Error: 'null' is null or not an object
URL: http://localhost:29080/sps_sc/

I can't find what the problem is.
Can anyone help me please?

Than You
Matara
private TableSelectPhaseListener tableSelectPhaseListener = new TableSelectPhaseListener();
    
    public void setSelected(Object object) {
        RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");
        if (rowKey != null) {
            tableSelectPhaseListener.setSelected(rowKey, object);
        }
    }
    
    public Object getSelected() {
        RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");
        return tableSelectPhaseListener.getSelected(rowKey);
    } 
    
    public Object getSelectedValue() {
        RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");
        return (rowKey != null) ? rowKey.getRowId() : null;
    }
    
    public boolean getSelectedState() {
        RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");
        return tableSelectPhaseListener.isSelected(rowKey);
    }

Open in new window

mkharis15Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mohammedfCommented:
on the radio button event type this:

TableRowDataProvder trp = (TableRowDataProvder)getBean("currentRow");
// trdp is something like pointer to the selected row ( radio button)
// and u ca get all values of this recored using .getValue("fieldName");

Open in new window

0
mkharis15Author Commented:
In which radio button event should I put this ? I tried it on "onChange" and "onClick". didn't work.

Matara
0
mohammedfCommented:
not in onChange ,,, not in onClick
right click on the radio Button ,, then click event change listener, then the code window will open ,, then writhe that code
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

mkharis15Author Commented:
thanks for your reply.
I checked in both "Sun Java Studio Creator 2 Update 1" and "netbeans 6". But it doesn't show "event change listener" when rightclick on radiobutton. i've attched a screenshot. I'm using "Sun Java Studio Creator 2 Update 1" in my project. I'm using 2 datatables in the page.

Thanks
Matara
radio.jpg
0
mohammedfCommented:
thanks for the picture
click ( Edit Event Handler ) then choose value changed listener then it will open the code window.
0
mkharis15Author Commented:
I'll only be able to try this on comming tuesday (05/02/2008) and let u know the resuls then.

Thank you
matara
0
mkharis15Author Commented:
Hi,
I tried it. But it didn't work.
I think the problem is some where else.
I tried a new page putting two tables in a LayoutPanel. I put the following javascripts in two tables in the JSP (table names "matara" and "suresh").
function initAllRows() {
  var table = document.getElementById("form1:matara");
  table.initAllRows();
}

function initAllRows() {
  var table = document.getElementById("form1:suresh");
  table.initAllRows();
}

Then added,
selected="#{UserManager_1_1.selectedState}" in tableRowGroup tag
onClick="setTimeout('initAllRows()',0)" selectId="radioButton1"  in tableColumn tag
name="radioButton1" selected="#{UserManager_1_1.selected}" selectedValue="#{UserManager_1_1.selectedValue}" in radioGroup tag
for table matara and

selected="#{UserManager_1_1.selectedState1}"  in tableRowGroup tag
onClick="setTimeout('initAllRows1()',0)" selectId="radioButton2" in tableColumn tag
name="radioButton2" selected="#{UserManager_1_1.selected1}" selectedValue="#{UserManager_1_1.selectedValue1}" in radioGroup tag
for table surash

Then added the following codes in the bean.

    private TableSelectPhaseListener tableSelectPhaseListener = new TableSelectPhaseListener();
   
    public void setSelected(Object object) {
//        RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");
//        if (rowKey != null) {
//            tableSelectPhaseListener.setSelected(rowKey, object);
//        }
    }
   
    public Object getSelected() {
//        RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");
//        return tableSelectPhaseListener.getSelected(rowKey);
        return null;
    }  
   
    public Object getSelectedValue() {
//        RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");
//        return (rowKey != null) ? rowKey.getRowId() : null;
        return null;
    }
   
    public boolean getSelectedState() {
//        RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");
//        return tableSelectPhaseListener.isSelected(rowKey);
        return false;
    }
   
    private TableSelectPhaseListener tableSelectPhaseListener1 = new TableSelectPhaseListener();
   
    public void setSelected1(Object object) {
        RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");
//        if (rowKey != null) {
//            tableSelectPhaseListener.setSelected(rowKey, object);
//        }
    }
   
    public Object getSelected1() {
//        RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");
//        return tableSelectPhaseListener.getSelected(rowKey);
        return null;
    }  
   
    public Object getSelectedValue1() {
//        RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");
//        return (rowKey != null) ? rowKey.getRowId() : null;
        return null;
    }
   
    public boolean getSelectedState1() {
//        RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");
//        return tableSelectPhaseListener.isSelected(rowKey);
        return false;
    }

Then It works fine.

Then  I opened  the comments in first for methods and removed the unnecessary returns (i included when commenting the code).

Then it gives the error
"null" is null or not an object.  at the javascript line  table.initAllRows();

Then I changed second javascript function name to   table.initAllRows1();

Now it works fine. I used a message group to verify that the correct selected row id is returned for each table.

But I'm still not convinced about what's happening.
If possible help me to understand what's happening.

Thank you very much for your help.

Matara
0
mohammedfCommented:
im not sure what exactly is going with ur code
here is a nice blog ,, u can find many things inside it
http://blogs.sun.com/divas/entry/radio_buttons_in_tables
and here is a nice one
http://blogs.sun.com/winston/category/Creator

hope u will find ur solution in one of them,
and keep me updated whit whats happened with u
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mkharis15Author Commented:
Thanks a lot for your help.
The code is working fine now. But certain behaviors are still not clear to me.

Thank you.

Matara
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Applications

From novice to tech pro — start learning today.