views:

31

answers:

1

I've got a series of web actions I'm implementing in Seam to perform create, read, update, etc. operations. For my read/update/delete actions, I'd like to have individual action classes that all extend an abstract base class. I'd like to put the @Factory method in the abstract base class to retrieve the item that is to be acted upon. For example, I have this as the base class:

public abstract class BaseAction {

   @In(required=false)@Out(required=false)
   private MyItem item=null;

   public MyItem getItem(){...}

   public void setItem(...){...}

   @Factory("item")
   public void initItem(){...}
}

My subclasses would extend BaseAction, so that I don't have to repeat the logic to load the item that is to be viewed, deleted, updated, etc. However, when I start my application, Seam throws errors saying I have declared multiple @Factory's for the same object.

Is there any way around this? Is there any way to provide the @Factory in the base class without encoutnering these errors?

+2  A: 

The problem you're encountering is that every Seam component needs a unique name - using your approach you'd have a component named "item" for each subclass.

I would do the following:

@Name( "action1" )
public class Action1 extends BaseAction
{
  ...
}

And in components.xml:

<factory name="action1Item" value="#{action1.item}" />
mtpettyp
So in other words, I'd need to move the @Factory down into the subclasses and name item differently, as opposed to being able to pull it up into the base class. Correct?
Shadowman
Yup - whatever approach you take just needs to ensure that the component name is unique.
mtpettyp