Author: nbelaevski
Date: 2008-09-30 13:21:21 -0400 (Tue, 30 Sep 2008)
New Revision: 10627
Modified:
trunk/framework/api/src/main/java/org/ajax4jsf/application/ViewHandlerWrapper.java
trunk/framework/impl/src/main/java/org/ajax4jsf/event/InitPhaseListener.java
Log:
https://jira.jboss.org/jira/browse/RF-4554
Modified:
trunk/framework/api/src/main/java/org/ajax4jsf/application/ViewHandlerWrapper.java
===================================================================
---
trunk/framework/api/src/main/java/org/ajax4jsf/application/ViewHandlerWrapper.java 2008-09-30
14:31:29 UTC (rev 10626)
+++
trunk/framework/api/src/main/java/org/ajax4jsf/application/ViewHandlerWrapper.java 2008-09-30
17:21:21 UTC (rev 10627)
@@ -51,8 +51,6 @@
*/
protected ViewHandler _handler;
- private boolean _initialized = false;
-
/**
* @param handler - to wrap.
*/
@@ -64,7 +62,6 @@
* @see
javax.faces.application.ViewHandler#calculateLocale(javax.faces.context.FacesContext)
*/
public Locale calculateLocale(FacesContext context) {
- fillChain(context);
return _handler.calculateLocale(context);
}
@@ -72,7 +69,6 @@
* @see
javax.faces.application.ViewHandler#calculateRenderKitId(javax.faces.context.FacesContext)
*/
public String calculateRenderKitId(FacesContext context) {
- fillChain(context);
return _handler.calculateRenderKitId(context);
}
@@ -80,7 +76,6 @@
* @see javax.faces.application.ViewHandler#createView(javax.faces.context.FacesContext,
java.lang.String)
*/
public UIViewRoot createView(FacesContext context, String viewId) {
- fillChain(context);
return _handler.createView(context, viewId);
}
@@ -88,7 +83,6 @@
* @see
javax.faces.application.ViewHandler#getActionURL(javax.faces.context.FacesContext,
java.lang.String)
*/
public String getActionURL(FacesContext context, String url) {
- fillChain(context);
return _handler.getActionURL(context, url);
}
@@ -96,7 +90,6 @@
* @see
javax.faces.application.ViewHandler#getResourceURL(javax.faces.context.FacesContext,
java.lang.String)
*/
public String getResourceURL(FacesContext context, String url) {
- fillChain(context);
return _handler.getResourceURL(context, url);
}
@@ -104,7 +97,6 @@
* @see javax.faces.application.ViewHandler#renderView(javax.faces.context.FacesContext,
javax.faces.component.UIViewRoot)
*/
public void renderView(FacesContext context, UIViewRoot root) throws IOException,
FacesException {
- fillChain(context);
_handler.renderView(context, root);
}
@@ -112,7 +104,6 @@
* @see
javax.faces.application.ViewHandler#restoreView(javax.faces.context.FacesContext,
java.lang.String)
*/
public UIViewRoot restoreView(FacesContext context, String viewId) {
- fillChain(context);
return _handler.restoreView(context, viewId);
}
@@ -120,7 +111,6 @@
* @see
javax.faces.application.ViewHandler#writeState(javax.faces.context.FacesContext)
*/
public void writeState(FacesContext context) throws IOException {
- fillChain(context);
_handler.writeState(context);
}
@@ -143,38 +133,37 @@
return _handler.calculateCharacterEncoding(context);
}
/**
- * Fill view-handlers chain for alternate handlers.
+ * <p>Fill view-handlers chain for alternate handlers.</p>
+ * <p><em>NOTE:</em> Calls to this method should be synchronized
externally since 3.3.0 version</p>
+ *
* @param context
*/
- synchronized protected void fillChain( FacesContext context){
- if(!_initialized){
- _initialized = true;
- String handlers = context.getExternalContext().getInitParameter(HANDLERS);
- if(null != handlers){
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- String[] classes = handlers.split(",");
- for (int i = 0; i < classes.length; i++) {
- String handlerClass = classes[i];
- if (_log.isDebugEnabled()) {
- _log.debug(Messages.getMessage(Messages.CREATE_ALTERNATE_HANDLER, handlerClass));
- }
+ public void fillChain( FacesContext context){
+ String handlers = context.getExternalContext().getInitParameter(HANDLERS);
+ if(null != handlers){
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ String[] classes = handlers.split(",");
+ for (int i = 0; i < classes.length; i++) {
+ String handlerClass = classes[i];
+ if (_log.isDebugEnabled()) {
+ _log.debug(Messages.getMessage(Messages.CREATE_ALTERNATE_HANDLER, handlerClass));
+ }
+ try {
+ Class<?> clazz = classLoader.loadClass(handlerClass);
try {
- Class<?> clazz = classLoader.loadClass(handlerClass);
- try {
- Constructor<?> constructor = clazz
- .getConstructor(new Class[] { ViewHandler.class });
- _handler = (ViewHandler) constructor
- .newInstance(new Object[] { _handler });
- } catch (NoSuchMethodException e) {
- // No constructor with parent class - create simple instance
- if (_log.isWarnEnabled()) {
- _log.warn(Messages.getMessage(Messages.ALTERNATE_HANDLER_CONSTRUCTOR_WARNING));
- }
- _handler = (ViewHandler) clazz.newInstance();
+ Constructor<?> constructor = clazz
+ .getConstructor(new Class[] { ViewHandler.class });
+ _handler = (ViewHandler) constructor
+ .newInstance(new Object[] { _handler });
+ } catch (NoSuchMethodException e) {
+ // No constructor with parent class - create simple instance
+ if (_log.isWarnEnabled()) {
+ _log.warn(Messages.getMessage(Messages.ALTERNATE_HANDLER_CONSTRUCTOR_WARNING));
}
- } catch (Exception e) {
- _log.error(Messages.getMessage(Messages.VIEW_HANDLER_INSTANTIATION_ERROR), e);
+ _handler = (ViewHandler) clazz.newInstance();
}
+ } catch (Exception e) {
+ _log.error(Messages.getMessage(Messages.VIEW_HANDLER_INSTANTIATION_ERROR), e);
}
}
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/event/InitPhaseListener.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/event/InitPhaseListener.java 2008-09-30
14:31:29 UTC (rev 10626)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/event/InitPhaseListener.java 2008-09-30
17:21:21 UTC (rev 10627)
@@ -80,11 +80,18 @@
FacesContext facesContext = event.getFacesContext();
Application application = facesContext.getApplication();
ViewHandler viewHandler = application.getViewHandler();
+
if (!(viewHandler instanceof AjaxViewHandler)) {
if(log.isDebugEnabled()){
log.debug("Set AjaxViewHandler on top of chain");
}
- application.setViewHandler(new AjaxViewHandler(viewHandler));
+
+ AjaxViewHandler ajaxViewHandler = new AjaxViewHandler(viewHandler);
+ ajaxViewHandler.fillChain(facesContext);
+
+ application.setViewHandler(ajaxViewHandler);
+ } else {
+ ((AjaxViewHandler) viewHandler).fillChain(facesContext);
}
initialized = true;
}