10 Replies Latest reply on May 5, 2011 4:27 PM by Johnny Hensegård

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

    Dmitri Ilyin Newbie


      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">

      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

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

          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
            Dmitri Ilyin Newbie

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

            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.


            • 3. Re: target _blank don't work with a4j:commandLink under seam
              Ronald van Kuijk Apprentice

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

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

                here is it...

                <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
                    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                    <title>seam test</title>
                    <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
                <input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="j_id1" />

                • 6. Re: target _blank don't work with a4j:commandLink under seam
                  Ronald van Kuijk Apprentice

                  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.

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


                    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
                      Juan Carlos Jimenez Newbie
                      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...

                      • 10. Re: target _blank don't work with a4j:commandLink under seam
                        Johnny Hensegård Newbie

                        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.


                        In you .xhtml file

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

                        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');