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

Storing in database with a AJAX form

Mikel Martin
Greenhorn

Joined: Nov 15, 2012
Posts: 8
Hi,

I made a form with the AJAX function.
Something like this:

<h:commandButton id="register" value="SEND">
<f:ajax execute="firstName lastName" render="output"/>
</h:commandButton>

I set the entity file, the facade file with the persistence unit and the J.S.F. Managed Bean with
a injection of the facade .

I can send the form resulting in the AJAX efect, nothing is wrong here; but the data of the form is no stored in the database
generated by the entity.

Am I missing something in the command button where the AJAX function is nested?

Thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

JSF has absolutely no database capabilities at all, so that means that you have to supply your own code to do the storing.

Beyond that, something has to invoke that code.

When you provide a SUBMIT button, whether traditional or AJAX it has to be attached to that code. For traditional submits, that would be an action method or (not recommended) action listener. For an AJAX button, you'd attach an AJAX listener method.


Customer surveys are for companies who didn't pay proper attention to begin with.
Mikel Martin
Greenhorn

Joined: Nov 15, 2012
Posts: 8
Thank you.

I have sorted at the moment wit the action attribute in the commandButton that references to a method

in the managed bean whose body holds the facade object and the create method and return a new response page.

I think I need to become clearer about the navigation in J.S.F.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

An AJAX request will not navigate. It is used for updating the current page.

A traditional JSF action method will navigate. It returns a rule name that is used to select which page to display next. If it returns null, the same page is re-displayed. In JSF2, explicit rule names are optional. If the returned value is not an explicitly-defined rule name, JSF will attempt to make a URL out of it and navigate to the page that corresponds to that URL. Being JSF, the URL in the browser location control will lag behind, but that doesn't matter for the purposes of navigation. A "redirect" option can be used in cases where you want to update the browser control, although there is a performance penalty involved.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Storing in database with a AJAX form
 
Similar Threads
made progress with Ajax and JSF 2.0, need help please
JSP Form Help
How to capture enter key?
Can i connect a js file to a database?
h:commandButton + actionListener