14 Replies Latest reply on Mar 26, 2007 4:30 AM by Daniel Knapp

    commandLink in a4j form

    Wolfgang Klaus Newbie


      I have a page with a t:datatable and a t:datascroller. Now I
      ajaxfied the datascroller as described in the documentation by
      surrounding the datable and the datascroller with a4j:form setting
      attribute ajaxSubmit="true". This works fine, but I have a h:commandLink
      inside the form. When I now click on the link inside the datatable wich
      goes to a new page to show detail an Ajax-Request is generated
      and the new page is without any style-sheet.
      How can I disable the ajaxSubmit for this case or is there another


        • 1. Re: commandLink in a4j form
          Ilya Shaikovsky Master

          Your rule in faces config must be one if ajax-ed controls must be used to redirect you to another page.

          btw.. you can't make controls inside ajax-ed form non ajax-ed. Form changes the behaviour of the all nested content

          • 2. Re: commandLink in a4j form
            Wolfgang Klaus Newbie

            Ok, i changed t:commandLink to a4j:commandLink and the rule is
            in faces config as before.
            <4j:commandLink action="showDetail">


            So after clicking the link the new page AdrDetail.jsp is opened but
            the stylesheet isn't applied to the page but when i look in the page source it is

            I think the problem is, how can i replace a complete page after an AJAX-Request. If this is not possible, maybe someon can give me a hint
            howto go to the detail page.


            • 3. Re: commandLink in a4j form
              Ilya Shaikovsky Master

              you should use if the rule will be used after ajax requests

              • 4. Re: commandLink in a4j form
                Sergey Smirnov Master

                Wolfgang, if you have a4j:commandLink, remove the ajaxSubmit="true" on the a4j:form. a4j:commandLink is an Ajax component already. You do not to convert it to Ajaxian link once more.

                • 5. Re: commandLink in a4j form
                  Wolfgang Klaus Newbie

                  Sergey, it is right that i don't need to ajaxify a4j:commandLink.
                  I have the a4j:form with ajaxSubmit="true" because i want the t:dataScroller to be ajaxified. For me it looks like i can do either Ajaxian the t:dataScroller with the disadvantage that commandLinks inside the formrefering to another page won't work or i can use the commandLink to go to the detail-page and it is not possible to Ajaxian the t:datascroller.
                  Maybe i give the rich:datascroller a try.


                  • 6. Re: commandLink in a4j form
                    Ilya Shaikovsky Master

                    Sorry for the unintelligible answers.. I've just lost "code" elements.. So some text was lost in my posts.

                    1) If you use ajaxSubmit on the form to ajaxify the datascroller - there is no need to use ajax Action components inside such form because all the standard components will use ajax submit inside this form. So place just simpl? h:commandLink inside.

                    In this case to perform navigation - your action must return the navigation outcome - that must be defined as

                    in your faces config. So ajax requests will be performed for all the components inside form and the components with such defined outcome - will navigate you to another pages

                    2) you may use non-ajax form and rich:dataScroller, that designed to use ajax for switching. So other components in the form may be ajax and none ajax in this case

                    • 7. Re: commandLink in a4j form
                      Wolfgang Klaus Newbie

                      Thank you Ilya, with the tip to add redirect to the navigation rule in faces-config now the change to the detail view works.
                      But there seems still a problem with a4j:form.
                      When using t:commandButton inside the form, the assigned action in the Bean won't be called.
                      First I searched my code if there is a problem, but in the end adding debug
                      and breakpoins showed me that the function won't be called.
                      On the other side when using a4j:commandButton the function is called.
                      For example:
                      <a4j:form ajaxSubmit="true">
                      <t:commandButton action="#{bean.doSomething}"/>
                      In my FireBug-console i can see that there is an AJAX-Request generated and
                      all Values in the bean are uptaded but the method "doSomething" isn't called.
                      My workaround was to use a4j:commandButton.


                      • 8. Re: commandLink in a4j form
                        Ilya Shaikovsky Master

                        It's strange.. my simple example with t:commandButton calls its action..

                        I've used myFaces 1.1.4.. What is your version?

                        • 9. Re: commandLink in a4j form
                          Wolfgang Klaus Newbie

                          Yes that's strange.
                          I'm using myFaces-core 1.1.5 and tomahawk-snapshot 1.1.5.

                          • 10. Re: commandLink in a4j form
                            Wolfgang Klaus Newbie

                            It has nothing todo with the different versions.
                            I currently tried myfaces-1.1.4 and it didn't work.
                            There must be something in my page. I have to research this
                            a little bit.
                            When I change the name of the called action to a name which is not
                            available in the bean, there is no error that this method isn't found.

                            • 11. Re: commandLink in a4j form
                              Ilya Shaikovsky Master

                              If you do not able to found the error you may be can send me your project template via email.

                              • 12. Re: commandLink in a4j form
                                Wolfgang Klaus Newbie

                                After some research I think the problem is in the generated request.
                                Here are both request send from the browser.
                                First with h:form
                                Second with a4j:form

                                In the first request I bolded out what i think is missing in the second.
                                The Button which was clicked is named cmdSuchen.
                                So how can JSF identify which Button was clicked on the page when
                                the value is not submitted?

                                @Ilya: I've made a simple example which I will mail you.


                                • 13. Re: commandLink in a4j form
                                  Wolfgang Klaus Newbie

                                  So some more research.
                                  There is a problem with a4j:form in Verson 1.0.7. After upgrading
                                  to 1.1.0 t:commandButton are working in a4j:form, but there
                                  is still a problem with t:commandLink and IExplorer 6 and tomahawk-1.1.5
                                  I will show what I found out until now.

                                  Here is a simple example:

                                  <%@ page contentType="text/html; charset=ISO-8859-1"%>
                                  <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
                                  <%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>
                                  <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
                                  <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
                                   <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
                                  <body class="dornier">
                                   <a4j:form id="form1" reRender="erg" ajaxSubmit="true">
                                   <%--h:form id="form1"--%>
                                   <h:outputLabel for="idsuchenach" value="Search"></h:outputLabel>
                                   <t:selectOneListbox size="1" id="idsuchenach"
                                   <f:selectItem itemLabel="Kname"
                                   <f:selectItem itemLabel="CustNo" itemValue="kdnr"></f:selectItem>
                                   <f:selectItem itemLabel="Name"
                                   <t:inputText id="idsystem" value="#{a4jformBean.rangeTable}" />
                                   <t:commandButton id="cmdSuchen" styleClass="buttonStyle"
                                   <h:outputText id="erg" value="#{a4jformBean.rangeTable}"/>
                                   <t:commandLink id="clink" action="#{a4jformBean.makeUpper}"><h:outputText value="link"/></t:commandLink>
                                   <a4j:outputPanel ajaxRendered="true">
                                   <h:messages layout="table"></h:messages>
                                   <a4j:log popup="false" width="400" height="200"/>

                                  The method does nothing more than make the input upper.
                                  In Firefox and IExplorer 7 when clicking either on the button or on
                                  the link the text is made upper.

                                  In IExplorer 6 only the method (makeUpper) is called when clicking
                                  on the commandButton.

                                  Looking at the genarated html shows the follwing for the commandLink.
                                  <a href="#" onclick="return oamSubmitForm('form1','form1:clink');" id="form1:clink">link</a>

                                  Ok when clicking on the link some script from tomahawk will be executed, which updates some hidden values. The important hidden fields
                                  for tomahawk are:
                                  _link_hidden and _idcl

                                  "_idcl" is the new hidden field to show jsf what link was pressed.

                                  In the javascript function oamSubmitForm the current form will be submitted.
                                  When submitting the form the A4J Javascript comes in action to
                                  generate an AJAXRequest.
                                  All fields of the form are appended to the url.
                                  In Firefox and IExplorer 7 the value for _idcl looks like this (from log-console):
                                  In IExplorer 6 it looks so:

                                  As you can see null is submitted and therefore jsf doesn't know wich
                                  link was clicked.

                                  There must be a problem with IExplorer 6 when the form is submitted by
                                  javascript and the submit action is also a javascript.
                                  The javascript in the form action didn't see the right values
                                  wich are set by javascript of the link.

                                  So it is not possible for me to Ajaxify t:datascroller with a4j:form as
                                  described in the documentation because of the problem with IExplorer 6.

                                  Has someone see such a behaviour with IExplorer 6.?