You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2012/02/12 23:18:55 UTC
svn commit: r1243342 - in
/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html:
HtmlScriptRenderer.java HtmlStylesheetRenderer.java
Author: lu4242
Date: Sun Feb 12 22:18:54 2012
New Revision: 1243342
URL: http://svn.apache.org/viewvc?rev=1243342&view=rev
Log:
MYFACES-3462 REGRESSION - Detect when to wpdate head or body target when content has been updated dynamically
Modified:
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlScriptRenderer.java
myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlStylesheetRenderer.java
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlScriptRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlScriptRenderer.java?rev=1243342&r1=1243341&r2=1243342&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlScriptRenderer.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlScriptRenderer.java Sun Feb 12 22:18:54 2012
@@ -45,6 +45,7 @@ import org.apache.myfaces.shared.renderk
import org.apache.myfaces.shared.renderkit.html.HTML;
import org.apache.myfaces.shared.renderkit.html.util.ResourceUtils;
import org.apache.myfaces.shared.util.ExternalContextUtils;
+import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
import org.apache.myfaces.view.facelets.el.CompositeComponentELUtils;
import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
@@ -57,23 +58,28 @@ import org.apache.myfaces.view.facelets.
*/
@JSFRenderer(renderKitId = "HTML_BASIC", family = "javax.faces.Output", type = "javax.faces.resource.Script")
@ListenerFor(systemEventClass = PostAddToViewEvent.class)
-public class HtmlScriptRenderer extends Renderer implements ComponentSystemEventListener {
+public class HtmlScriptRenderer extends Renderer implements ComponentSystemEventListener
+{
//private static final Log log = LogFactory.getLog(HtmlScriptRenderer.class);
private static final Logger log = Logger.getLogger(HtmlScriptRenderer.class.getName());
private static final String IS_BUILDING_INITIAL_STATE = "javax.faces.IS_BUILDING_INITIAL_STATE";
- public void processEvent(ComponentSystemEvent event) {
- if (event instanceof PostAddToViewEvent) {
+ public void processEvent(ComponentSystemEvent event)
+ {
+ if (event instanceof PostAddToViewEvent)
+ {
UIComponent component = event.getComponent();
String target = (String) component.getAttributes().get(JSFAttr.TARGET_ATTR);
- if (target != null) {
+ if (target != null)
+ {
FacesContext facesContext = FacesContext.getCurrentInstance();
Location location = (Location) component.getAttributes().get(CompositeComponentELUtils.LOCATION_KEY);
if (location != null)
{
- UIComponent ccParent = CompositeComponentELUtils.getCompositeComponentBasedOnLocation(facesContext, location);
+ UIComponent ccParent
+ = CompositeComponentELUtils.getCompositeComponentBasedOnLocation(facesContext, location);
if (ccParent != null)
{
component.getAttributes().put(
@@ -84,15 +90,26 @@ public class HtmlScriptRenderer extends
// If this is an ajax request and the view is being refreshed and a PostAddToViewEvent
// was propagated to relocate this resource, means the header must be refreshed.
- // Note ajax request does not occur
+ // Note ajax request does not occur on non postback requests.
+
if (!ExternalContextUtils.isPortlet(facesContext.getExternalContext()) &&
- facesContext.getPartialViewContext().isAjaxRequest() &&
- !facesContext.getAttributes().containsKey(IS_BUILDING_INITIAL_STATE) &&
- MyfacesConfig.getCurrentInstance(facesContext.getExternalContext()).isStrictJsf2RefreshTargetAjax())
+ facesContext.getPartialViewContext().isAjaxRequest())
{
- //!(component.getParent() instanceof ComponentResourceContainer)
- RequestViewContext requestViewContext = RequestViewContext.getCurrentInstance(facesContext);
- requestViewContext.setRenderTarget("head", true);
+ boolean isBuildingInitialState = facesContext.getAttributes().
+ containsKey(IS_BUILDING_INITIAL_STATE);
+ // The next condition takes into account the current request is an ajax request.
+ boolean isPostAddToViewEventAfterBuildInitialState =
+ !isBuildingInitialState ||
+ (isBuildingInitialState &&
+ FaceletViewDeclarationLanguage.isRefreshingTransientBuild(facesContext));
+ if (isPostAddToViewEventAfterBuildInitialState &&
+ MyfacesConfig.getCurrentInstance(facesContext.getExternalContext()).
+ isStrictJsf2RefreshTargetAjax())
+ {
+ //!(component.getParent() instanceof ComponentResourceContainer)
+ RequestViewContext requestViewContext = RequestViewContext.getCurrentInstance(facesContext);
+ requestViewContext.setRenderTarget("head", true);
+ }
}
facesContext.getViewRoot().addComponentResource(facesContext,
@@ -106,10 +123,12 @@ public class HtmlScriptRenderer extends
//TODO target check here
UIComponent component = event.getComponent();
String target = (String) component.getAttributes().get(JSFAttr.TARGET_ATTR);
- if (target != null) {
+ if (target != null)
+ {
FacesContext facesContext = FacesContext.getCurrentInstance();
UIComponent uiTarget = facesContext.getViewRoot().getFacet(target);
- if (uiTarget == null) {
+ if (uiTarget == null)
+ {
throw new FacesException("Target for component not found");
}
}
@@ -117,29 +136,40 @@ public class HtmlScriptRenderer extends
}
@Override
- public boolean getRendersChildren() {
+ public boolean getRendersChildren()
+ {
return true;
}
@Override
public void encodeChildren(FacesContext facesContext, UIComponent component)
- throws IOException {
+ throws IOException
+ {
if (facesContext == null)
+ {
throw new NullPointerException("context");
+ }
if (component == null)
+ {
throw new NullPointerException("component");
+ }
Map<String, Object> componentAttributesMap = component.getAttributes();
String resourceName = (String) componentAttributesMap.get(JSFAttr.NAME_ATTR);
boolean hasChildren = component.getChildCount() > 0;
- if (resourceName != null && (!"".equals(resourceName))) {
- if (hasChildren) {
+ if (resourceName != null && (!"".equals(resourceName)))
+ {
+ if (hasChildren)
+ {
log.info("Component with resourceName " + resourceName +
" and child components found. Child components will be ignored.");
}
- } else {
- if (hasChildren) {
+ }
+ else
+ {
+ if (hasChildren)
+ {
// Children are encoded as usual. Usually the layout is
// <script type="text/javascript">
// ...... some javascript .......
@@ -149,9 +179,12 @@ public class HtmlScriptRenderer extends
writer.writeAttribute(HTML.SCRIPT_TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
RendererUtils.renderChildren(facesContext, component);
writer.endElement(HTML.SCRIPT_ELEM);
- } else {
+ }
+ else
+ {
if (!facesContext.getApplication().getProjectStage().equals(
- ProjectStage.Production)) {
+ ProjectStage.Production))
+ {
facesContext.addMessage(component.getClientId(),
new FacesMessage("Component with no name and no body content, so nothing rendered."));
}
@@ -161,25 +194,28 @@ public class HtmlScriptRenderer extends
@Override
public void encodeEnd(FacesContext facesContext, UIComponent component)
- throws IOException {
+ throws IOException
+ {
super.encodeEnd(facesContext, component); //check for NP
Map<String, Object> componentAttributesMap = component.getAttributes();
String resourceName = (String) componentAttributesMap.get(JSFAttr.NAME_ATTR);
String libraryName = (String) componentAttributesMap.get(JSFAttr.LIBRARY_ATTR);
- if (resourceName == null) {
+ if (resourceName == null)
+ {
//log.warn("Trying to encode resource represented by component" +
// component.getClientId() + " without resourceName."+
// " It will be silenty ignored.");
return;
}
- if ("".equals(resourceName)) {
+ if ("".equals(resourceName))
+ {
return;
}
-
+
String additionalQueryParams = null;
- int index = resourceName.indexOf('?');
+ int index = resourceName.indexOf('?');
if (index >= 0)
{
additionalQueryParams = resourceName.substring(index + 1);
@@ -187,15 +223,20 @@ public class HtmlScriptRenderer extends
}
Resource resource;
- if (libraryName == null) {
- if (ResourceUtils.isRenderedScript(facesContext, libraryName, resourceName)) {
+ if (libraryName == null)
+ {
+ if (ResourceUtils.isRenderedScript(facesContext, libraryName, resourceName))
+ {
//Resource already founded
return;
}
resource = facesContext.getApplication().getResourceHandler()
.createResource(resourceName);
- } else {
- if (ResourceUtils.isRenderedScript(facesContext, libraryName, resourceName)) {
+ }
+ else
+ {
+ if (ResourceUtils.isRenderedScript(facesContext, libraryName, resourceName))
+ {
//Resource already founded
return;
}
@@ -204,19 +245,23 @@ public class HtmlScriptRenderer extends
}
- if (resource == null) {
+ if (resource == null)
+ {
//no resource found
log.warning("Resource referenced by resourceName " + resourceName +
(libraryName == null ? "" : " and libraryName " + libraryName) +
" not found in call to ResourceHandler.createResource." +
" It will be silenty ignored.");
return;
- } else {
- if (ResourceUtils.isRenderedScript(facesContext, resource.getLibraryName(), resource.getResourceName())) {
+ }
+ else
+ {
+ if (ResourceUtils.isRenderedScript(facesContext, resource.getLibraryName(), resource.getResourceName()))
+ {
//Resource already founded
return;
}
-
+
// Rendering resource
ResourceUtils.markScriptAsRendered(facesContext, libraryName, resourceName);
ResourceUtils.markStylesheetAsRendered(facesContext, resource.getLibraryName(), resource.getResourceName());
Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlStylesheetRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlStylesheetRenderer.java?rev=1243342&r1=1243341&r2=1243342&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlStylesheetRenderer.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlStylesheetRenderer.java Sun Feb 12 22:18:54 2012
@@ -43,6 +43,7 @@ import org.apache.myfaces.shared.renderk
import org.apache.myfaces.shared.renderkit.html.HTML;
import org.apache.myfaces.shared.renderkit.html.util.ResourceUtils;
import org.apache.myfaces.shared.util.ExternalContextUtils;
+import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
import org.apache.myfaces.view.facelets.el.CompositeComponentELUtils;
import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
@@ -77,7 +78,8 @@ public class HtmlStylesheetRenderer exte
Location location = (Location) component.getAttributes().get(CompositeComponentELUtils.LOCATION_KEY);
if (location != null)
{
- UIComponent ccParent = CompositeComponentELUtils.getCompositeComponentBasedOnLocation(facesContext, location);
+ UIComponent ccParent
+ = CompositeComponentELUtils.getCompositeComponentBasedOnLocation(facesContext, location);
if (ccParent != null)
{
component.getAttributes().put(
@@ -87,15 +89,26 @@ public class HtmlStylesheetRenderer exte
}
// If this is an ajax request and the view is being refreshed and a PostAddToViewEvent
// was propagated to relocate this resource, means the header must be refreshed.
- // Note ajax request does not occur
+ // Note ajax request does not occur on non postback requests.
+
if (!ExternalContextUtils.isPortlet(facesContext.getExternalContext()) &&
- facesContext.getPartialViewContext().isAjaxRequest() &&
- !facesContext.getAttributes().containsKey(IS_BUILDING_INITIAL_STATE) &&
- MyfacesConfig.getCurrentInstance(facesContext.getExternalContext()).isStrictJsf2RefreshTargetAjax())
- {
- //!(component.getParent() instanceof ComponentResourceContainer)
- RequestViewContext requestViewContext = RequestViewContext.getCurrentInstance(facesContext);
- requestViewContext.setRenderTarget("head", true);
+ facesContext.getPartialViewContext().isAjaxRequest() )
+ {
+ boolean isBuildingInitialState = facesContext.getAttributes().
+ containsKey(IS_BUILDING_INITIAL_STATE);
+ // The next condition takes into account the current request is an ajax request.
+ boolean isPostAddToViewEventAfterBuildInitialState =
+ !isBuildingInitialState ||
+ (isBuildingInitialState &&
+ FaceletViewDeclarationLanguage.isRefreshingTransientBuild(facesContext));
+ if (isPostAddToViewEventAfterBuildInitialState &&
+ MyfacesConfig.getCurrentInstance(facesContext.getExternalContext()).
+ isStrictJsf2RefreshTargetAjax())
+ {
+ //!(component.getParent() instanceof ComponentResourceContainer)
+ RequestViewContext requestViewContext = RequestViewContext.getCurrentInstance(facesContext);
+ requestViewContext.setRenderTarget("head", true);
+ }
}
facesContext.getViewRoot().addComponentResource(facesContext,
component, "head");
@@ -113,9 +126,13 @@ public class HtmlStylesheetRenderer exte
throws IOException
{
if (facesContext == null)
+ {
throw new NullPointerException("context");
+ }
if (component == null)
+ {
throw new NullPointerException("component");
+ }
Map<String, Object> componentAttributesMap = component.getAttributes();
String resourceName = (String) componentAttributesMap.get(JSFAttr.NAME_ATTR);