1

下面的代码是tabView,后面是加载页面的结构。对于 commandButton,我尝试了 actionListener、渲染和更新的不同组合,显式引用目标 inputtextarea (req) 等。当表单在其自己的页面中运行时(而不是在选项卡中),该操作可以正常工作。

在“preRenderView”事件中,我初始化数据结构,这些数据结构在表单显示时填充。问题是当我单击预览按钮时。通常动作触发,处理方法组装数据以在预览输入外部区域(req)中显示,并显示。

奇怪的是,当我单击按钮时,不会调用该操作,尽管有活动调用我的其他选项卡的 loadReqEvents,并且在托管 tabView 的外部页面中。我怀疑这是我不知道的 JSF 的请求-响应细微差别。感谢帮助。

<p:tabView id="tbv" dynamic= "true" activeIndex="#{sessionController.activeTab}" styleClass="tabview-style">       
  <p:tab id="rtmTab" styleClass="tab-style" title="RTM" closable="false" titletip="Requirements Traceability Matrix">
      <ui:include src="url(./../rtm.xhtml"/>
   </p:tab>
   <p:tab id="composeTab" styleClass="tab-style" title="#{sessionController.composeTabTitle}" rendered="#{sessionController.crudTabRendered}" closable="false" titletip="Composition Form">
      <ui:include src="url(./..#{sessionController.composeUrl}.xhtml"/>
   </p:tab>
   <p:tab id="objTab" styleClass="tab-style" title="Object / Data Model" closable="false" titletip="Object and Data Model View">
      <ui:include src="url(./../objView.xhtml"/>
   </p:tab>
</p:tabView>  
</p:layoutUnit>


<p:layoutUnit id="formLayout" position="center" gutter="0" styleClass="form-layout"> 
  <h:form>
    <f:event listener="#{attrDefController.loadReqEvent}" type="preRenderView"></f:event>  
    <p:panel style="background-color:rgb(222,231,254);width:925px;height:98%;margin-top:-4px;margin-left:-8px">
      <h:panelGrid columns="7" style="margin-right:-8px" cellpadding="2">
          <h:commandButton id="preview" value="Preview" action="#{attrDefController.previewReqAction}" style="width:100px; margin-top:2px">
             <f:ajax execute="@form" render="req"/>
          </h:commandButton>
       </h:panelGrid>
     </p:panel>
   </h:form>
 </p:layoutUnit>
4

1 回答 1

0

在没有看到组件req声明位置的标记的情况下,我假设它存在于ui:include.

问题是 的render属性f:ajax指定了页面上不存在的 id。这样做的原因是组件客户端 ID 将以其 parent 的客户端 ID 为前缀UINamingContainer

并非所有 JSF 组件都是 UINamingContainer,form这就是为什么您通常会看到表单的 ID 以组件的客户端 ID 为前缀的原因。例如:

<h:form id="formone">
  <h:outputText id="textComponent" value="YO" />
  <h:commandButton ...>
    <f:ajax update="textComponent" />
  </h:commandButton>
</h:form>
<h:form id="formtwo">
  <h:commandButton ...>
    <f:ajax update=":formone:textComponent" />
  </h:commandButton>
</h:form>

在上面的示例中,客户端 IDtextComponent实际上是formone:textComponent。现在,上面示例中的命令按钮仍然可以通过其实际 ID 引用它,因为它恰好UINamingContainer与其兄弟组件相同。

然而,另一种形式的 commandButton 必须通过其完整的客户端 ID 访问它,因为它不是textComponent. 它通过在客户端 ID 前面加上通用选择器:,然后在其后加上textComponent.

现在这与您的问题有什么关系?

PrimeFaces TabView 组件恰好也是一个UINamingContainer

所以这意味着要 Ajax 渲染带有 ID 的组件,req您需要为表单指定一个 ID 并以这种方式调用它......

render=":formid:tbv:req"

我希望这是有道理的。

于 2013-03-07T14:41:12.227 回答