1

我有:主页和对话框上的按钮。

A 想要托管 bean (NewDialog.java) 的 ViewScope 生命周期,执行对话框。换句话说:按下按钮时重新创建 NewDialog bean,并在关闭对话框时销毁。

但是在加载主页时已经创建了 NewDialog bean。如何仅在按下按钮时强制创建bean?

<ui:composition
   <h:form id="mainForm">
      <p:commandButton value="New Dialog"
                  onclick="newDialogVar.show();"/>  
   </h:form>

        <ui:include src="#{viewScopedBean.page}.xhtml" />
    </ui:define>
</ui:composition>

包含页面:

    <ui:composition ..
        <f:view >
       <h:form id="formId"
         <p:dialog appendToBody="false"
                  dynamic="true"
                  modal="true"
                  widgetVar="newDialogVar">

              <p:commandButton value="Ok"
                         actionListener="#{newDialog.ok}"/>
      </h:form>
    </p:dialog>
    </f:view>
</ui:composition>

豆:

@ManagedBean
@ViewScoped
public class NewDialog implements Serializable{

  @PostConstruct
    protected void postConstruct() {
        LOG.info("----------------- PostConstruct -------------------");
    }
}

我使用:PrimeFaces 3.5 和 Mojarra 2.1.22

提前致谢!

PS:根据研究我补充说:

<context-param>
    <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
    <param-value>false</param-value>
</context-param>

到 web.xml。


官方的Windows SDK提供了一种方法来获取已知文件夹的协作:

var client = new BoxClient(...);
var collabs = await client.FoldersManager.GetCollaborationsAsync(folderId);

(编辑 8/29/14 指向官方 SDK)

4

2 回答 2

3

This is expected behavior. The <ui:include> runs during view build time, not during view render time. So even if you conditionally render one of its parents, it will still evaluate its src attribute during building/restoring of the view. In depth background explanation of "view build time" versus "view render time" can be found in this answer: JSTL in JSF2 Facelets... makes sense?

Your concrete functional requirement is unclear, so I can't elaborate the right approach in detail, but fact is, you need to look for an alternate approach if you want to postpone the creation of the bean to display of the dialog. Perhaps you need to split the bean in two ones, one holding the include path and another holding the dialog's data?

于 2013-06-06T13:57:08.263 回答
0

我有一个像你这样在对话框内显示图形的情况,这个按钮调用一个方法来将 src 设置为对话框:

<p:commandButton value="Montos" update=":form2:growl, :form2:displaygraf" oncomplete="montosDialog.show()" actionListener="#{serviciosMB.mostrarGraf}" icon="ui-icon-disk"/> 

这是对话框(在同一页面中)

  <p:dialog id="dialog" header="Estado del monto del contrato" widgetVar="montosDialog" resizable="false">  
      <p:panel id="displaygraf">
          <ui:include src="#{serviciosMB.urlGrafMontos}" />  
      </p:panel>
   </p:dialog> 

managedbean 服务MB:

 public void mostrarGraf() throws Exception {
    try {
        if (this.servicioUtilNew.getContratoUtil().getMontosList().isEmpty()) {
            this.urlGrafMontos ="void.xhtml";
            JsfUtil.addWarnningMessage("El contrato no tiene montos definidos");
        } else {
              this.urlGrafMontos ="grafMontosServicios.xhtml";
        }
    } catch (Exception e) {
        JsfUtil.addErrorMessage(e, "Error: addOrdenProdServArr() " + e.getMessage());

    }
}

这是 grafMontosServicios.xhtml

 <h:body>              
    <p:barChart id="stacked1" value="#{grafMontosServiciosMB.categoryModelChartMontos}"   legendPosition="ne" animate="true"
                    title="Estado del monto del contrato" barMargin="20" style="height:300px; width: 500px"/>                                                                      
</h:body>

构建图形的托管 bean

public CartesianChartModel getCategoryModelChartMontos() {
    return categoryModelChartMontos;
}

public void setCategoryModelChartMontos(CartesianChartModel categoryModelChartMontos) {
    this.categoryModelChartMontos = categoryModelChartMontos;
}
/**
 * Creates a new instance of GrafMontosServiciosMB
 */
public GrafMontosServiciosMB() {
}
@PostConstruct
public void crearTablaMontos() {
    try {
        ...           
    } catch (Exception e) {
        JsfUtil.addErrorMessage(e, "Error: createCategoryModel() " + e.getMessage());
    }
}

}

于 2013-06-07T16:24:25.437 回答