aspose file tools*
The moose likes JSF and the fly likes insert a new row in a datatable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "insert a new row in a datatable" Watch "insert a new row in a datatable" New topic
Author

insert a new row in a datatable

asmaa kellal
Greenhorn

Joined: May 22, 2011
Posts: 18
hello

I have a problem with the use of a datatable in jsf page.I use datatable to introduce the values ​​of a product (for example reference...ect) and I have a button that allows me to insert a new row but when I click the button a line will be added but with the contents of the previous line more if I add 3 lines next time when I compile I find these 3 lines with their contents

this is my bean






my page jsf





question 1 :how to initialize my list so I can get an empty table
question2: how to get a new empty row

can you help me please
thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16228
    
  21

JSF2 changed things a little and someday I'll even read up on the details. But in JSF1, a dataTable could NOT directly reference a collection object as its model. You HAD to front ("wrap") the collection with a JSF DataModel object. That's because extra context not part of the actual data is required to properly render a dataTable and track any command objects (buttons and links) rendered within its rows.

JSF2 can automatically construct that DataModel for you in certain simple cases, I understand, but apparently you're running up on one of the cases that the automated mechanism doesn't do very well.

If you construct a DataModel as a property of your backing bean, use the setWrappedData method (or wrapping DataModel constructor) to wrap your List, then reference the datamodel property in your dataTable tag instead of referencing the List directly, that should make it happier. To add rows, just add them to the list, which you can either continue to keep as a distinct property (you no longer need a public "get" method) or you can pull it from the datamodel using the getWrappedData() method. Either way works.

And, of course "myBean" has to be session scope or greater for JSF1, View scope or greater for JSF2. Request Scope datamodels get destroyed and re-created on each request/response cycle and they lose critical information when that happens.


Customer surveys are for companies who didn't pay proper attention to begin with.
asmaa kellal
Greenhorn

Joined: May 22, 2011
Posts: 18
Hello
could you give me an example so that I can better understand

how use etWrappedData method in backing bean
show me how modify my program to solve this problem if it is possible
please help me more
thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16228
    
  21

asmaa kellal wrote:Hello
could you give me an example so that I can better understand

how use etWrappedData method in backing bean
show me how modify my program to solve this problem if it is possible
please help me more
thanks


I recommend getting a good book on JSF. You might also want to google for "JSF for nonbelievers", which is an old, but very useful introduction to JSF in 4 parts by Rick Hightower written up at IBM DeveloperWorks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: insert a new row in a datatable