2011-03-12 107 views
1

我试图在页面加载时使用JavaScript打开primefaces对话框组件,但是我无法打开它。我的“这里!”当页面加载时alert会被触发,但不能使用客户端的widgetvar属性找到该组件。任何人都知道在JavaScript中适当的参考?Primefaces使用Javascript打开p:对话框

代码:

<ui:composition template="#{layoutBean.registeredTemplate}"> 
    <ui:define name="head"> 
     <script type="text/javascript"> 
      jQuery(document).ready(function(){ 
       alert("HERE!"); 
       scrapeImagesDlg.show(); 
      }); 
     </script> 
    </ui:define> 

    <ui:define name="content"> 
     <p:dialog header="#{bundle['bookmarklet.dialog.HEADER']}" 
       widgetVar="scrapeImagesDlg" 
       modal="true" 
       styleClass="dialog dialog2" 
       draggable="false" 
       resizable="false" 
       showEffect="fade" 
       hideEffect="fade" 
       closeListener="#{bookmarklet.close}" 
      onCloseUpdate="imageGrid"> 

     <div class="dialog dialog2"> 
      <div class="dialog-top-reg"></div> 

      <div class="dialog-middle-reg"> 
       <div class="close-button"><h:form> 
        <p:commandButton onclick="scrapeImagesDlg.hide()"/> 
       </h:form></div> 

       <h:form id="scrapeFrm"> 
       <p:commandButton onclick="scapeImages()" value="scrape images"/> 

       <h:inputHidden id="scrapeURL" value="http://www.freefoto.com/preview/04-01-70?ffid=04-01-70"/> 

       <p:remoteCommand name="scapeImages" 
        process="@this,scrapeURL" 
        actionListener="#{bookmarklet.loadImages}" 
        update="imageGrid"/> 

       <p:outputPanel id="imageGrid"> 
        <p:dataGrid var="img" 
         value="#{bookmarkletBean.imageURLs}" 
         rendered="#{bookmarkletBean.shouldRender}" 
         columns="1" 
         rows="1" 
         paginator="true" 
         effect="true" 
         paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} " 
         paginatorPosition="bottom"> 

         <p:column> 
           <h:panelGrid columns="1" style="width:100%"> 
             <p:graphicImage value="#{img}" width="100" height="100"/> 
          </h:panelGrid> 
         </p:column> 
        </p:dataGrid> 
       </p:outputPanel> 
       </h:form> 
      </div> 
      <div class="dialog-bottom-reg"></div> 
     </div> 
     </p:dialog> 
    </ui:define> 
</ui:composition> 

回答

11
<p:dialog visible="true" ...> 

告诉加载页面时PrimeFaces自动打开对话框。

+1

我主要的问题是脚本块在头部而不是在体内,所以脚本在对话框甚至创建之前运行。 – c12 2011-03-16 07:24:06