10 Replies Latest reply on May 5, 2011 4:27 PM by zellx

    target _blank don't work with a4j:commandLink under seam

      Hi,


      i can not get work simple thing that works under pure richfaces and don't want to work together with seam.
      The simple commandLink  just works (new browser will be opened and the output goes to it) with simple richfaces web application. As i put seam to the application, only put the jars to lib dir and configure listener a.s.o. nothing special (so all requests go throught seam) the output goes to the old browser page, no new page is opened.


       <a4j:commandLink action="#{bean.showReport}" value="download" target="_blank">
       </a4j:commandLink>



      I'm using seam 2.2.0.CR1. Could it be an issue of the seam version?


      h:commandLink works. But i need an ajax link. My primary task is to get it work from richfaces context menu, that expects ajax.


      any ideas?


      thaks a lot for any advises
      regards
      Dmitri

        • 1. Re: target _blank don't work with a4j:commandLink under seam
          asookazian

          show the xhtml and backing bean in the case of JSF/RF only.  I'm not sure if this is a Seam-related issue...

          • 2. Re: target _blank don't work with a4j:commandLink under seam

            What exactly should i show?
            The xhtml and the bean are the same in case of JSF/RF with or without seam.



            <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">
                
                    <h:form>
                        <h:commandLink action="#{pdfReporter.showReport}" value="h:commandLink plus action" target="_blank">
                        </h:commandLink>
                        <br></br>    
                        <a4j:commandLink action="#{pdfReporter.showReport}" value="a4j:commandLink plus action" target="_blank">
                        </a4j:commandLink>
                    </h:form>
            
            </ui:composition>
            


            That's all.


            The bean does nothing special. it is just a jsf managed bean. It doesn't care what it does and what the method returns. If you whant  i could provide the sample. I have build a simple app. just for testing this issue.


            regards
            Dmitri

            • 3. Re: target _blank don't work with a4j:commandLink under seam
              kukeltje.ronald.jbpm.org

              Can you show how the 'generated' html looks like? e.g. with firebug? Both for h: and a4j: ?

              • 4. Re: target _blank don't work with a4j:commandLink under seam
                kukeltje.ronald.jbpm.org

                Oh, and try an a4j:form....

                • 5. Re: target _blank don't work with a4j:commandLink under seam

                  here is it...


                  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
                      <html>
                      <head>
                      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                      <title>seam test</title>
                      </head>
                      <body>
                      <div id="main">
                  <form id="j_id2" name="j_id2" method="post" action="/seamtest/index.jsf" enctype="application/x-www-form-urlencoded">
                  
                  <input type="hidden" name="j_id2" value="j_id2" />
                  
                  <script type="text/javascript" language="Javascript">function dpf(f) {var adp = f.adp;if (adp != null) {for (var i = 0;i < adp.length;i++) {f.removeChild(adp[i]);}}};function apf(f, pvp) {var adp = new Array();f.adp = adp;var i = 0;for (k in pvp) {var p = document.createElement("input");p.type = "hidden";p.name = k;p.value = pvp[k];f.appendChild(p);adp[i++] = p;}};function jsfcljs(f, pvp, t) {apf(f, pvp);var ft = f.target;if (t) {f.target = t;}f.submit();f.target = ft;dpf(f);};</script>
                  
                  <a href="#" onclick="if(typeof jsfcljs == 'function'){jsfcljs(document.getElementById('j_id2'),{'j_id2:j_id3':'j_id2:j_id3'},'_blank');}return false">h:commandLink plus action</a>
                  <br />
                  
                  <a href="#" id="j_id2:j_id5" name="j_id2:j_id5" onclick="A4J.AJAX.Submit('_viewRoot','j_id2',event,{'similarityGroupingId':'j_id2:j_id5','parameters':{'j_id2:j_id6':'21','j_id2:j_id5':'j_id2:j_id5'} ,'actionUrl':'/seamtest/index.jsf'} );return false;" target="_blank">a4j:commandLink plus action
                  </a>
                  
                  <input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="j_id1" />
                  </form>
                  
                  </div>
                  </body>
                  </html>



                  • 6. Re: target _blank don't work with a4j:commandLink under seam
                    kukeltje.ronald.jbpm.org

                    ok, and did you have a look at the differences? Would be nice if you tried analyzing it to instead just posting ;-)


                    In the h: the target is one of the params in the javascript call, in the a4j it is a real target attribute. Since both return false (as they should) the target by itself does nothing unless the A4J.AJAX.Submit reads the target attribute from the element where the event originates (the 'a').


                    If you have put a a4j:form around the a4j:commandLink and it still does not work, it might be a bug. You might try debugging the A4J.AJAX.Submit and see what really happens.

                    • 7. Re: target _blank don't work with a4j:commandLink under seam

                      with a4j:form is the same......

                      • 8. Re: target _blank don't work with a4j:commandLink under seam

                        well,


                        i'm not so experiensed in JS. I saw the deferense with target handling, but i don't know the handling.


                        I'll try to debug....

                        • 9. Re: target _blank don't work with a4j:commandLink under seam
                          freakjuancho
                          Hi my friend... I have the same problem with the h:commandLink and a4j:commandLink "target" tag, instead of that element you can use the s:link tag, and with the:


                          target="#" or target="_new"

                          elements, I hope this can be helpful...

                          Cheers
                          • 10. Re: target _blank don't work with a4j:commandLink under seam
                            zellx
                            Hi,

                            I don't see any post to solve this issue, so I'll just post a hack for you :)

                            Seam will in the following tag remove the target attribute <s:download target="_blank"... and generate an <a href.. tag.
                            I would say this is a bug because we don't get any error messages from Seam. I have not looked into the bugg reports, maybe a later version will have this fixed or not.
                            Anyway, this solution will work in any Seam version.


                            Solution:

                            In you .xhtml file

                            <s:div id="something">
                              <s:download ....></s:download>
                            </s:div>

                            I put an id attribute on an enclosing <s:div tag,  you would like to do it on <s:download but it will remove the id as it did with the target attribute from the <a href tag.
                            No all you have to do is to create a javascript that will be called on pageload or when you perform some action that creates this attribute in the tag ;)

                            var divTag = document.getElementById('something');
                            var aTag = divTag.getElementsByTagName('a')[0];
                            aTag.setAttribute('target', '_blank');


                            Cheers