Yes, phase listener doesn't seem like the place to handle it.

How many submit buttons do the forms have?  It'd seem like you'd want
to do this in the action or actionListener for each of the UICommands
instead of in a phase listener.

If you're going to use a phase listener, you'll need to determine
which form was submitting.   Don't know how that's done off the top of
my head, but you could set a breakpoint on an action and see how
things got there.


On 8/1/06, Tom Innes <[EMAIL PROTECTED]> wrote:
Thanks for the suggestion Matthias,

Unfortunately that is exactly what I was doing.

My suspicion is that since

countryQBE is a Managed Property of countryForm and
countryForm is a Managed Property of stateForm

that all three Phase Listeners fire.  Unfortunately I don't see a way to
distinguish between them. Does anybody know of a way?

Tom


-----Original Message-----
From: Matthias Fischer [mailto:[EMAIL PROTECTED]
Sent: Tuesday, August 01, 2006 1:06 PM
To: MyFaces Discussion
Subject: Re: PhaseListener/SetFocus Question

JavaServerFaces in Action mentions on page 437 that you can register a
phase listerner with a bean. The example shows a bean that refreshes a
list before phase RENDER_RESPONSE. Maybe this helps:

public class MyBean() {

public MyBean() {

LifecycleFactory lifecycleFactory = (LifecycleFactory)
FactoryFinder.getFactory(FactoryFinder.LIFECYLE_FACTORY);
Lifecycle lifecycle =
lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
lifecycle.addPhaseListener(
new PhaseListener() {

   public void beforePhase() {
      refreshList();
  }

  public void afterPhase() {
  }

   publid PhaseId getPhaseId() {
      return PhaseId.RENDER_RESPONSE;
  }
});

 protected void refreshList() {
 ...
}
...
}


Tom Innes wrote:
> I have a question on how best to handle focus when an error occurs.
>
> I am currently using the Sandbox focus component and have implemented a
> PhaseListener on my backing beans to set focus to the first input
component
> that has a message associated with it. On each of my backing beans I have
a
> setFocusId and a getFocusId Method.
>
> Consider the following Example
>
> Backing Bean
> CountryQBE
>  - getCode
>  - setCode
>  - getName
>  - setName
>  - setFocusId
>  - getFocusId
>
> CountryForm
>  - getCode
>  - setCode
>  - getName
>  - setName
>  - setFocusId
>  - getFocusId
>
>
> StateForm
>  - getCode
>  - setCode
>  - getName
>  - setName
>  - setFocusId
>  - getFocusId
>
> Say as a Result of Pressing a command button on the CountryForm an Error
> occurs on the nameField.  When this happens the PhaseListener Fires on all
> three backing beans and sets the FocusId to the nameFieldId.
>
> Thus the CountryQBE, CountryForm and StateForm backing beans all have
their
> focusId property set to nameFieldId.
>
> Is there any way to limit the phase listener to only fire for the current
> form that it is processing?
>
> Tom
>
>
>
>



Reply via email to