Followup:  I DID manage to load my own lifecycle using a lifecycleFactory. But 
for the record, I just can't figure out
where the DEFAULT lifecycle loads.  In the myfaces lifecycleFactoryImpl's 
no-arg constructor it adds the "DEFAULT"
lifecycle but somehow that seems to load BEFORE my factory/lifecycle-factory 
faces configuration setting.  (It's not in
the standard-faces-config.xml file either or any other MyFaces config files I 
can find).  I couldn't add both mine and
the default because somehow, BEFORE my lifecycle-factory setting loads, JSF 
loads a default factory with a default
lifecycle.  I just change which is being used.

So, here is how I did it in four simple steps.

1. Create a class that extends the myfaces lifecycleFactoryImpl and have your 
constructor add the lifecycle under your
own key kind of like so:
        public final static String CUSTOM_LIFECYCLE = "DAVID";
        public lifecycleFactory() {
                addLifecycle(lifecycleFactory.CUSTOM_LIFECYCLE, new 
LifecycleImpl());
        };

2. Create my own lifecycle class.  For the above test example, I simply 
installed a second copy of class
org.apache.myfaces.lifecycle.lifecycleImpl because my own implementation isn't 
ready yet.

3. Set the faces config (faces-config.xml) to load your own lifecycleFactory 
implementation:
<factory>
        
<lifecycle-factory>com.friedsoftware.test.lifecycleFactory</lifecycle-factory>
</factory>

4. Set the javax.faces.LIFECYCLE_ID to the string you used to add your 
lifecycle to the factory.  The above constant was
"DAVID" so I set this in web.xml:
<context-param>
        <param-name>javax.faces.LIFECYCLE_ID</param-name>
        <param-value>DAVID</param-value>
</context-param>

That's it.  Now I can continue on with my experiment to make the view creation 
keep the viewId of "/about.jsf" but try
templating off "/hostname/about.jsf" to reduce file IO when virtual hosting 
with JSF.  More to follow (and possibly a
Wiki post!).

Regards,
David

-----Original Message-----
From: David G. Friedman [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 14, 2005 5:02 PM
To: MyFaces Discussion
Subject: RE: lifecycle questions


FYI, I'm going to try to go the other way:

Create my own lifecycleFactory implementation, specify it in a faces-config.xml 
file, then have that one's constructor
add a lifecycle called "DAVID", which will be specified in the web.xml as 
mentioned below.  I'll keep everyone posted, I
just need a mental break right now.

Regards,
David

-----Original Message-----
From: David G. Friedman [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 14, 2005 4:12 PM
To: MyFaces Discussion
Subject: RE: lifecycle questions


> I doubt you'll find any examples. Changing the
> lifecycle is really a pretty unusual thing to do.

I'm a lot closer but my problem right now is a listener order one: the Myfaces 
listener loads from the Jar BEFORE my
listener can load (to add my new lifecycle).

Essentially, the spec says I can change the default lifecycle (a default 
implementation stores under the
lifecycleFactory key "DEFAULT") using the web.xml context param:

<context-param>
    <param-name>javax.faces.LIFECYCLE_ID</param-name>
    <param-value>DEFAULT</param-value>
</context-param>

So, I want to change "DEFAULT" to "DAVID" so I can use my own lifecycle.  But I 
do that in my listener, which won't load
until AFTER the MyFaces jar's one loads so "DAVID" doesn't get in there and 
MyFaces initialization blows up like so:

INFO: Reading config /WEB-INF/faces-config.xml
Dec 14, 2005 3:29:24 PM org.apache.myfaces.webapp.StartupServletContextListener 
initFaces
SEVERE: Error initializing ServletContext
java.lang.IllegalArgumentException: Unknown lifecycle 'DAVID'.
at 
org.apache.myfaces.lifecycle.LifecycleFactoryImpl.getLifecycle(LifecycleFactoryImpl.java:60)

I would prefer this over also having to change the lifecycleFactory in 
faces-config.xml to use a key other than
javax.faces.LIFECYCLE_ID so things can still follow the JSF v1.1 spec.  Now, 
JSF spec v1.2 would allow me to specify the
javax.faces.LIFECYCLE_ID in an init param for the servlet (i.e. AFTER my 
listener loaded) but MyFaces isn't that far
along yet so it is not an option.

And yes, I tried pushing my lifecycle into the factory to replace "DEFAULT" but 
that exceptions out/fails:
> INFO: java.lang.IllegalArgumentException: Lifecycle with id 'DEFAULT' already 
> exists.

Does anyone have any ideas on how to change the listener load order?

Thanks again for any suggestions,
David

Reply via email to