You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jason Vincent <jt...@gmail.com> on 2006/02/14 21:40:33 UTC

Shale: postRender method?

Hi All,

I was wondering if there is an easy way to get a postRender method to
be called in my Shale ViewController.
Is a new Phase Listener the only / best option? Perhaps I can extend a
Shale class to also call a postRender method?

Here is my scenario:
I have the concept of an ErrorEventCollector in the ViewController. 
Basically, the collector is passed around in the model calls to
capture errors during the model execution.  This might include errors
caused by validation checks on the retrieved data from the DB, as well
as any exceptions.  These events can be generated in any phase - init,
validation, application, or render.

In my BaseViewController - I want to have the event collector checked
for any events.  If there are events in the collector, then I want to
create FacesMessages for each event.  I tried putting the check in the
Shale destroy method, but the messages weren't being displayed by the
JSP.  So It seems I need to have this check as the last step in the
render_response phase.

Thanks for any help.
Jason

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Shale: postRender method?

Posted by Craig McClanahan <cr...@apache.org>.
On 2/14/06, Jason Vincent <jt...@gmail.com> wrote:
>
> ok... I got it to show the messages...
>
> I did what you suggested and moved the <h:messages> to the end of my
> page - THANKS!  But the method to convert my ErrorEvents into
> FacesMessages still needed to be called.  So I made it return true and
> set it as the "render" attribute for the messages tag. AHHH!
> It worked, but ewwwww. :)
>
> I could change my design so that the FacesMessages are created
> immediately when the events are added to the collecor.  That would
> eliminate the need for the render attribute.  BUT, I'll need to beg
> for forgiveness from my UI designers when I tell them that the
> <h:messages> tag MUST be at the end of the page.
>
> I guess the original intent of the FacesMessages was to be used during
> the Validation phase. Hmmm.
> Is it a sign of mis-use of the JSF framework if my getter methods in
> the render phase can produce FacesMessages?


I would say yes, that's a misuse.  If your messages represent the generic
concept of validation errors, you should strive to have those messages
created during the Process Validations phase (if it's things that validators
should normally catch), or Invoke Application phase (if its business rule
enforcement like "you cannot claim that user id because it belongs to
someone else').

HMMM.... Perhaps I could override/extend the responseComplete method
> to do my custom stuff first, and then call super.responseComplete???
> Is this a good approach or even possible or even the right method to
> override? It seems like a path to the dark side.


Yes ;-).

Thanks for the help.
> Jason


Craig


On 2/14/06, Craig McClanahan <cr...@apache.org> wrote:
> > On 2/14/06, Jason Vincent <jt...@gmail.com> wrote:
> > >
> > > Hmm... I guess a phase listener wouldn't work for me. From what you
> > > say, it appears that the outcome of the phase is already determined
> > > before the "afterPhase" listener is triggered.
> > >
> > > Is there a another place for me to plug into the steps taken "during"
> > > a phase, that is, before the final steps in the phase are completed?
> >
> >
> > I don't see how that would really help you ... what you seem to be
> needing
> > is that the messages get generated before the <h:messages> component
> itself
> > is rendered.
> >
> > Or at least, I just need the FacesMessages to not get processed until
> > > the last step of the render phase.
> >
> >
> > Put your <h:messages> component last???
> >
> > Thanks,
> > > Jason
> >
> >
> > Craig
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Shale: postRender method?

Posted by Jason Vincent <jt...@gmail.com>.
ok... I got it to show the messages...

I did what you suggested and moved the <h:messages> to the end of my
page - THANKS!  But the method to convert my ErrorEvents into
FacesMessages still needed to be called.  So I made it return true and
set it as the "render" attribute for the messages tag. AHHH!
It worked, but ewwwww. :)

I could change my design so that the FacesMessages are created
immediately when the events are added to the collecor.  That would
eliminate the need for the render attribute.  BUT, I'll need to beg
for forgiveness from my UI designers when I tell them that the
<h:messages> tag MUST be at the end of the page.

I guess the original intent of the FacesMessages was to be used during
the Validation phase. Hmmm.
Is it a sign of mis-use of the JSF framework if my getter methods in
the render phase can produce FacesMessages?

HMMM.... Perhaps I could override/extend the responseComplete method
to do my custom stuff first, and then call super.responseComplete???
Is this a good approach or even possible or even the right method to
override? It seems like a path to the dark side.

Thanks for the help.
Jason



