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 2010/08/21 20:09:05 UTC
svn commit: r987807 - in
/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/tree2:
AbstractHtmlTree.java HtmlTreeRenderer.java HtmlTreeTagHandler.java
Author: lu4242
Date: Sat Aug 21 18:09:04 2010
New Revision: 987807
URL: http://svn.apache.org/viewvc?rev=987807&view=rev
Log:
TOMAHAWK-1540 t:tree2 navigation, expand and collapse image component manipulation does not work well with PSS on JSF 2
Added:
myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/tree2/HtmlTreeTagHandler.java
Modified:
myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/tree2/AbstractHtmlTree.java
myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/tree2/HtmlTreeRenderer.java
Modified: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/tree2/AbstractHtmlTree.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/tree2/AbstractHtmlTree.java?rev=987807&r1=987806&r2=987807&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/tree2/AbstractHtmlTree.java (original)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/tree2/AbstractHtmlTree.java Sat Aug 21 18:09:04 2010
@@ -51,7 +51,8 @@ import org.apache.myfaces.component.Loca
@JSFComponent(
name = "t:tree2",
clazz = "org.apache.myfaces.custom.tree2.HtmlTree",
- tagClass = "org.apache.myfaces.custom.tree2.TreeTag")
+ tagClass = "org.apache.myfaces.custom.tree2.TreeTag",
+ tagHandler = "org.apache.myfaces.custom.tree2.HtmlTreeTagHandler")
public abstract class AbstractHtmlTree extends UITreeData
implements LocationAware, LibraryLocationAware
{
Modified: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/tree2/HtmlTreeRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/tree2/HtmlTreeRenderer.java?rev=987807&r1=987806&r2=987807&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/tree2/HtmlTreeRenderer.java (original)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/tree2/HtmlTreeRenderer.java Sat Aug 21 18:09:04 2010
@@ -83,7 +83,6 @@ public class HtmlTreeRenderer extends Re
private static final int EXPANDED = 2;
private static final int LINES = 4;
private static final int LAST = 8;
- private int counter = 0;
public void processEvent(ComponentSystemEvent event)
{
@@ -521,7 +520,8 @@ public class HtmlTreeRenderer extends Re
// add the appropriate image for the nav control
UIGraphic image = new HtmlGraphicImage();
- String imageId = IMAGE_PREFIX+(counter++);
+ image.setTransient(true);
+ String imageId = IMAGE_PREFIX+tree.createUniqueId(context, null).substring(UIViewRoot.UNIQUE_ID_PREFIX.length());//IMAGE_PREFIX+(counter++);
image.setId(imageId);
image.setUrl(navSrcUrl);
@@ -548,8 +548,6 @@ public class HtmlTreeRenderer extends Re
expandImgSrc = context.getApplication().getViewHandler().getResourceURL(context, expandImg.getUrl());
if (expandImg.isRendered())
{
- expandImg.setId(imageId + NODE_STATE_EXPANDED);
- expandImg.setParent(tree);
nodeImageId = expandImg.getClientId(context);
nodeImgFacet = expandFacet;
}
@@ -562,8 +560,6 @@ public class HtmlTreeRenderer extends Re
collapseImgSrc = context.getApplication().getViewHandler().getResourceURL(context, collapseImg.getUrl());
if (collapseImg.isRendered())
{
- collapseImg.setId(imageId + NODE_STATE_CLOSED);
- collapseImg.setParent(tree);
nodeImageId = collapseImg.getClientId(context);
nodeImgFacet = collapseFacet;
}
Added: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/tree2/HtmlTreeTagHandler.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/tree2/HtmlTreeTagHandler.java?rev=987807&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/tree2/HtmlTreeTagHandler.java (added)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/tree2/HtmlTreeTagHandler.java Sat Aug 21 18:09:04 2010
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.custom.tree2;
+
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIGraphic;
+import javax.faces.component.UIViewRoot;
+import javax.faces.view.facelets.ComponentConfig;
+import javax.faces.view.facelets.ComponentHandler;
+import javax.faces.view.facelets.FaceletContext;
+
+/**
+ *
+ * @since 1.1.10
+ * @author Leonardo Uribe
+ */
+public class HtmlTreeTagHandler extends ComponentHandler
+{
+ private static final String IMAGE_PREFIX = "t2";
+ private static final String NODE_STATE_EXPANDED = "x";
+ private static final String NODE_STATE_CLOSED = "c";
+
+ public HtmlTreeTagHandler(ComponentConfig config)
+ {
+ super(config);
+ }
+
+ @Override
+ public void onComponentPopulated(FaceletContext ctx, UIComponent c,
+ UIComponent parent)
+ {
+ if (ComponentHandler.isNew(c))
+ {
+ // t:tree2 requires to force id rendering of UIGraphic images on "expand" and "collapse" facets for
+ // a nodeTypeFacet. Long time ago, this was done on HtmlTreeRenderer.encodeNavigation, but that
+ // hack will not work well with jsf 2 PSS, because it requires ids to be generated in a "stable" way,
+ // and that hack used a counter to generate it.
+ for (Map.Entry<String, UIComponent> entry : c.getFacets().entrySet())
+ {
+ UIComponent nodeTypeFacet = entry.getValue();
+ UIComponent expandFacet = nodeTypeFacet.getFacet("expand");
+ if (expandFacet != null)
+ {
+ //if (! (expandFacet instanceof UIGraphic))
+ //{
+ // expandFacet = expandFacet.getChildren().get(0);
+ // nodeTypeFacet.getFacets().put("expand", expandFacet);
+ //}
+ UIGraphic expandImg = (UIGraphic)expandFacet;
+ String id = expandImg.getId();
+ if (id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
+ {
+ expandImg.setId(IMAGE_PREFIX + id.substring(UIViewRoot.UNIQUE_ID_PREFIX.length()) + NODE_STATE_EXPANDED);
+ }
+
+ }
+
+ UIComponent collapseFacet = nodeTypeFacet.getFacet("collapse");
+ if (collapseFacet != null)
+ {
+ //if (! (collapseFacet instanceof UIGraphic))
+ //{
+ // collapseFacet = collapseFacet.getChildren().get(0);
+ // nodeTypeFacet.getFacets().put("collapse", collapseFacet);
+ //}
+ UIGraphic collapseImg = (UIGraphic)collapseFacet;
+ String id = collapseImg.getId();
+ if (id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
+ {
+ collapseImg.setId(IMAGE_PREFIX + id.substring(UIViewRoot.UNIQUE_ID_PREFIX.length()) + NODE_STATE_CLOSED);
+ }
+ }
+ }
+ }
+ }
+}