You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shale.apache.org by Ingo Düppe <ma...@dueppe.com> on 2007/02/11 15:20:55 UTC

@Property with in out like in seam

Hi,

I wonder if shale should support an out semantic like in shale.

In my page classes I always neet to get some object from the session 
scope and mostly I need to refresh them in the prerender method and put 
the refreshed object back to the session scope. Like in the following 
example.

@Property (value="#{sessionScope.enrollment})
private Enrollment enrollment;

public void prerender () {
     if (enrollment != null) {
          enrollment = lectureService.getEnrollment(enrollment.getId());
          setSessionBean("enrollment", enrollment);
     } else {
         // error cannot display without a selected enrollment - 
redirect to some starting page
     }
}

So for me it would be nice if all properties that are defined as out 
will be set back to their scope after the prerender method is called

@Property (value="#{sessionScope.enrollment}", out=true)
private Enrollment enrollment;

public void prerender() {
   if (enrollment != null)
      enrollment = lectureService.getEnrollment(enrollment.getId());
   else
      // redirect
}

Regards
Ingo




Re: @Property with in out like in seam

Posted by Ingo Düppe <ma...@dueppe.com>.
Craig McClanahan schrieb:
> On 2/11/07, Ingo Düppe <ma...@dueppe.com> wrote:
>> Hi,
>>
>> I wonder if shale should support an out semantic like in shale.
> I presume you mean like in Seam? :-)
Yes, you are right, just got mixed up :-)
>  
> That would indeed be an interesting approach.  One of the things I would
> like to see Shale do in the future is be an implementation of JSR-299
> (WebBeans), and it wouldn't surprise me at all to see this concept be
> included there.
>
> In the mean time, I've found it useful to use the saveData() and
> restoreData() methods in the AbstractViewController base class to save 
> and
> restore state information across requests (it saves the state in a 
> generic
> attribute on the UIViewRoot, so JSF's state machinery does the heavy
> lifting.  You could simulate injection and outjection pretty easily 
> with one
> liners:
>
>    public void preprocess() {
>        setValue("#{sessionScope.enrollment}", restoreData("enrollment"));
>        // May need conditional logic here if it won't always exist
>    }
>
>    public void prerender() {
>        saveData("enrollment", getValue("#{sessionScope.enrollment}"));
>    }
>
> This also works to save variables local to the current view (sort of like
> "flash scope" when you are redisplaying the same page).  It can also be
> combined with the normal injection that JSF supports on managed beans to
> initialize local (to your view controller bean) references to session or
> application scope objects.
>
> Craig

This sound interesting,  I will give it a look.

Thx
Ingo




Re: @Property with in out like in seam

Posted by Craig McClanahan <cr...@apache.org>.
On 2/11/07, Ingo Düppe <ma...@dueppe.com> wrote:
>
> Hi,
>
> I wonder if shale should support an out semantic like in shale.


I presume you mean like in Seam? :-)

In my page classes I always neet to get some object from the session
> scope and mostly I need to refresh them in the prerender method and put
> the refreshed object back to the session scope. Like in the following
> example.
>
> @Property (value="#{sessionScope.enrollment})
> private Enrollment enrollment;
>
> public void prerender () {
>      if (enrollment != null) {
>           enrollment = lectureService.getEnrollment(enrollment.getId());
>           setSessionBean("enrollment", enrollment);
>      } else {
>          // error cannot display without a selected enrollment -
> redirect to some starting page
>      }
> }
>
> So for me it would be nice if all properties that are defined as out
> will be set back to their scope after the prerender method is called
>
> @Property (value="#{sessionScope.enrollment}", out=true)
> private Enrollment enrollment;
>
> public void prerender() {
>    if (enrollment != null)
>       enrollment = lectureService.getEnrollment(enrollment.getId());
>    else
>       // redirect
> }


That would indeed be an interesting approach.  One of the things I would
like to see Shale do in the future is be an implementation of JSR-299
(WebBeans), and it wouldn't surprise me at all to see this concept be
included there.

In the mean time, I've found it useful to use the saveData() and
restoreData() methods in the AbstractViewController base class to save and
restore state information across requests (it saves the state in a generic
attribute on the UIViewRoot, so JSF's state machinery does the heavy
lifting.  You could simulate injection and outjection pretty easily with one
liners:

    public void preprocess() {
        setValue("#{sessionScope.enrollment}", restoreData("enrollment"));
        // May need conditional logic here if it won't always exist
    }

    public void prerender() {
        saveData("enrollment", getValue("#{sessionScope.enrollment}"));
    }

This also works to save variables local to the current view (sort of like
"flash scope" when you are redisplaying the same page).  It can also be
combined with the normal injection that JSF supports on managed beans to
initialize local (to your view controller bean) references to session or
application scope objects.



Regards
> Ingo


Craig