Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Basic JSF design question

 
Pinal N Patel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone,

I am very new to JSF and I am having a little hard time designing JSF components.

Basically, my application contains three jsp pages. First is called Entry.jsp which contains a input text field (to enter a name of a person) and two submit buttons ("Get Addr Info" button and "Get Recently Viewed Product" button). Based on the submit button, I have a POJO class that goes and retrieves relevant information for a person typed in the input text field and displays in the appropriate jsp pages (addr.jsp or viewedProduct.jsp).

Now, my question is, Whose responsibility is to retrieve the database information? Is it the backing bean (EntryBean) associated with Entry.jsp? So, this means, I have to call the POJO class from EntryBean to retrieve the Person info from database and populate the associated backing bean for the next view page based on the navigation rule.

OR, Should AddrBean/ViewProductBean retrieve the Person info from db? If yes, Could you please describe/seq diagram on how the flow works?

I really appreciate everyone's input on this.

Thanks in advance!!

OR,
 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've only done little JSF so far, but based on my experience with other MVC web frameworks, I'd strongly consider a third option: another class (some people may call it 'controller class', 'action class', or even 'facade').

So this would end up as follows:

1. class EntryForm:
Stores request parameters that were submitted from entry.jsp
So in entry.jsp you have some input fields such as:
< h:inputText value="#{entryBean.text}" / > ...

2. class AddrView:
Stores data to be shown by the 'address' jsp (e.g. city, street...)
So in addrView.jsp you have some output fields such as:
< h utputText value="#{addView.stree}" / > ...

3. class ProductView:
Stores data to be shown by the 'product view' jsp (e.g. list of products)
So in productView.jsp you have some output fields such as:
< h utputText value="#{productView.price}" / > ...

4. class EntryController :
the only class that holds logic that talks with the database (directly or, preferrable, though another utility class).
This class would hold references to the other beans, and read/update them as required:



Use the following code to make sure entryController methods are called when buttons are clicked:


Now, the only remaining problem is how to make sure that your EntryController actually knows the beans entryForm, addrView, productView..
For this, JSF uses 'injection' technique, which means you need the following lines in your 'faces-config.xml', for 'EntryController' (this tells JSF to call EntryController.setEntryForm() with your 'Entry Form', and similarly for the other bean):



Good luck.
 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, slight correction:
on step 1 ("EntryForm")
I wrote < h:inputText value="#{entryBean.text}" >
It should actually be < h:inputText value="#{entryForm.text}" >
 
Alexander Jesse
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isolate your db-accesses into a service-layer. Each service concentrating on one business-object.

For Cross-object-boundary functionality, write facade-objects.

Objects that travel the layer-boundaries are DTO's (DataTransferObjects).

From your managed beans access either
pure: only facade-objects (needs a few more)
mixed: facade-objects and services

How to find the services? Either use a service-lookup facility or use Spring.

hth
Alexander
 
Pinal N Patel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot guys!!. The information all of you have provided is greatly appreciated.
 
Pinal N Patel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok Guys, I have one more question based on the above postings.

The controller methods are called from action tags in JSP, then the controller gets the data from the backend and populates the form. So, it seems like after retriving the data, controller needs to set the navigation-case values( such as "success", "failure" etc) to determine the next page. Is it a good idea to let the controller decide the navigation case?

Regards,
Pinal.
 
Alexander Jesse
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The controller (as known eg within Struts) is not existant in JSF. You call a managedbean-method which does the usecase-work and then returns the navigation-outcome.

The navigation-outcome can point to different result-pages in dependance from the source-page...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic