beehive-user@incubator.apache.org
[Top] [All Lists]

RE: question about inheritance

Subject: RE: question about inheritance
From: "Jarrod Knox"
Date: Fri, 20 May 2005 17:06:02 -0500
One thing off the top of my head is calling a page flow from my page flow
that is not shared.

Example:

Pageflow 1

Pageflow 2

Jsp contains pageflow 1 and pageflow 2 forms in pageflow 2

This won't work because I can't include the pageflow 1 in pageflow 2 it will
look for the action in pageflow 1 in pageflow 2 that won't exist.

Developing a "custom" portal like application, so if I could do this it
would be great.
        - currently I am forced to merge the 2 different flows into one.

Jarrod

-----Original Message-----
From: Richard Feit [mailto:richard.feit@xxxxxxx] 
Sent: Friday, May 20, 2005 3:15 PM
To: Beehive Users
Subject: Re: question about inheritance

Thank you!  :)
Hopefully you'll continue to find that it's got what you need, and where 
it doesn't, we'd love to get bugs/feature-requests, or better yet, to 
have people get involved.

The questions are great for us to hear -- they give us a sense for where 
we've done things well and where there are holes... and where we need to 
fill in the docs.

Oh, and if it *is* good, getting the word out definitely helps the 
project.  :)

Rich

Adam Jenkins wrote:

