Stripes: Abstract ActionBean - invoking handler
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I have quite interesting task in hand. While designing for a project, I kept certain base ActionBean classes as abstract with atleast one abstract method, which would be implemented in the sub-classes. Now, the base classes are bound to some URL as per my design, to suit the requirement. If any subclass URL is invoked it's working properly, taking the inherited handler impl. from base, but i'm not able to invoke the base class handler by it's own URL. Kindly confirm with your ideas.
e.g.
abstract BaseXYZActionBean implements ActionBean(@UrlBinding - "/{$event}/{field}")
SubClassOfXYZ extends BaseXYZActionBean (@UrlBinding - "/title/{$event}/{field}")
The events are defined in BaseXYZActionBean class.
Now from the browser, the url "/title/{$event}/{field}" is working, but not the "/{$event}/{field}". Kindly suggest.
Refreshing life every moment...
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
But as you said BaseXYZActionBean is abstract, so by definition, it cannot be instantiated.
So you either have to make the base not abstract, or move the URL binding to a concrete subclass of the base.
Hope that helps.
Frederic Daoud
Author, Stripes...and Java Web Development is Fun Again
Stripes book
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
that's right. Even I had the same info from Stripesframework site [http://www.stripesframework.org/display/stripes/Lifecycles+Etc.]. But I guess masking the URL is allowed in Stripes. e.g.
----------------
abstract BaseXYZActionBean implements ActionBean(@UrlBinding - "/search")
SubClassOfXYZ extends BaseXYZActionBean (@UrlBinding - "/search/{$event}")
The events are defined in BaseXYZActionBean class including @DefaultHandler.
----------------
Now if I try the URL "/search" from the browser, it's mapping SubClassOfXYZ, and invokes the inherited @DefaultHandler in it. So, from the browser it seems as if Base class is getting invoked.
The only problem is if there are more than one sub-class, then to invoke the URL of base (though an abstract), I've to keep one of subclass's @UrlBinding as the above example. Let me know what do you feel about this approach (though not much logical in my opinion).
Refreshing life every moment...
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Subhadip Chatterjee wrote:
Now if I try the URL "/search" from the browser, it's mapping SubClassOfXYZ, and invokes the inherited @DefaultHandler in it. So, from the browser it seems as if Base class is getting invoked.
What is actually happening is that the subclass is being instantiated. An event handler from the parent class can still be invoked, just like regular object-oriented programming.
Subhadip Chatterjee wrote:
The only problem is if there are more than one sub-class, then to invoke the URL of base (though an abstract), I've to keep one of subclass's @UrlBinding as the above example. Let me know what do you feel about this approach (though not much logical in my opinion).
I think you should put the common code in your base class, but no URL binding on the base class, only in concrete subclasses.
Frederic Daoud
Author, Stripes...and Java Web Development is Fun Again
Stripes book
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Refreshing life every moment...
| They worship nothing. They say it's because nothing is worth fighting for. Like this tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |






