6 Replies Latest reply on Sep 1, 2010 2:53 AM by Andreas Hoehmann

    Problem rendering form

    Gustavo Vera Newbie

      Hi all!

       

      I hope somebody can help me with this issue: I have 2 forms(form A, form B) in a webpage. I don't want that form B loads when the page loads for the first time but when the user clicks on an action link inside form A.

      This is the code I have:

       

                Code from form A:

                               ..............................                   
                               <rich:spacer width="10" />
                              <a:commandLink  action="#{clipList.loadClipsByOrder(_currentorder)}" ajaxSingle="true"
                                             reRender="orderDetails">
                                  <s:graphicImage value="/img/show.gif" />
                              </a:commandLink>

                               ................................

       

       

                Code from form B:

                               ................

                             <h:form  style="width:910px" id="orderDetails" border="0" cellspacing="0" cellpadding="0" rendered="#{clipList.orderFilter}">
                              <h:outputText value="No clips for that order" rendered="#{empty clipList.resultList}"/>
                                <rich:panel style="width: 910px; margin:0; padding:0"  rendered="#{not empy clipList.resultList}">

                               ................................................

                Code from my bean:

                     public class ClipList extends ExtendedEntityQuery<Clip> {

                         private static final long serialVersionUID = 6725812087867495437L;

                         private static final String EJBQL = "select clip from Clip clip";

                         private static final String[] RESTRICTIONS = { "lower(clip.name) like concat(lower(#{clipList.clip.name}),'%')", "clip.order =                                                                                      #{clipList.clip.order}",    "clip.status = #{clipList.clip.status}" };

                         private Clip clip = new Clip();

                         private Boolean orderFilter = Boolean.FALSE;

                          ...........................................

       

      clipList.orderFilter is a flag from my bean that is activaded when the user clicks on the Form A link, it is false by default.

      I thought the use of this flag would be the solution but I had no results. I read a related topic in this forum (http://community.jboss.org/thread/148735?tstart=0 ) but the way it was solved doesnt work for me.

       

      Thanks for your help!

        • 1. Re: Problem rendering form
          liumin hu Master

          hi,

           

          you cant rerender orderDetails because it is not rendered. you need  put your form B in a outputpanel with this id.

           

          liu

          • 2. Re: Problem rendering form
            Gustavo Vera Newbie

            Thanks for your answer. I made the changes as you suggested. The problem was that my form has CSS and its borders were shown when the page loaded and I wanted it to be show only when there were content available, i.e. when the user clicks the commandlink. To solve that problem I took the idea of the post I wrote above and your idea:

            This is what I did, just in case somebody in the future faces the same issue :

             

            -------------------------

            <rich:spacer width="10" />
                                    <a:commandLink  action="#{clipList.loadClipsByOrder(_order)}" ajaxSingle="true"
                                                    onclick="$('detailsContainer').removeClassName('hideOnLoad')"
                                                    reRender="orderDetails">
                                        <s:graphicImage value="/img/show.gif" />
                                    </a:commandLink>

            ---------------------------

            <a:outputPanel id="detailsContainer" styleClass="hideOnLoad">
                        <h:form  id="orderDetails" style="width:910px"  border="0" cellspacing="0" cellpadding="0">
                        <h:outputText value="Keine Clips für die Bestellung verfügbar" rendered="#{empty clipList.resultList and clipList.orderFilter}" id="textClip"/>
                        <rich:panel
                            style="width: 910px; margin:0; padding:0"
                            rendered="#{not empty clipList.resultList and clipList.orderFilter}">
                            <div><rich:dataTable

            -----------------------------

            .hideOnLoad {
                 display: none;
            }

             

            I don't know if it is the correct way to solve the problem.. if there is a better solution I would be grateful

             

            Thanks!

            • 3. Re: Problem rendering form
              liumin hu Master

              hi,

               

              you can keep the rendered on your form, just give his id to the outputpanel.

               

              liu

              • 4. Re: Problem rendering form
                Rob Acraman Newbie

                Your original problem is that conditionally rendered components (ie. having a "rendered=" attribute) should NEVER be in the target list of a "reRender=".

                 

                See http://community.jboss.org/wiki/CommonAjaxRequestsProblems#conditionalRendering :

                 

                reRender attribute should not be pointed to  conditionally rendered elements, because the framework has no idea where  to add the element which wasn't in DOM before. Parents of such  components should be reRendered instead.

                 

                 

                As liumin said, just wrap your form in an outputpanel and reRender that - eg:

                 

                <a:commandLink  action="#{clipList.loadClipsByOrder(_order)}" ajaxSingle="true"
                                                        onclick="$('detailsContainer').removeClassName('hideOnLoad')"
                                                        reRender="detailsContainer">

                 

                <a:outputPanel id="detailsContainer">

                                        <h:form  style="width:910px" id="orderDetailsForm" border="0"  cellspacing="0" cellpadding="0" rendered="#{clipList.orderFilter}">

                1 of 1 people found this helpful
                • 5. Re: Problem rendering form
                  Gustavo Vera Newbie

                  Since I am beggining using AJAX, JBoss and Seam this piece of advice is very helpful.

                  Thanks for that!

                  • 6. Re: Problem rendering form
                    Andreas Hoehmann Newbie

                    Hi,

                     

                    Have a look into the links posted by the other guys ... there you can find the information

                     

                    Some points:

                     

                    1. if you use rendered attribute on a jsf component then the ui-representation (html) of the component can be included or excluded

                         - one time the browser shows the html, other time doesn't depends on the the "rendered value (true/false)"

                     

                    2. then think about the dom (html-tag-structure) inside your browser ...

                     

                         <div id="foo">

                            <br/>

                            <p id="bar">

                               some content

                            </p>

                         </div>

                     

                       If you remove the p element (id=bar) it's easy ... find the id then remove the element from the dom.

                     

                       But if you add such a element ... you must find a target for that "new" element ... and such a "parent" element

                       must always be there .. thats the point

                     

                    I hope I hep you ... read the other links!

                     

                    Regards

                    Andreas

                    -[http://www.ahoehma.de]-