><explitative> awesome!
>
>Wow, talk about spoilt for choice! :)  Each of those answers not only
>help, but that's fantastic information to know for other uses.
>
>A big well done to all the people that worked on this.  My entire team
>(all fairly senior developers) are continually blown away by not just
>the things that beehive does, but that lateral thinking that went into
>it's creation.
>
>It's good to see programming of this calibre.  Very inspiring to others
>in the field.  Cheers for all the hard work and such a quick response to
>my questions.
>
>Thanks again
>Adam
>
>On Fri, 2005-05-20 at 13:10 -0600, Richard Feit wrote:
>  
>
>>Hi Adam,
>>
>>These are great questions.  A few responses; hopefully one or more will 
>>help you.
>>
>>    - You can override beforeAction()/afterAction() on either the base 
>>class or the derived class.  This is a brute-force way to run code 
>>before/after every action.  In the beforeAction method, you could even 
>>write code to read the action method's annotations through reflection, 
>>and look for a custom annotation that you wrote to determine whether to 
>>do the check and throw an exception if necessary.
>>
>>    - We do have the idea of "action interceptors".  An action 
>>interceptor is a class that can be configured to run before/after a 
>>particular action, or all actions, or all actions in a particular page 
>>flow.  It can do things like change/cancel the destination URI, throw an 
>>exception, or "inject" an entire nested page flow to run before the 
>>action.  These are registered in WEB-INF/beehive-netui-config.xml.  
>>There's a bit of doc on this at 
>>http://incubator.apache.org/beehive/pageflow/config/beehive-netui-config.h
tml#pageflow-action-interceptors 
>>.  But what you *really* want is a "named" action interceptor that you 
>>can refer to in an annotation.  Short of that, you could write an 
>>interceptor that would use the reflection/annotation-based approach I 
>>mentioned above.  But read on...
>>
>>    - In this specific case our annotations can help you do what you 
>>want.  If you set the 'loginRequired' attribute on an action (or on the 
>>page flow class, in @Jpf.Controller, which can be overridden on a 
>>per-action basis), then a NotLoggedInException will be thrown if you hit 
>>the action without being logged in.  By default, "being logged in" means 
>>that getUserPrincipal() returns a non-null value on the request; 
>>however, you can plug in your own login behavior.  To do this, you'd 
>>implement org.apache.beehive.netui.pageflow.handler.LoginHandler, and 
>>register your class under <login-handler> in 
>>WEB-INF/beehive-netui-config.xml. 
>>
>>Hope this helps -- let me know if you need more info on any of this.
>>
>>Rich
>>
>>Adam Jenkins wrote:
>>
>>    
>>
>>>Hi Rich,
>>>
>>>Thanks for the quick response.  That's excellent info, it answers about
>>>3/4 of what I was after.  I have one more small question about executing
>>>the assertion.
>>>
>>>Lets say I have a controller (and my syntax could be wrong here, I'm
>>>still getting my head around beehive, but I think it get's what I'm
>>>trying to achieve accross):
>>>
>>>@Jpf.Controller(
>>>     simpleActions={
>>>             @Jpf.Forward(name="not_authenticated" path="login.do")
>>>     }       
>>>     catches={
>>>             @Jpf.Catch(type=UserNotLoggedInException.class
method="forceLogin")
>>>     }
>>>)
>>>public clas Base extends PageFlowController{
>>>
>>>     private void assertUserLoggedIn(...) throws
UserNotLoggedInException{
>>>             //do some stuff to make sure the user is validated.
>>>     }
>>>
>>>     public Forward forceLogin(...){
>>>             return new Forward("not_authenticated");
>>>     }
>>>}
>>>
>>>Now, I want to call assertUserLoggedIn before any action is executed and
>>>I want it on almost every action in the system (except of course the
>>>'login' action).  I would normally do this in a superclass of all the
>>>struts actions I used.  That is, I would call assertUserLoggedIn in the
>>>super class struts action and, if the exception was thrown it would be
>>>handled by the global exception handling.  If no exception was thrown, I
>>>would then call an abstract method that is implemented in the subclass
>>>that actually does the processing and returns the forward.  That was my
>>>way of enforcing that the first thing every action did was check and
>>>make sure that the user was in fact logged in.  So, in a nut shell, is
>>>there a way to call a common assertion or set of assertions (or set of
>>>methods for that matter) from a whole set of actions without actually
>>>specifying the assertions at the start of every action (think
>>>crosscutting).  How would you recommend achieving something like that in
>>>beehive?
>>>
>>>Cheers
>>>Adam
>>>
>>>On Thu, 2005-05-19 at 17:14 -0600, Richard Feit wrote:
>>> 
>>>
>>>      
>>>
>>>>Hi Adam,
>>>>
>>>>Beehive does support inheritance in page flows (and in controls, for 
>>>>that matter).  The important point for page flows is that the base and 
>>>>derived @Jpf.Controller annotations are merged.   So if you have the 
>>>>following hierarchy:
>>>>
>>>>   @Jpf.Controller(
>>>>       nested=true,
>>>>       catches={
>>>>           @Jpf.Catch(type=Exception1.class, method="handleException1")
>>>>       }
>>>>   )
>>>>   public class Base extends PageFlowController ...
>>>>
>>>>
>>>>   @Jpf.Controller(
>>>>       catches={
>>>>           @Jpf.Catch(type=Exception2.class, method="handleException2")
>>>>       }
>>>>   )
>>>>   public class Derived1 extends Base ...
>>>>
>>>>
>>>>   @Jpf.Controller(
>>>>       catches={
>>>>           @Jpf.Catch(type=Exception3.class, method="handleException3")
>>>>       }
>>>>   )
>>>>   public class Derived2 extends Derived1 ...
>>>>
>>>>...then the @Jpf.Controller annotation for Derived2 is virtually this:
>>>>
>>>>   @Jpf.Controller(
>>>>       nested=true,
>>>>       catches={
>>>>           @Jpf.Catch(type=Exception1.class, method="handleException1")
>>>>           @Jpf.Catch(type=Exception2.class, method="handleException2")
>>>>           @Jpf.Catch(type=Exception3.class, method="handleException3")
>>>>       }
>>>>   )
>>>>
>>>>Additionally, action methods, exception handler methods, and annotated 
>>>>control fields are all inherited as long as they're not private.
>>>>
>>>>Does this answer your question?
>>>>
>>>>Rich
>>>>
>>>>Adam Jenkins wrote:
>>>>
>>>>   
>>>>
>>>>        
>>>>
>>>>>Hi All,
>>>>>
>>>>>I'm starting out with beehive and wondering about inheritance.  With
>>>>>struts apps, I would put security assertions in a super class of all
>>>>>actions and redirect any exceptions thrown to the appropriate page.  Is
>>>>>there a way to do similar in beehive or do you have to use shared flows
>>>>>for common stuff like that.
>>>>>
>>>>>Cheers
>>>>>Adam
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>     
>>>>>
>>>>>          
>>>>>
>>> 
>>>
>>>      
>>>
>
>
>  
>


<Prev in Thread] Current Thread [Next in Thread>