在同一页面jsf中更新面板

时间:2014-08-22 18:57:41

标签: jsf jsf-2 primefaces

嗨我正在做一个带有primefaces的文档管理系统5.y做了一个搜索功能,搜索按钮位于左侧菜单的模板中,搜索结果显示在中心单元布局中。如果我搜索,搜索功能运行良好,但是当我对结果进行调整并尝试再次搜索时,结果不会刷新

我的模板文件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">

<f:view contentType="text/html">
    <h:head>
        <f:facet name="first">
            <meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
            <title>Sysged</title>
            response.setHeader("Content-Disposition", "inline");
        </f:facet>
    </h:head>

    <h:body>

        <p:layout fullPage="true">

            <p:layoutUnit position="north" size="100" resizable="true" closable="true"collapsible="true">     
                <h:graphicImage library="images" name="logo.png" ></h:graphicImage>
                 <h:graphicImage library="images" name="footer.jpg" ></h:graphicImage>
            </p:layoutUnit>



            <p:layoutUnit position="west" size="270" header="Main menu"   collapsible="true" resizable="true">
            <h:form>
            <p:menu>

                <p:submenu label="Import">
                    <p:menuitem value="Local" icon="ui-icon-disk"   url="UIlocalImport.xhtml"/>
                    <p:menuitem value="URL" icon="ui-icon-arrowrefresh-1-w"
                        url="UIlurlImport.xhtml" />
                </p:submenu>
                <p:submenu label="Search">
                    <p:menuitem>
                        <h:panelGrid columns="3" cellpadding="5"
                            style="margin-bottom:10px">

                            <p:inputText id="paramSearch" value="# {documentBean.paramSearch}"
                                required="true" label="Keyword"  />
                            <p:watermark for="paramSearch" value="Search with a keyword"
                                id="watermark" />
                        </h:panelGrid>

                        <p:commandButton action="#{documentBean.search2}"  value="Search"  update=":content"/>

                    </p:menuitem>

                </p:submenu>



                <p:submenu label="Administrator">
                    <p:menuitem value="Category manager" url="UIadminCategories.xhtml">
                    </p:menuitem>

                    <p:submenu label="Close sesion">
                        <p:menuitem>
                            <p:commandButton action="#{userBean.logout}" value="exit"
                                icon="ui-icon-close" />
                        </p:menuitem>
                    </p:submenu>

                </p:submenu>

            </p:menu>
            </h:form>
            </p:layoutUnit>

            <p:layoutUnit position="center">
            <h:panelGroup id="content" >
                <ui:insert  name="UIlocalImport" ></ui:insert>

                <ui:insert name="Uisearch"></ui:insert>
                <ui:insert name="UiadminCategories"></ui:insert>
                <ui:insert name="UIlurlImport"></ui:insert>
                </h:panelGroup>
            </p:layoutUnit>

        </p:layout>

    </h:body>

   </f:view>
 </html>

我可以搜索的xhtml之一

<ui:define name="UIlurlImport">

    <h:panelGrid columns="1" cellpadding="5">
        <h:form>
            <p:growl id="messages" showDetail="true" />

            <p:panel id="panel" header="URL import" syle="vertical-align:top;">

                <p:outputLabel for="url" value="URL" />
                <p:inputText id="url" value="#{urlImportBean.url}" required="true"
                    label="URL">
                    <f:validateLength minimum="5" />
                    <p:ajax update="msgOutput" event="keyup" />
                </p:inputText>
                <p:message for="category" id="msgOutput" display="icon" />
                <p:outputLabel for="category" value="Category" style="padding:10px" />
                <p:selectOneMenu id="category" value="#{urlImportBean.category}"
                    label="category" filter="true">
                    <f:selectItems value="#{categorieBean.items}" id="selectCategoy" />
                    <p:ajax />
                </p:selectOneMenu>
                <p:commandButton value="Import" update="messages"
                    icon="ui-icon-home" action="#{urlImportBean.importImage}" />

            </p:panel>
        </h:form>


     </h:panelGrid>
    </ui:define>
</ui:composition>

显示结果,但如果我搜索,则不会更新任何内容

<ui:define name="Uisearch">
    <h:outputScript library="js" name="pdfobject.js" target="head" />
    <h:panelGrid columns="1" cellpadding="2">

        <p:panel id="panelResults" header="Results">

            <p:dataList value="#{documentBean.documentsMatched}" var="document"
                type="definition">

                <h:outputLink value="file/#{document.pdfPath}" target="_blank">view  document</h:outputLink>   
                <div id="pdf2">
                    <object data='file/#{document.pdfPath}' type='application/pdf'
                        width='1000px' height='400px'>

                        <p>
                            It appears your Web browser is not configured to display  PDF
                            files. No worries, just <a href='file/#  document.pdfPath}'>click
                                here to download the PDF file.</a>
                        </p>

                    </object>
                </div>


            </p:dataList>

         </p:panel>

     </h:panelGrid>

  </ui:define>

</ui:composition>

boton调用的方法

    public String search2()
 {
    System.out.println("searching "+ paramSearch);

    DocumentModel doc = new DocumentModel();
    this.setDocumentsMatched(doc.searchText(this.paramSearch));
    System.out.println("search");
    return "UIsearch";

}

提前感谢您的时间和下水道

1 个答案:

答案 0 :(得分:-1)

使用操作方法中的重定向:

return "UIsearch?faces-redirect=true"; 

我不确定它的工作原理,但我的猜测是浏览器正在缓存页面,现在被迫重新加载。