Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javascript in JSF

 
selvakumar Thiyagarajan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
i have a JSF datatable and few fields below the table. Also i have a [Save] button with backing bean.My requirement is i should enter the values in those fields and on click of Save, the values should be stored in DB and the Datatable should be updated. Without the Onclick event, datas are stored in Database. if i include the script i am not even able to save the data.

Can any one suggest an idea to update the Datatable as well Data Base(Back end) on click of Save button? Thanks in advance,.


Sample code:

 
Srini Mutpur
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why you need onclick event... what exactly you are trying to do with the onclick javascript function... Could please elaborate ?
 
selvakumar Thiyagarajan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
on click event generates a new value in one of those fields below the grid. Other feilds are entered manually. So, the newly generated value should be updated in the datatable as well as Database.

Also, i am experiencing one more issue. If the click the Save button, the newly generated value is refreshed,i.e. it is cleared.
Any suggestions?
 
Srini Mutpur
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Are you using Rich faces, if yes you can <a4j:jsFunction> or other <a4j: > action mehtods so that you can update dynamically without refreshing the page.

Also, i am experiencing one more issue. If the click the Save button, the newly generated value is refreshed,i.e. it is cleared.
Does the newly generated value is mapped to any one of the bean property ?

Bind the each input text field with one bean property so that on form submit values will be updated to the bean and the values wont be cleared.

Hope it may solve your problem. Let me know if you have any confusion.

Thanks
Srini
 
selvakumar Thiyagarajan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Srini,

"Bind the each input text field with one bean property so that on form submit values will be updated to the bean and the values wont be cleared. "




i am using a backing bean for all the feilds. If i use <h:inputText> the value is not getting cleared. Whereas if i use, <hutputText> the value is getting cleared on click of Save. Any idea? Any idea to update the DataTable using Javascript. i am not using RichFaces.
 
Tim Holloway
Saloon Keeper
Posts: 18303
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The datatable is the View of the the Model that resides on the server, so there's an inherent conflict there. You want to update server-based data without notifying the server.

Plus, the core JSF doesn't have any support for JavaScript over and above what raw HTML has. That's why JS/AJAX add-ons such as RichFaces and IceFaces are so popular.
 
Smitha H Rao
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need to add/delete and update operations on datatable.

Refer the article:
http://www.skill-guru.com/blog/2009/08/20/edit-delete-and-clear-records-using-jsf-datatable/


Hope this helps
 
Jennylyn Fernandez
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just add a return in the onclick event of your Javascript. Return true if you want it to do the action, otherwise return false.
So if you want to call the action after the JavaScript function, your code for the <h:commandButton> should be like this:



 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic