2014-01-31 40 views
1

你好我有更新的问题,我有一些复合组件嵌套在少数组件中,我想更新其中的一些,什么是正确的方法?第二我可以更新div吗?Primefaces更新

代码示例:

<div id="outer"> 
    <p:commandButton id="button"/> 
    <div id="inner"> 
     <h:form id="form"> 
      <mycomponents:test whatToUpdate="form panel button outer label">//here problem 
     </h:form> 
    </div> 
</div> 
<div id="outer2"> 
    <h:form id="form"> 
     <p:panelGroup id="panel"> 
      <p:label id="label" value="value"/> 
     </p:panelGroup> 
    </h:form> 
</div> 

回答

0

相反的div使用号码:outputPanel

<p:outputPanel id="outer"> 
    <p:commandButton id="button" update="inner"/> 
    <p:outputPanel id="inner"> 
     <h:form id="form"> 
      <mycomponents:test whatToUpdate="form panel button outer label">//here problem 
     </h:form> 
    </p:outputPanel> 
</p:outputPanel> 
+0

当然,但我有问题如何调用组件 “窗体面板按钮外部标签”,因为不是所有都可以从视图 – user2771738

+0

第二我不能更新divs?我有问题,因为当我把div id更新时,我总是有堆栈跟踪 – user2771738

0

我发现了一些简单的方法来更新嵌套组件(我想是这样),我希望有人会发现这个有用的。 这个想法是将styleClass设置为primefaces组件(不知道一些随机的styleClass名称),并使用该styleClass更新组件。 例如:

...bla bla nested components 
<p:panel id="somePanel" styleClass="somePanelStyle"> 
`... bla bla nested components` 
<p:panel> 
... bla bla nested components 

任何你需要通过按钮进行更新(以ID为“somePanel”这个例子面板)例如:

<p:commanButton update="@(.somePanelStyle)" 

目前我只是用这种方式,因为它很容易实现更新和搜索(eclipse中的CTRL + H)该组件在哪里。

关于更新的div,BalusC得到了一些很好的答案: Answer about updating divs from JSF by BalusC

0

之前显示我的答案,我希望做一些假设:

  • 首先使用相同的标识符予h:form并且这是一个错误
  • 我不知道whatToUpdate究竟代表了什么,但我想它是绑定到一些update属性。
  • 我想formwhatToUpdate里面的值是你的复合组件引用的外部属性。
  • 里面JSF上下文我不建议你使用div,我会把它们放在的唯一地方是HTML模板代码。
  • in JSF上下文我不建议您更新h:form组件外的元素,尤其是如果您的p:commandButton是提交按钮。
  • 我注意到你只想把组件更新成两个子树,如果你把所有东西放在一个h:form里面就会更容易用子表单引用更新子树内的每个组件。

这是我这是什么,我会在你的地方做:

<h:form id="form1"> 
    <p:outputPanel id="outer"> 
    <p:commandButton id="button"/> 
    <p:outputPanel id="inner"> 
     <mycomponents:test whatToUpdate="@form :form2"> 
    </p:outputPanel> 
    </p:outputPanel> 
</h:form> 

<h:form id="form2"> 
    <p:outputPanel id="outer2"> 
    <p:panelGroup id="panel"> 
     <p:label id="label" value="value"/> 
    </p:panelGroup> 
    </p:outputPanel> 
</h:form> 

这样你就可以更新的最简单的方法form1form2每个组件,你不必再担心如果你想在其中一个子树中添加一些组件。

让我知道如果我错了一些假设。