?
Solved

jsf datatable select single row

Posted on 2008-02-01
10
Medium Priority
?
6,570 Views
Last Modified: 2011-10-19
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

0
Comment
Question by:mkharis15
  • 5
  • 4
9 Comments
 
LVL 6

Expert Comment

by:mohammedf
ID: 20796004
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
 

Author Comment

by:mkharis15
ID: 20796164
In which radio button event should I put this ? I tried it on "onChange" and "onClick". didn't work.

Matara
0
 
LVL 6

Expert Comment

by:mohammedf
ID: 20796229
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:mkharis15
ID: 20796747
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
 
LVL 6

Expert Comment

by:mohammedf
ID: 20798203
thanks for the picture
click ( Edit Event Handler ) then choose value changed listener then it will open the code window.
0
 

Author Comment

by:mkharis15
ID: 20803100
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
 

Author Comment

by:mkharis15
ID: 20822486
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
 
LVL 6

Accepted Solution

by:
mohammedf earned 1000 total points
ID: 20824170
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
 

Author Comment

by:mkharis15
ID: 20829704
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.
Suggested Courses

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question