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

Javascript in JSF

selvakumar Thiyagarajan
Greenhorn

Joined: Oct 06, 2008
Posts: 28
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

Joined: Mar 29, 2008
Posts: 24
Why you need onclick event... what exactly you are trying to do with the onclick javascript function... Could please elaborate ?


SCJP 1.5
selvakumar Thiyagarajan
Greenhorn

Joined: Oct 06, 2008
Posts: 28
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

Joined: Mar 29, 2008
Posts: 24

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

Joined: Oct 06, 2008
Posts: 28
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

Joined: Jun 25, 2001
Posts: 16065
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Smitha H Rao
Ranch Hand

Joined: Oct 20, 2007
Posts: 50
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

Free Mock tests Interview questions
Jennylyn Fernandez
Greenhorn

Joined: Sep 24, 2009
Posts: 2
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:



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javascript in JSF