• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF portlet

 
Zuochao Liao
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I use JSF and portlet in my application. In my first page, I need to get product price from the database (using DAO) and show the price in the Page, then the user can update the old price and submit the new price.

I want to call the DAO and get product info (include price), put in a bean and store the bean in the session

My question is for the initial display page, which way is better to trigger the invoking of DAO?
1. Invoke the DAO code in the doView method?
2. Invoke the DAO code in the getPrice() method in the JSF pagecode?
The disadvantage for this way is:
The first phase of JSF life cycle(Restore view) will invoke the getPrice() code unexpected, it makes a extra DAO call

Any suggestion?

Thanks in advance.

George
 
Zuochao Liao
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The workflow is:

Init display page (Display product information including the old price, only show status=A record)
--> The User updates price without entering any key (product no.)
--> Click submit button
--> Invoke DAO, update database and change product status from A to B,
reselect the database (only show status=A). Since the status has bean changed from A to B, the old/new price will not be display again.


The related JSF managed bean code is:

ArrayList getProductBean(){

productBean = (ArrayList) sessionScope
.get("productBean");

boolean isFirstTime = (productBean== null);

if (isFirstTime) {
invoke Dao...
}
}

The question is the first phase of JSF life cycle (Restore view) will invoke the getPorductBean() code unexpected, it makes a extra DAO call if I don't cache productBean in the session. For this case, it's ok to cache the bean in the session. I don't always want cache the bean in the session for other case to get around the JSF life cycle(Restore view) invoking getPorductBean() unexpected issue.

Cheers,

George
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic