• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

insert a new row in a datatable

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
asmaa kellal
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
reply
    Bookmark Topic Watch Topic
  • New Topic