• 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

Javascript in JSF

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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, <h:outputText> the value is getting cleared on click of Save. Any idea? Any idea to update the DataTable using Javascript. i am not using RichFaces.
 
Saloon Keeper
Posts: 27762
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
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.
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:



 
reply
    Bookmark Topic Watch Topic
  • New Topic