• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

Stripes: Abstract ActionBean - invoking handler

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks,
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.
 
author
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you invoke a URL, Stripes tries to create an instance of the corresponding action bean.

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.
 
Subhadip Chatterjee
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Fred,
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).
 
Frederic Daoud
author
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Subhadip Chatterjee
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Fred.
 
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
reply
    Bookmark Topic Watch Topic
  • New Topic