File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes How to connect the value attribute of a form to properties of a entity? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to connect the value attribute of a form to properties of a entity?" Watch "How to connect the value attribute of a form to properties of a entity?" New topic
Author

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

Mikel Martin
Greenhorn

Joined: Nov 15, 2012
Posts: 8
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

Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1089
    
  10

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.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Mikel Martin
Greenhorn

Joined: Nov 15, 2012
Posts: 8
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?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

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.


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 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

Joined: Jun 25, 2001
Posts: 16250
    
  21

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to connect the value attribute of a form to properties of a entity?