• 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

How to connect the value attribute of a form to properties of a entity?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to Java Server Faces.

I set a XHTML page with a form in it, using the form component of J.S.F.

On the other hand I set a JPA entity with properties
and a JPA controller generated from that entity.

My question is how I connect the form of the XHTML with the properties of the JPA entity to persist
the data submitted through the form.

I need to invoke the JPA controller methods from the value attribute of the form component?

Could I see a example of the process? FORM COMPONENT -> J.P.A. ENTITY PROPERTIES


Thank you

 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The usual way of doing this is to have a ManagedBean that will be referred in the facelets page via EL.
You can start with the tutorial page to understand how this works.
 
Mikel Martin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the answer.

After some research I see the process of storing data of input components of a form.

A entity class is created -> a session facade is generated for that entity -> a J.S.F. managed bean is created with a reference to the facade through the use of dependency injection
-> a J.S.F. webpage is created with the values of the form component refering to the properties and methods of the J.S.F. managed bean.

But I have still the question of where are the tables generated by the entities.
How can I access those tables to check the information sent through the form?
 
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JPA (ORM) Domain Model entities rarely work well as JSF backing beans. That is because JSF is totally (and deliberately) ignorant of persistent storage mechanisms. And, in particular, JSF lacks the ability to instantiate a backing bean as a result of a database lookup.

JSF backing beans, in fact, are intended to act as GUI View Models, and as such, not really part of the business logic or persistency subsystems. You can, in some cases collapse one or more of those layers into a JSF backing bean (most of us have at least some business logic in there), but the primary function of the backing bean is to serve as the Model in an MVC universe.

While direct access to Domain Model objects is, like I said, not always easy or even possible, you can use JSF backing beans as containers for Domain Model objects, and even present those objects as properties of JSF backing beans, accessible under the same rules as any other POJO objects set as backing bean properties.
 
Mikel Martin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the answer.


As far as I understand, the Managed Bean as part of the View Model donĀ“t access JPA Domain Model but it is injected a session bean that holds public methods to create, edit, remove and find entities. In this indirect way the JSF XHTML can reference entities and hence the database.

Anyway, what I am trying to find is what is the best way in the JavaServer Faces framework, to access or to create a database from the front end (XHTML).
 
Tim Holloway
Saloon Keeper
Posts: 27807
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
What I normally do is use the Spring Framework to inject one or more persistency services into my JSF backing bean - although if you're not a Spring fan, you could also do this the hard way using a Service Locator.

My high-level persistency services provide business-aware transactionally-bounded data service functions on connected sets of Entities. They are, in turn, injected with the lower-level per-table persistency function providers (DAOs doing find and CRUD operations). I'm not presently using EJB for that, but if you are, you can, of course, use Session EJBs where you find it useful.
reply
    Bookmark Topic Watch Topic
  • New Topic