0

p:outputLabel 会为相关的 UIInput 设置标签,但是当它是 Omnifaces 的子级时 o:tree 是行不通的。验证错误消息仍然使用 clientId。

Omnifaces outputLabel 可以为相关的 UIComponent 设置标签,并且可以与 o:tree 一起使用。

Primefaces 在 endEncode 方法中设置标签,使用 o:tree 时,在 endEncode 之前调用 validateValue 方法。

有人有解决方法吗?

更新:

版本:

  • 爪哇 7
  • TomEE 1.5.1 (myfaces 2.1.9)
  • Primefaces-3.4.1
  • omn​​ifaces-1.3-SNAPSHOT-20121121

只能用myfaces重现,用Mojarra最后一个节点的lable值将用于其他节点的无效消息。

4

2 回答 2

2

我可以重现你的问题。这个问题与 OmniFaces 无关<o:tree>,但它实际上是 PrimeFaces 中的一个错误<p:outputLabel>。作为证据,尝试在 中使用它<ui:repeat>,您会看到完全相同的问题。

至于为什么它与 OmniFaces 一起工作<o:outputLabel>,那是因为它在关联的输入组件中将标签设置为 a ValueExpression。PrimeFaces 设置了当前评估的值,该值在请求消息时不一定是正确的值。

我建议将其作为问题报告给 PrimeFaces 人员,并附上使用<ui:repeat>.

于 2012-12-01T21:24:12.093 回答
0

这个问题有两个部分。一个在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;
        }
于 2012-12-02T07:01:42.670 回答