Thanks for your quick response. I will try the 2nd approach. The first
approach, I am also aware of, is not acceptable as I try to avoid
Servlet API in my bean class.
_____
From: Andrew Robinson [mailto:[EMAIL PROTECTED]
Sent: Tuesday, January 08, 2008 12:09 PM
To: MyFaces Discussion
Subject: Re: How to distinguish between Form loading and
submiting in JSF?
Not sure about a way with portlets, but this should work with a
servlet environment:
"POST".equals(((HttpServletRequest)FacesContext.getCurrentInstance().get
ExternalContext().getRequest()).getMethod())
Note that all command* components post, so this will not tell
you if the page is new or not.
Another way is to store an attribute in the UIViewRoot during
rendering. If it is present, it is the 2nd (or more) time that the page
has been renderer, and if it is not set then it is the first.
FacesContext.getCurrentInstance().getViewRoot().getAttributes().get("myp
roperty") != null
...
FacesContext.getCurrentInstance().getViewRoot().getAttributes().put("myp
roperty", true)
-Andrew
On Jan 8, 2008 9:57 AM, Zheng, Xiahong <[EMAIL PROTECTED]>
wrote:
Hi all,
I have a form that is wired with a backing bean. On the
initial loading,
I need to load the backing properties from the DB to be
displayed on the
page, then persist into the DB on submission after user
edited the form.
I only want to preload the bean from DB on the initial
form loading not
on the form submission. Is there a way for the backing
bean to know
whether it is created as a result of initial request or
a form submit so
it can act accordingly.
Thanks,
Xiaohong