Thanks, that worked. 

-----Original Message-----
From: Simon Kitching [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 08, 2008 12:25 PM
To: MyFaces Discussion
Subject: Re: How to distinguish between Form loading and submiting in
JSF?

If you are using JSF1.2, then I believe this will tell you whether this
is a return to an existing view (ie not the first render of a view):

FacesContext.getRenderKit().getResponseStateManager().isPostBack().

Regards, Simon

---- Andrew Robinson <[EMAIL PROTECTED]> schrieb:
> 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
> >


Reply via email to