Forums Register Login

insert a new row in a datatable

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
 

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 just had the craziest dream. This tiny ad was in it.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 7285 times.
Similar Threads
One-To-Many Child Objects Not Rendering
My binding with datatable give me null ate the backing bean, do i miss some thing
Input row select on data table does not get called
Dynamic Component in JSF
h:dataTable binding => duplicate ID
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 12:05:09.