7 Replies Latest reply on Apr 13, 2009 6:55 PM by pgmjsd

    Open a pop-up window from a command button

    ricardoalonso

      Hi guys,


      There is a way to open a pop-up window from a command button? I know that from a command link is possible, but it change all the layout of the page.


      Thanks in advance..


      Ricardo Alonso

        • 1. Re: Open a pop-up window from a command button
          gonorrhea

          try this, it works in my code:


          <h:form>
          <a4j:jsFunction name="reRenderProblemCodeModal" 
                                reRender="problemCodeDataModalDiv"
                              oncomplete="Richfaces.showModalPanel('editProblemCodePanel');"/>     
          </h:form>




          <h:form id="populateProblemCodesForm">
          
          <a4j:commandLink value="Edit"
                     ajaxSingle="true"                                                                                      
                     action="#{repairCaseDetails.populateProblemCodesModalPanel(equipmentRepairProblemCodeList.getRowIndex())}"
                     oncomplete="reRenderProblemCodeModal();"/>     
          
          </form>


          • 2. Re: Open a pop-up window from a command button
            gonorrhea

            you can substitute <a4j:commandButton> for <a4j:commandLink>

            • 3. Re: Open a pop-up window from a command button
              ricardoalonso

              The problem is that I need to open a real new browser window, not just a modal pane, because in this new window will appear a report pdf.

              • 4. Re: Open a pop-up window from a command button
                gonorrhea

                try this, i just tested it:


                <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                
                <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                     xmlns:ui="http://java.sun.com/jsf/facelets"
                     xmlns:h="http://java.sun.com/jsf/html"
                     xmlns:f="http://java.sun.com/jsf/core"
                     xmlns:a4j="http://richfaces.org/a4j"
                     xmlns:rich="http://richfaces.org/rich"
                     xmlns:s="http://jboss.com/products/seam/taglib"
                     template="/templates/normal.xhtml">
                     
                <ui:define name="body">
                                                         
                               <h:form>
                                    <a4j:jsFunction name="openWindow"
                                                        oncomplete="window.open ('http://www.javascript-coder.com','mywindow','menubar=1,resizable=1,width=350,height=250');" />                   
                               </h:form> 
                               
                               <h:form>
                                    <a4j:commandButton value="Open Window" onclick="openWindow()"/>
                               </h:form>
                          
                </ui:define>
                
                </ui:composition>

                • 5. Re: Open a pop-up window from a command button
                  ricardoalonso

                  but how to pass the action result to this new window?


                  the new window should show a jasper report with the params of the base page.

                  • 6. Re: Open a pop-up window from a command button
                    gonorrhea

                    You could use Seam Remoting to access the action result variable stored in a JavaBean or session bean.


                    And then dynamically construct the URL (HTTP GET request) by appending the params from the Seam remoting call and then using that as the first param of the window.open() call.


                    window.open('/foo/bar?a1=1234','mywindow','menubar=1,resizable=1,width=350,height=250');



                    where a1=1234 is the result of the Seam remoting call...


                    WARNING: I have not tested this!


                    • 7. Re: Open a pop-up window from a command button
                      pgmjsd

                      Arbi Sookazian wrote on Apr 09, 2009 22:48:


                      You could use Seam Remoting to access the action result variable stored in a JavaBean or session bean.

                      And then dynamically construct the URL (HTTP GET request) by appending the params from the Seam remoting call and then using that as the first param of the window.open() call.

                      window.open('/foo/bar?a1=1234','mywindow','menubar=1,resizable=1,width=350,height=250');



                      where a1=1234 is the result of the Seam remoting call...

                      WARNING: I have not tested this!



                      I think if you do this you should make sure that the Seam Remoting call does't fire when there is already an A4J request happening.  If requests from Seam Remoting and A4J hit the server simultaneously then Seam's contexts can get messed up.   Usually Seam Remoting ends up failing due to 'no conversation' or something like that.