【问题标题】:Controlling component from backing bean从 backing bean 控制组件
【发布时间】:2015-07-22 04:19:22
【问题描述】:

我想用 bean 中的新组件“更新”一个组件。

XHTML

<composite:interface>
  <composite:attribute name="rootKey"   required="true" />
  <composite:attribute name="id"        required="true" />
</composite:interface>
<composite:implementation>

<rich:panel id="#{cc.attrs.id}" binding="#{myBean.customPanel}"/>

<a4j:jsFunction name="createPanels"
  action="#{myBean.createPanels}"
  render="#{cc.attrs.id}">
  <a4j:param name="rootId" assignTo="#{myBean.rootId}"/>
  <a4j:param name="rootKey" assignTo="#{myBean.rootKey}"/>
</a4j:jsFunction>

<script type="text/javascript">
/* <![CDATA[ */
  jQuery(document).ready(function() {
    createPanels('#{cc.attrs.id}','#{cc.attrs.rootKey}');
  });
/*]]>  */
</script>
</composite:implementation>
</ui:composition>

豆子

private UIPanel rootPanel;

public void setCustomPanel(UIPanel panel) {
  rootPanel = panel;
}

public UIPanel getCustomPanel() {
  return rootPanel;
}

public void createPanels() {
  //try #1 : Adding new panels as children
  rootPanel.getChildren().add((UIPanel)createPanels(rootId,rootKey));
  //try #2 : A new Panel component 
  rootPanel = (UIPanel)createPanels(rootId,rootKey); 
  ...
  rootPanel.setId(rootId); // this ID is the same as the 'placeholder' panelId 
  FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add(rootPanel.getId()); // the rerender should also already be done in the XHTML js function.
}

使用调试器,我看到 rootPanel 更改为新面板组件,但不在视图中。 我想念什么?

简而言之:在 xhtml 视图中为面板组件动态生成子组件。生成需要“rootKey”参数来生成正确的集合。

使用:

  • JSF 莫哈拉 2.1.19
  • 富豪脸

【问题讨论】:

  • 您是否检查过来自服务器的响应? (你可以把 a4j:log 放到你的页面上查看)。
  • 嗯,不,我没有检查响应。我不熟悉页面上的 a4j:log。生病检查日志功能(对于未来的问题很可能非常有用)

标签: jsf richfaces components javabeans


【解决方案1】:

对我来说,解决方案是重新渲染父组件,而不是实际组件。 还将新元素子元素作为子元素添加到绑定组件中。

XHTML:在占位符周围添加了一个 h:panelgroup。

<h:panelGroup id="#{cc.attrs.id}_parent">
  <rich:panel id="#{cc.attrs.id}" binding="#{myBean.panel}"/> 
</h:panelGroup>

<a4j:jsFunction name="createPanels"
  action="#{myBean.createPanels}"
  render="#{cc.attrs.id}_parent">
  <a4j:param name="rootId" assignTo="#{myBean.rootId}"/>
  <a4j:param name="rootKey" assignTo="#{myBean.rootKey}"/>
</a4j:jsFunction>

BEAN:尝试 #1 是正确的。

public void createPanels() {
  UIPanel newPanel = (UIPanel)createPanels(rootId,RootKey);
  if(newPanel.getChildCount() >= 1){
    rootPanel.getChildren().addAll(newPanel.getChildren());
    rootPanel.setStyleClass(newPanel.getStyleClass());
    rootPanel.setHeader(newPanel.getHeader());
  }
}

【讨论】:

    猜你喜欢
    • 2015-01-13
    • 1970-01-01
    • 2014-08-10
    • 2015-12-06
    • 2018-12-25
    • 2019-05-15
    • 1970-01-01
    • 1970-01-01
    • 2014-08-11
    相关资源
    最近更新 更多