aspose file tools
The moose likes JSF and the fly likes Rendering database loaded pojo the first time. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Rendering database loaded pojo the first time." Watch "Rendering database loaded pojo the first time." New topic
Author

Rendering database loaded pojo the first time.

Chase Bonham
Ranch Hand

Joined: Jul 15, 2006
Posts: 50
I need JSF to render a database loaded pojo as opposed to constructing a
blank one.

I have a Person.java pojo and my JSP looks like this.

<f:view>
<h:form id="helloForm">
FirstName: <t:inputText value="#{person.firstName}" />
</h:form>
</f:view>

I want to load a Person pojo from database and display the firstName
as opposed to creating a new Person pojo.

How do I wire the database loading logic with JSF?.
[ October 14, 2006: Message edited by: Chase Bonham ]
Peter Onneby
Greenhorn

Joined: Mar 01, 2006
Posts: 8
Originally posted by Chase Bonham:
I need JSF to render a database loaded pojo as opposed to constructing a
blank one.

I have a Person.java pojo and my JSP looks like this.

<f:view>
<h:form id="helloForm">
FirstName: <t:inputText value="#{person.firstName}" />
</h:form>
</f:view>

I want to load a Person pojo from database and display the firstName
as opposed to creating a new Person pojo.

How do I wire the database loading logic with JSF?.

[ October 14, 2006: Message edited by: Chase Bonham ]


Hi Chase

You could create a managed form bean, HelloForm.java perhaps, which would act as a layer between your Person.java and the JSP.

The HelloForm.java backing bean could have a method, loadPerson() , that gets a database connection and retrieves a Person object. This object should be referenced in HelloForm.

You can then create a navigation rule in faces-config.xml that calls your HelloForm.loadPerson() method when the JSP loads.


Referencing the Person object through the HelloForm would look something like this:

<f:view>
<h:form id="helloForm">
FirstName: <t:inputText value="#{HelloForm.person.firstName}" />
</h:form>
</f:view>

Hope this helps you on the way.

Peter
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Rendering database loaded pojo the first time.
 
Similar Threads
Dynamic Component in JSF
Check box column trouble
Am I misunderstanding the basics of JSF 2.0?
Not able to run simple JSF
JSF Backing Bean