Unless Java reflection is used, it is not possible for a portlet bridge to use the JSF 2.0/2.1 API to wrap the Flash implementation provided by Mojarra or MyFaces.
In order to solve this problem, this issue serves as a proposal to add javax.faces.context.FlashWrapper and javax.faces.context.FlashFactory to the JSF API.
Background:
The JSF 2.0/2.1 API does not currently provide a factory-style way of obtaining Flash scope instances. Instead, the ExternalContext#getFlash() method inside the JSF runtime is responsible for acting as
a pseudo-factory for creating instances.
One solution for a portlet bridge would be to create its own implementation of the Flash interface. However it is much more desirable to simply wrap the Mojarra/MyFaces flash implementation and override methods where necessary.
1) Add a FlashWrapper class:
package javax.faces.context;
public abstract class FlashWrapper extends Flash implements FacesWrapper<Flash>
Precedent/Example:
http://javaserverfaces.java.net/nonav/docs/2.0/javadocs/javax/faces/application/ApplicationWrapper.html
2) Also to add a FlashFactory:
package javax.faces.context;
public abstract class FlashFactory
extends Object implements FacesWrapper<FlashFactory>
public abstract Flash getFlash();
The wrappable FlashFactory instance would take a one-arg constructor and look something like this:
public class FlashFactoryImpl extends FlashFactory {
private FlashFactory wrappedFactory;
public FlashFactoryImpl(FlashFactory flashFactory) {
wrappedFactory = flashFactory;
}
@Override
public Flash getFlash() {
return new FlashImpl(wrappedFactory.getFlash());
}
@Override
public FlashFactory getWrapped() {
return wrappedFactory;
}
}
Precedent/Example:
http://javaserverfaces.java.net/nonav/docs/2.0/javadocs/javax/faces/application/ApplicationFactory.html
3) Add constant FLASH_FACTORY to FactoryFinder and require JSF implementations to return a wrappable FlashFactory instance.
http://javaserverfaces.java.net/nonav/docs/2.0/javadocs/javax/faces/FactoryFinder.html
Neil, I'll meet you half way. Here's the first part of the work already done.
I need you to fill out the API javadoc for the two new classes in jsf-api. The real kicker is my insistence on the color coded changebars.
I'm about to write a FAQ entry on how to do those. When I have done so, I'll point to it from this issue.