How to subclass a managed bean

I don't even know if I can explain what I want to do here, but here goes: I have a generic abstract "Task" class with common properties (name, description, startDate, endDate, isEnabled, owner), and a property called "editorAction" that specified the JSF action to call when editing this Task.

There are also many subclasses of the Task class (such as HttpTask, FtpTask, EmailTask, etc). For each Task subclass, I have specified a separate managed Bean.

Now, I have a "list" page, where all current tasks are displayed. Each item in the list is of type Task. When the user clicks the "edit" link for the item, I need to:

a) set the relevant managed bean for the type of task being edited, and

b) launch the relevant editor for the Task.

These tasks come from a database table, and the editor action is specified in the database.

What I'd like to be able to do is specify asingle managed bean of type Task, then set the value of that bean to any object that is a valid subclass of the Task class. How can I go about doing this? It seems like this is all managed by Faces internally. How can I go about setting the value of a managed bean programmatically?

[1208 byte] By [xoxotaa] at [2007-11-27 11:21:10]
# 1

Make it a session scoped bean. You may have to make a common superclass that can be instantiated unless Task itself may be instantiated. You can set the value by accessing the session map (ExternalContext.getSessionMap()). You will have to inject whatever dependencies the Task implementation has by hands.

Make sure that any bean you have that has Task injected into it is a request scope bean. Otherwise you could end up with references to a stale Task.

RaymondDeCampoa at 2007-7-29 14:47:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...