Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Storing in database with a AJAX form

 
Mikel Martin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18214
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mikel Martin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18214
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic