0

我有一个 Facelets 子视图,它为客户端/subviews/document-tree.xhtml上的每个选项卡呈现一棵树<rich:tabPanel>。页面和子视图基于 JSF 2 和 RichFaces 4。

<ui:composition ...>
  <rich:tree value="#{rootNode}" var="treeNode" id="#{treeId}">

    <rich:treeNode ... id="chapternode">

      <h:panelGrid columns="2">
        <rich:outputText value="#{treeNode.name}" />
        <h:commandLink>
          <h:graphicImage library="images/icons" name="delete.png"  />
          <rich:componentControl target="remove-chapter-popup" operation="show" />
        </h:commandLink>
        <rich:popupPanel modal="true"
                         onmaskclick="#{rich:component('remove-chapter-popup')}.hide(); return false;"
                         id="remove-chapter-popup">
          <f:facet name="header">
            <h:outputText value="Remove chapter?" />
          </f:facet>
          <f:facet name="controls">
            <h:outputText value="X" />
          </f:facet>
          <p>Remove chapter #{treeNode.name}?</p>
          <h:panelGrid columns="2">
            <h:commandButton value="Add"
                             action="#{nodeManager.removeChapterNode(treeNode)}" 
                             onclick="#{rich:component('remove-chapter-popup')}.hide(); return true;">

              <!--f:ajax execute="@this" render="@form" /-->        <!-- never executed! -->
              <a4j:ajax execute="@this" render="@form" />           <!-- this works however! -->

            </h:commandButton>
            <h:commandButton value="Cancel"
                             onclick="#{rich:component('remove-chapter-popup')}.hide(); return false;" immediate="true" />
          </h:panelGrid>
        </rich:popupPanel>
      </h:panelGrid>

    </rich:treeNode>

    ...

  </rich:tree>
</ui:composition>

这基本上显示了带有名称的树节点以及右侧的图像以供删除。

每个树子视图都放置在一个<rich:tab>中,因此选项卡面板确实具有所需的封闭<h:form>。没有其他嵌套形式(无论如何禁止)。

bean被#{nodeManager.removeChapterNode(treeNode)}正确标记为@ViewScoped.

现在发生的事情有点奇怪:

使用<f:ajax execute="@this" ... />按钮时永远不会执行,而使用<a4j:ajax execute="@this" ... /> 总是有效。

为什么?这里有什么问题?

考虑到 RichFaces根据他们自己的话<a4j:ajax>100% 基于 JSF 2的事实,这没有多大意义。<f:ajax>

这可能是我正在使用的 JSF 2.1.7 中的错误吗?(JBoss AS 7.1.1.Final 附带的实现)

4

2 回答 2

0

这是减少的差异:

<form id="tree-form" name="tree-form" method="post" action="/pqgenerator2/debug.jsf" enctype="application/x-www-form-urlencoded">
 ...
  <table style="margin: 0 auto;">
    <tbody>
      <tr>
- <td><input id="tree-form:sorting-tree-one:real root:j_idt34" type="submit" name="tree-form:sorting-tree-one:real root:j_idt34" value="Fortfahren" onclick="jsf.util.chain(this,event,'RichFaces.$(\'tree-form:sorting-tree-one:real root:add-root-chapter-popup\').hide(); return true;','mojarra.ab(this,event,\'action\',\'@this tree-form:sorting-tree-one:real root:new-root-chapter-name-input\',\'@form\')');return false" /></td>
+ <td><input id="tree-form:sorting-tree-one:real root:j_idt34" type="submit" name="tree-form:sorting-tree-one:real root:j_idt34" value="Fortfahren" onclick="jsf.util.chain(this,event,'RichFaces.$(\'tree-form:sorting-tree-one:real root:add-root-chapter-popup\').hide(); return true;','RichFaces.ajax(this,event,{&quot;parameters&quot;:{&quot;javax.faces.behavior.event&quot;:&quot;action&quot;,&quot;org.richfaces.ajax.component&quot;:&quot;tree\\u002Dform:sorting\\u002Dtree\\u002Done:real root:j_idt34&quot;} ,&quot;sourceId&quot;:this} )');return false" /></td>
      </tr>
    </tbody>
  </table>
