这个问题有两个部分。一个在primefaces一侧。它将评估值设置为 UIInput 的标签属性,而不是 ValueExpression。所以所有数据都使用相同的标签。二是兼容性问题。Myfaces 2.1.9 是 JSF2.1 并且需要Component
遵循VisitHint.SKIP_ITERATION
. Omnifaces 不支持它。这是一个使 Omnifaces 工作的补丁。
diff -r 0c0b57aa6780 src/org/omnifaces/component/tree/TreeInsertChildren.java
--- a/src/org/omnifaces/component/tree/TreeInsertChildren.java Fri Nov 30 12:39:03 2012 -0400
+++ b/src/org/omnifaces/component/tree/TreeInsertChildren.java Sun Dec 02 14:56:02 2012 +0800
@@ -16,6 +16,7 @@
import javax.faces.component.UIComponent;
import javax.faces.component.visit.VisitCallback;
import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitHint;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
@@ -66,6 +67,11 @@
*/
@Override
public boolean visitTree(VisitContext context, VisitCallback callback) {
+ Boolean skipIterationHint = context.getHints().contains(VisitHint.SKIP_ITERATION);
+ if (skipIterationHint != null && skipIterationHint.booleanValue())
+ {
+ return super.visitTree(context, callback);
+ }
return Components.getClosestParent(this, Tree.class).visitTreeNode(context, callback);
}
diff -r 0c0b57aa6780 src/org/omnifaces/component/tree/TreeNodeItem.java
--- a/src/org/omnifaces/component/tree/TreeNodeItem.java Fri Nov 30 12:39:03 2012 -0400
+++ b/src/org/omnifaces/component/tree/TreeNodeItem.java Sun Dec 02 14:56:02 2012 +0800
@@ -18,6 +18,7 @@
import javax.faces.component.UIComponent;
import javax.faces.component.visit.VisitCallback;
import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitHint;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
@@ -119,6 +120,12 @@
@Override
@SuppressWarnings({ "rawtypes", "unchecked" }) // For TreeModel. We don't care about its actual type anyway.
public boolean visitTree(final VisitContext context, final VisitCallback callback) {
+
+ Boolean skipIterationHint = context.getHints().contains(VisitHint.SKIP_ITERATION);
+ if (skipIterationHint != null && skipIterationHint.booleanValue())
+ {
+ return super.visitTree(context, callback);
+ }
if (!isVisitable(context) || getChildCount() == 0) {
return false;
}
更新:
此补丁与 JSF 2.0 有一些编译时兼容性
diff -r 0c0b57aa6780 src/org/omnifaces/component/tree/TreeFamily.java
--- a/src/org/omnifaces/component/tree/TreeFamily.java Fri Nov 30 12:39:03 2012 -0400
+++ b/src/org/omnifaces/component/tree/TreeFamily.java Mon Dec 03 09:33:00 2012 +0800
@@ -16,6 +16,8 @@
import javax.faces.FacesException;
import javax.faces.component.UIComponentBase;
+import javax.faces.component.visit.VisitContext;
+import javax.faces.component.visit.VisitHint;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
@@ -136,4 +138,24 @@
}
}
+ /**
+ *
+ * <a href="http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-545" >JSF Spec</a>
+ * @param context The faces context
+ * @param visitContext the visit tree context
+ * @return
+ */
+ boolean isSkippingIteration(final VisitContext visitContext) {
+ //
+ try {
+ //JSF 2.1
+ VisitHint skipHint = VisitHint.valueOf("SKIP_ITERATION");
+ return visitContext.getHints().contains(skipHint);
+ }
+ catch(IllegalArgumentException e) {
+ //JSF 2.0
+ Object skipHint = visitContext.getFacesContext().getAttributes().get("javax.faces.visit.SKIP_ITERATION");
+ return Boolean.TRUE.equals(skipHint);
+ }
+ }
}
\ No newline at end of file
diff -r 0c0b57aa6780 src/org/omnifaces/component/tree/TreeInsertChildren.java
--- a/src/org/omnifaces/component/tree/TreeInsertChildren.java Fri Nov 30 12:39:03 2012 -0400
+++ b/src/org/omnifaces/component/tree/TreeInsertChildren.java Mon Dec 03 09:33:00 2012 +0800
@@ -66,6 +66,9 @@
*/
@Override
public boolean visitTree(VisitContext context, VisitCallback callback) {
+ if (isSkippingIteration(context)) {
+ return super.visitTree(context, callback);
+ }
return Components.getClosestParent(this, Tree.class).visitTreeNode(context, callback);
}
diff -r 0c0b57aa6780 src/org/omnifaces/component/tree/TreeNodeItem.java
--- a/src/org/omnifaces/component/tree/TreeNodeItem.java Fri Nov 30 12:39:03 2012 -0400
+++ b/src/org/omnifaces/component/tree/TreeNodeItem.java Mon Dec 03 09:33:00 2012 +0800
@@ -119,6 +119,10 @@
@Override
@SuppressWarnings({ "rawtypes", "unchecked" }) // For TreeModel. We don't care about its actual type anyway.
public boolean visitTree(final VisitContext context, final VisitCallback callback) {
+ if (isSkippingIteration(context)) {
+ return super.visitTree(context, callback);
+ }
+
if (!isVisitable(context) || getChildCount() == 0) {
return false;
}