primefaces p:outputLabel未设置UIInput的标签,当它是Omnifaces树的子节点时使用它的值

时间:2012-12-01 03:30:34

标签: jsf primefaces omnifaces

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

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

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

任何人都有解决方法吗?

更新:

版本:

  • Java 7
  • TomEE 1.5.1(myfaces 2.1.9)
  • Primefaces-3.4.1
  • omnifaces-1.3-SNAPSHOT-20121121

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

2 个答案:

答案 0 :(得分:2)

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

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

我建议将其作为issue向PrimeFaces人员报告,并使用<ui:repeat>进行演示。

答案 1 :(得分:0)

这个问题有两个部分。一个是在主要方面。它将评估值设置为UIInput的label属性,而不是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;
        }

UPDATE:

此补丁与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;
        }