...

- </div></span></span></div></div><input type="hidden" name="tree-form:sorting-tree-one__SELECTION_STATE" id="tree-form:sorting-tree-one__SELECTION_STATE" class="rf-tr-sel-inp" value="" /><script type="text/javascript">new RichFaces.ui.Tree("tree\u002Dform:sorting\u002Dtree\u002Done",{"toggleType":"client"} );</script></div></div><script type="text/javascript">new RichFaces.ui.Tab("tree\u002Dform:j_idt21",{"index":0,"leave":null,"togglePanelId":"tree\u002Dform:tree\u002Dtabpanel","switchMode":"client","name":"Blah GmbH","enter":null,"disabled":false} )</script></div><script type="text/javascript">new RichFaces.ui.Tab("tree\u002Dform:j_idt21",{"index":0,"leave":null,"togglePanelId":"tree\u002Dform:tree\u002Dtabpanel","switchMode":"client","name":"Blah GmbH","enter":null,"disabled":false} )</script></div><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="998210192617713914:-9142017502724223608" autocomplete="off" />
+ </div></span></span></div></div><input type="hidden" name="tree-form:sorting-tree-one__SELECTION_STATE" id="tree-form:sorting-tree-one__SELECTION_STATE" class="rf-tr-sel-inp" value="" /><script type="text/javascript">new RichFaces.ui.Tree("tree\u002Dform:sorting\u002Dtree\u002Done",{"toggleType":"client"} );</script></div></div><script type="text/javascript">new RichFaces.ui.Tab("tree\u002Dform:j_idt21",{"index":0,"leave":null,"togglePanelId":"tree\u002Dform:tree\u002Dtabpanel","switchMode":"client","name":"Blah GmbH","enter":null,"disabled":false} )</script></div><script type="text/javascript">new RichFaces.ui.Tab("tree\u002Dform:j_idt21",{"index":0,"leave":null,"togglePanelId":"tree\u002Dform:tree\u002Dtabpanel","switchMode":"client","name":"Blah GmbH","enter":null,"disabled":false} )</script></div><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="-5805340602741883884:1908800949269113937" autocomplete="off" />
</form>

这里的问题是,我为要显示的 RichFaces 根创建了一个虚拟根节点,并通过 RichFaces 添加了真正的根节点TreeNodeImpladdChild("real root", ...)其中包含键中的空格。

代码显然可以处理这个<a4j:ajax>问题,但不是 JSF 2 <f:ajax>(注意第一个差异部分)。

于 2012-05-02T11:03:13.400 回答
0

ID 中的空格是非法的。另请参见UIComponent#setId()javadoc。

设置名称

public abstract void setId(java.lang.String id)

设置这个的组件标识符UIComponent(如果有的话)。组件标识符必须遵守以下语法限制:

  • 不能是零长度字符串。
  • 第一个字符必须是字母或下划线 ('_')。
  • 后续字符必须是字母、数字、下划线 ('_') 或破折号 ('-')。

组件标识符还必须遵守以下语义限制(请注意,此限制不是由setId()实现强制执行的):

  • UIComponent指定的标识符在作为最近祖先a的后代的所有组件(包括构面)中必须是唯一的NamingContainer,或者如果没有这样的祖先是 a ,则在整个组件树的范围内是唯一的NamingContainer

参数

  • id- 新的组件标识符,或 null 表示这UIComponent没有组件标识符

抛出

  • IllegalArgumentException- 如果 id 在语法上无效

似乎 RichFaces 从未根据树的规则对其进行验证。反过来,我会将其视为 RichFaces 中的错误。向 RichFaces 人员报告。

于 2012-05-02T11:55:45.450 回答