从PrimeFaces 5中的另一个对话框更新对话框中的数据表

时间:2015-04-30 20:31:41

标签: jsf jsf-2 primefaces

我是JSF / PrimeFaces的新手,我正在尝试从另一个Dialog(SearchDlg)更新我的Dialog(SearchResultsDlg)中的DataTable(SearchResultsTable)我尝试将我的对象列表放在FacesContext上,我试过了使它成为返回类型但Dialog(SearchResultsDlg)保持弹出空。 java方面没有错误,我知道我从查询中返回了Object类型的List。以下是代码执行顺序的信息。任何想法都会很棒!

Search.xhtml

<ui:composition>
    <p:dialog id="SearchDlg"
              widgetVar="SearchDialog"
              modal="true"
              resizable="false"
              appendTo="@(body)" header="#{bundle.Search}">

        <h:form id="SearchForm" >
            <h:panelGroup id="SearchDisplay">
                <p:panelGrid columns="2">
                    <p:outputLabel  id="SearchLabel" value="What" />
                    <p:inputText    id="SearchText" value="#{offerController.searchText}" size="40"/>

                    <p:outputLabel  id="ZipCodeLabel" value="Where" />
                    <p:inputText    id="postalcode" value="#{offerController.postalCode}" size="12"/>
                </p:panelGrid>

                <p:commandButton id="Search"
                                 value="Search"
                                 actionListener="#{offerController.search}"
                                 onclick="handleSubmit(args, 'SearchDialog')" />
                <p:commandButton value="#{bundle.Cancel}"  onclick="SearchDialog.hide()"/>
            </h:panelGroup>
        </h:form>
    </p:dialog>
</ui:composition>

OfferController.java

public List<Offer> search() {

    List<Offer> offers = null;
    try {
        offers = getFacade().search(PostalCode, Distance, Category, SubCategory, SearchText, SearchType);

        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("offer", offers);
        RequestContext.getCurrentInstance().openDialog("SearchResult");
        RequestContext.getCurrentInstance().update("SearchResultsTable");

    } catch (Exception e) {
        System.out.println(e);
    }

    return offers;
}

SearchResults.xhtml

<ui:composition>
    <p:dialog id="SearchResultsDlg"
              widgetVar="SearchResultsDialog"
              modal="true"
              resizable="false"
              appendTo="@(body)"
              header="#{bundle.Login}" >

        <ui:define name="title">
            <h:outputText value="#{bundle.ListOfferTitle}"></h:outputText>
        </ui:define>

        <ui:define name="body">
            <h:form id="SearchResultsForm">
                <p:panel header="#{bundle.ListOfferTitle}">
                    <p:dataTable id="SearchResultsTable" value="#{offerController.search}" var="offer"
                                 selectionMode="single" selection="#{offerController.selected}"
                                 paginator="true"
                                 rowKey="#{offer.name}"
                                 rows="10"
                                 rowsPerPageTemplate="10,20,30,40,50">

                        <p:ajax event="rowSelect"   update="createButton viewButton editButton deleteButton"/>
                        <p:ajax event="rowUnselect" update="createButton viewButton editButton deleteButton"/>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListOfferTitle_sellerUserID}"/>
                            </f:facet>
                            <h:outputText value="#{offer.sellerUserID}"/>
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListOfferTitle_name}"/>
                            </f:facet>
                            <h:outputText value="#{offer.name}"/>
                        </p:column>
                    </p:dataTable>
                </p:panel>
            </h:form>
        </ui:define>
    </p:dialog>
</ui:composition>

2 个答案:

答案 0 :(得分:0)

selector使用update

p:dataTable id="SearchResultsTable" styleClass="for-update" 

buttonajax

p:commandButton id="Search" update="@(.for-update)"  

答案 1 :(得分:0)

您必须从更新操作的组件中引用要更新的组件。例如,如果我想更新&#34; dataTable1&#34;包含在&#34; dialog1&#34;来自&#34; button2&#34;包含在&#34; dialog2&#34;:

<p:dialog id="dialog1" ... >
    <h:form id="form1">
        <p:dataTable id="dataTable1"...>
            ...
        </p:dataTable>
    </h:form>
</p:dialog>
<p:dialog id="dialog2" ... >
    <h:form id="form2">
        <p:commandButton
            process="@form" update=":form1:dataTable1" />
    </h:form>
</p:dialog>