Less than 42 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Rendering database loaded pojo the first time.  RSS feed

 
Chase Bonham
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!