On 2/14/06, Craig McClanahan <cr...@apache.org> wrote:
> On 2/14/06, Jason Vincent <jt...@gmail.com> wrote:
> >
> > Hmm... I guess a phase listener wouldn't work for me. From what you
> > say, it appears that the outcome of the phase is already determined
> > before the "afterPhase" listener is triggered.
> >
> > Is there a another place for me to plug into the steps taken "during"
> > a phase, that is, before the final steps in the phase are completed?
>
>
> I don't see how that would really help you ... what you seem to be needing
> is that the messages get generated before the <h:messages> component itself
> is rendered.
>
> Or at least, I just need the FacesMessages to not get processed until
> > the last step of the render phase.
>
>
> Put your <h:messages> component last???
>
> Thanks,
> > Jason
>
>
> Craig
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Shale: postRender method?

Posted by Craig McClanahan <cr...@apache.org>.
On 2/14/06, Jason Vincent <jt...@gmail.com> wrote:
>
> Hmm... I guess a phase listener wouldn't work for me. From what you
> say, it appears that the outcome of the phase is already determined
> before the "afterPhase" listener is triggered.
>
> Is there a another place for me to plug into the steps taken "during"
> a phase, that is, before the final steps in the phase are completed?


I don't see how that would really help you ... what you seem to be needing
is that the messages get generated before the <h:messages> component itself
is rendered.

Or at least, I just need the FacesMessages to not get processed until
> the last step of the render phase.


Put your <h:messages> component last???

Thanks,
> Jason


Craig

Re: Shale: postRender method?

Posted by Jason Vincent <jt...@gmail.com>.
Hmm... I guess a phase listener wouldn't work for me. From what you
say, it appears that the outcome of the phase is already determined
before the "afterPhase" listener is triggered.

Is there a another place for me to plug into the steps taken "during"
a phase, that is, before the final steps in the phase are completed?

Or at least, I just need the FacesMessages to not get processed until
the last step of the render phase.

Thanks,
Jason

On 2/14/06, Craig McClanahan <cr...@apache.org> wrote:
> On 2/14/06, Jason Vincent <jt...@gmail.com> wrote:
> >
> > Hi All,
> >
> > I was wondering if there is an easy way to get a postRender method to
> > be called in my Shale ViewController.
> > Is a new Phase Listener the only / best option? Perhaps I can extend a
> > Shale class to also call a postRender method?
>
>
> Doesn't the destroy() method do what you want?  It is called after
> rendering.
>
> Here is my scenario:
> > I have the concept of an ErrorEventCollector in the ViewController.
> > Basically, the collector is passed around in the model calls to
> > capture errors during the model execution.  This might include errors
> > caused by validation checks on the retrieved data from the DB, as well
> > as any exceptions.  These events can be generated in any phase - init,
> > validation, application, or render.
> >
> > In my BaseViewController - I want to have the event collector checked
> > for any events.  If there are events in the collector, then I want to
> > create FacesMessages for each event.  I tried putting the check in the
> > Shale destroy method, but the messages weren't being displayed by the
> > JSP.  So It seems I need to have this check as the last step in the
> > render_response phase.
>
>
> Hmm ... destroy() *is* called by an afterPhase listener for the Render
> Response phase, so something else must be going on here.
>
> Note, of course, that any messages you *add* in the destroy() method will,
> of course, not be rendered -- precisely because rendering *has* ben
> completed.
>
> Craig
>
> Thanks for any help.
> > Jason
> >
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Shale: postRender method?

Posted by Craig McClanahan <cr...@apache.org>.
On 2/14/06, Jason Vincent <jt...@gmail.com> wrote:
>
> Hi All,
>
> I was wondering if there is an easy way to get a postRender method to
> be called in my Shale ViewController.
> Is a new Phase Listener the only / best option? Perhaps I can extend a
> Shale class to also call a postRender method?


Doesn't the destroy() method do what you want?  It is called after
rendering.

Here is my scenario:
> I have the concept of an ErrorEventCollector in the ViewController.
> Basically, the collector is passed around in the model calls to
> capture errors during the model execution.  This might include errors
> caused by validation checks on the retrieved data from the DB, as well
> as any exceptions.  These events can be generated in any phase - init,
> validation, application, or render.
>
> In my BaseViewController - I want to have the event collector checked
> for any events.  If there are events in the collector, then I want to
> create FacesMessages for each event.  I tried putting the check in the
> Shale destroy method, but the messages weren't being displayed by the
> JSP.  So It seems I need to have this check as the last step in the
> render_response phase.


Hmm ... destroy() *is* called by an afterPhase listener for the Render
Response phase, so something else must be going on here.

Note, of course, that any messages you *add* in the destroy() method will,
of course, not be rendered -- precisely because rendering *has* ben
completed.

Craig

Thanks for any help.
> Jason
>