4 Replies Latest reply on Jan 10, 2012 6:36 AM by sree_valtech

    How to open separate new window using h:commandButton Or a4j:commandButton

    sree_valtech

      I am trying to open separate new window using h:commandButton. But by using following code, i am not able to open separate new window.

       

      My Jsp Code:

       

      <h:commandButton id="genReport"

                                  value="Generate Report" action="#{reportBean.generateReport}">

      </h:commandButton>

       

       

      Bean Code:

       

      HttpServletResponse res =

                          (HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();

                      res.getWriter().println("<script>window.open('" +

                                              reportURL.toString() + "');</script>");

       

       

       

      Please anyone give me clarification.

       

      Thanks in advance.

        • 1. Re: How to open separate new window using h:commandButton Or a4j:commandButton
          mcmurdosound

          I'm using commandLinks like this one:

           

          <h:commandLink value="open"                      
                                   action="#{bean.action(param)}"
                                   target="_blank"
                                   style="float: right; top: -3px; position: relative; z-index: 10;"
                                   styleClass="styleclass1"
                                   title="ui.openInNewTab"/>
          • 2. Re: How to open separate new window using h:commandButton Or a4j:commandButton
            sree_valtech

            Using command link its possible.  but for commandButton, in backing bean through action how to do it.

             

            One more thing. If validation success then only separate new window has to open. if validation fails, failure message has to display in the same page,

             

            Please any one give me clarification.

             

             

            Thanks alot in advance.

            • 3. Re: How to open separate new window using h:commandButton Or a4j:commandButton
              mcmurdosound

              hmmm I'd use a button and a link in this case:

              a) the button, clickable for the user:

              a4j:commandButton oncomplete="jQuery("#myform\\:mybutton").click()" value="clickme"

               

              and

              b)

              the h:commandButton from the previous example - but with id and style="display:none;" to hide it.

               

               

              you should add something like:if (#{facesContext.maximumSeverity.ordinal lt 2}) jQuery('#.... to only click the second link, if there are no validation errors.

               

              you have to look for the correct syntax for yourself. I don't have any example with me right now.

              • 4. Re: How to open separate new window using h:commandButton Or a4j:commandButton
                sree_valtech

                Thanks alot Peter for your quick responce

                 

                I did in the same way, but i written java script for that.

                 

                I used both commandButton and hidden commandLink(display:none;)

                 

                when user click on commandButton, If validation success, commandLink will be clicked automatically using script and opening separate new window using' target='_blank' 

                , if validation fails, corresponding message will be displayed on the same page.

                 

                 

                rightnow no issues.

                 

                But i want know alternatives to improve my knowledge.

                 

                Pleaase let me know if there is any other alternatives.

                 

                Once again thanks alot peter.