wood burning stoves 2.0*
The moose likes JSF and the fly likes how to send datatable column value which contains array onclicking of that column, to javascript? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "how to send datatable column value which contains array onclicking of that column, to javascript?" Watch "how to send datatable column value which contains array onclicking of that column, to javascript?" New topic
Author

how to send datatable column value which contains array onclicking of that column, to javascript?

prasad kakani
Ranch Hand

Joined: Jul 15, 2008
Posts: 59
Hi Techies,

I nearly spent 3 days to find the ways to do an expand / collapse table using jsf2.0.tags.
But am not able to do that. So i have implemented using core html tags with jsf data table .But dont know how to pass the data table column which contains an array thru onclick function. Please ,kindly requesting you that ,how this can be done?



Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Dear Prasad,
What do you mean by passing an array? On clicking you must be passing a specific value. Why are not using some JSF 2 specification like Primefaces
or Richfaces, you life will be a lot more easier. Can you elaborate your problem, so that i can help.
BR,


Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950
    
  19

Prithvi Sehgal wrote:Dear Prasad,
What do you mean by passing an array? On clicking you must be passing a specific value. Why are not using some JSF 2 specification like Primefaces
or Richfaces, you life will be a lot more easier. Can you elaborate your problem, so that i can help.
BR,


I think that this question is a semi-duplication of this question: http://www.coderanch.com/t/579983/JSF/java/send-array-xhtml-onclick-funtion

If I read it correctly, Prasad basically want to do the dreaded table-within-a-table thing.


Customer surveys are for companies who didn't pay proper attention to begin with.
prasad kakani
Ranch Hand

Joined: Jul 15, 2008
Posts: 59

Thanks for your reply prithvi and Tim.

Basically i would like to create an expandable row datatable. We dont go with rich faces or primefaces or any apis as we decided to do with plain jsf2.0. even not in jquery. Exact requirement is like this. The other post what Tim said is mine only.

I need to have a table with 4 columns. among them , the first column is boolean check box and second one is expandable buttonimage with text, and third and fourth is nothing to display. When a button is clicked of any row, a new row created under that row with list values of second column.

Please can you please help me out.?

REgards,
Prasad.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950
    
  19

If you want to literally replicate all or part of a row, that's fairly easy. If you wanted the row to add child rows to an inner table, that's a lot harder.

To replicate a row, use the getRowIndex() method on the table's DataModel object to determine which row to copy and use that to grab the row in question (or use getRowData()). Clone as much of the row data as you wish, then insert the cloned row at position rowIndex+1 of the DataModel's wrapped data. This works for indexable datamodels such as ListDataModel and ArrayDataModel.
prasad kakani
Ranch Hand

Joined: Jul 15, 2008
Posts: 59

Hi Tim,

if you elabarate through code this, that would be a great help to me. where i am failing to understand is onclick of second column of row how to call backing bean which has function like populatedatatable(), in which we will get the selected row index and add the row with the list of values.

Thanks
Venkat
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950
    
  19

You don't use "onclick". That's a client-side (JavaScript) function. You want a server-side action:


This is only a model and is not complete nor (probably) fully correct.

In the backing bean (myBean):


Again, working code may vary slightly, but this is basically how it goes.
prasad kakani
Ranch Hand

Joined: Jul 15, 2008
Posts: 59

Thank you soo much Tim for your great help..

There is one doubt here i.e instead of command button , can't i use image [+] or [-] to expand or collapse in te second column of any row? on click of this [+] image on that row, the datatable should be populated and should be inserted below that clicked row and image should be changed to [-].

Can you please suggest how this can be done using javascript?

Thanks
Venkat.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950
    
  19

If you want data that's stored on the server to appear and disappear, you either have to send it to the client from the server as part of the initial page display or you have to make an on-demand (AJAX) request to the server. No amount of JavaScript can magically make server data appear on the client without contacting the server.

If you want on-demand fetch and display, you'll need AJAX code to pull it from the server and DOM-manipulating code to display it. I'd prefer a good support library such as jQuery over brute-force vanilla JavaScript, but that's up to you.
prasad kakani
Ranch Hand

Joined: Jul 15, 2008
Posts: 59
Thank you soo much Tim for your great help,

i am able to achieve this row expansion. I am using command button as it has an attribute of img. But i have one doubt. In the code you mentioned what is the point of cloning the row and how to get the complete list of rows in a datatable at one go.? Can you please elabarate bit more abt ListDataModel?

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950
    
  19

I don't actually know if that is what you wanted after some of the later questions you asked.

In MVC, you don't do logic in the View. Instead, the View shows what's in the model. So if you wanted to copy a row in the table, you'd copy the corresponding Row Model object in the Table Model, then update the View based on the updated Model.
prasad kakani
Ranch Hand

Joined: Jul 15, 2008
Posts: 59
Hi Tim,

With your help i did almost done with row exansion . But I got stuck up in row expansion of a table while displaying the images .The problem is, when i click [+] image button(command button) column in a row , a new row is getting added , and also displayed in page with changed image [-]. but this is happening for all the rows. Row expansion is happeing for that perticuler row, but all rows image is getting changed. I could not able to set image to the selected command button . How this can be done..?

Here is my code in

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to send datatable column value which contains array onclicking of that column, to javascript?
 
Similar Threads
Putting a ResultSet into an Array
Question on table heading and table columne alignment
JTable help needed.
2d arrays
2d arrays