6 Replies Latest reply on Jul 27, 2009 1:14 AM by Anton Trapp

    Layouting and a4j:regions? (Newbie question?)

    Anton Trapp Newbie

      Hello RichFaces community!

      I just started with RichFaces some days ago (was the winner of my JavaScript Ajax frameworks for Java), so maybe I got something totally wrong from the books, tutorials and googled pages I allready read...

      I have a panelGrid (for the layouting of labels and input elements) and two selections (regions depending on nations). The code is pretty simple and looks like this:

      <h:panelGrid columns="2">
      ...
      <h:outputText value="#{mls.country}"/>
       <a4j:region renderRegionOnly="true">
       <h:selectOneMenu id="nation" value="#{nation}">
       <f:selectItems value="#{companyAddressBean.nations}"/>
       <a4j:support event="onblur" actionListener="#{companyAddressBean.changeCountry}" process="region_area"/>
       </h:selectOneMenu>
       </a4j:region>
      
       <h:outputText value="#{mls.region}"/>
       <a4j:region renderRegionOnly="true" id="region_area">
       <h:selectOneMenu id="region" value="#{companyAddressBean.company.address.region}">
       <f:selectItems value="#{companyAddressBean.regions}"/>
       </h:selectOneMenu>
       </a4j:region>
      


      Now I have some questions that I can't answer from the books and manuals:

      1) The a4j:region should imho be a logical group, but it does group all elements in the output and renders them as one. So I can not create a4j:regions over multiple lines, right? (maybe someone can tell me why the region is a layout and a logical grouping element or what element for the grouping only I missed).

      2) When I change the region (a4j:support) the call goes to the backend and works as expected, but the process statement does not trigger a reRender (the reRender does not work in this case because of the seperate regions). The region - selectOneMenu is only populated at page requests. How can I rerender this area when something in the first changes (as I think there is no solution for a region over multiple lines)?

      3) Is the panel/region the best layout for classic HTML pages with label/field and Ajax validation)? This is used in all the tutorials I read...

      Thank you very much in advance!

      Greetings,

      Anton



        • 1. Re: Layouting and a4j:regions? (Newbie question?)
          Roland Schöler Newbie

          Hi Anton, nice to have you here and your name sounds similar to the region where I'm from.....8-}

          Don't know if it is allowed, but I'll try. My first attemptions were similar to your's - internet search, internet tutorials etc., but later on, I've found a book which has helped me to save a lot of time. I would suggest this to you:
          http://www.amazon.de/Practical-Richfaces-Max-Katz/dp/1430210559/ref=sr_1_1?ie=UTF8&s=books-intl-de&qid=1248435867&sr=8-1

          But this book is only a starting point - for my opinion a very good, and userfriendly starting point.

          Nevertheless you could also search through Developer Guide and the useful online-demo:
          http://livedemo.exadel.com/richfaces-demo/richfaces/region.jsf;jsessionid=34AE10ACA175FC7F8232303C1310EF62?c=region&tab=usage

          Now I'll try to answer your question (from my understanding or from the book above):
          1) a4j:region let's you specify, which components will be processed (processed includes decoding,conversion etc.). And it's up to you how big your a4j:region is. You must be aware, that this will have affects inside this region. Rerendering is done with the keyword reRender, initated from a ajax-able component (e.g. a4j:support)

          2)Rerendering could be done with reRender="Component-ID" - just try to add reRender="region_area" to your a4j:support.

          Also you should play a little bit around with some keywords to get a feeling for what you do.

          3) Don't know, but don't forget standard-JSF components are not AJAX-able by default. For such components you could use a4j:support (=adds AJAX functionality to any standard JSF component - you only must ensure, that this component contains the event, which you use for triggering ajax)

          Short conclusion to topic AJAX:
          Although you use AJAX - always the whole page will be submitted!
          But only parts of this page will be processed, e.g. the components inside the a4j:region etc.

          Regards
          rschoeler

          • 2. Re: Layouting and a4j:regions? (Newbie question?)
            Anton Trapp Newbie

            Thank you for your answer!

            I don't think, that reRender is working outside the renderRegionOnly="true" region, that's why I tried the process directive.

            If I reRender a region on the screen, are then only the richfaces components rerendered? Than it is impossible (without jQuery native JavaScript programming) to display two comboboxes (h:selectOneMenu) in a parent/child relationship? That sounds very odd to me...

            What would be great would be one tutorial that is not only a hello world one. Is there anything that covers typical application features (Ajax validation of elements *lol*, layouting a form, master/slave relationships)? Would make the whole thing a lot easier to learn than googling around for weeks...

            Regards,

            Anton

            • 3. Re: Layouting and a4j:regions? (Newbie question?)
              Nick Belaevski Master

              Hi,

              I don't think, that reRender is working outside the renderRegionOnly="true" region, that's why I tried the process directive.

              Yes, when renderRegionOnly="true", re-rendering is limited to the region. Note that renderRegionOnly="false" by default. JSF lifecycle can be divided into two parts: 'execute' (all phases except 6(RENDER_RESPONSE)) and 'render'. 'process' attribute affects 'execute' part; reRender affects 'render'. 'renderRegionOnly' affects rendering and allows to narrow re-rendering to the scope of components just inside this region. This can be useful, because there are some components that are re-rendered on each AJAX request (e.g. rich:message(s)) and this may cause unwanted effects.

              If I reRender a region on the screen, are then only the richfaces components rerendered? Than it is impossible (without jQuery native JavaScript programming) to display two comboboxes (h:selectOneMenu) in a parent/child relationship? That sounds very odd to me...

              Please let me clarify on this: components from another frameworks (like standard JSF ones, MyFaces Tomahawak, etc) and not only RF ones can be re-rendered.
              The only rule that applies to regions/'process' is that this stuff is processed for request initiated by some AJAX component (a4j:support, a4j:commandLink, a4j:commandButton, a4j:form, rich:* components that have common AJAX attributes like 'process', 'reRender', 'eventsQueue', etc). So, if you use h:commandLink to submit form, then regions are not being processed; if you've used a4j:commandLink, then regions are processed.

              What would be great would be one tutorial that is not only a hello world one. Is there anything that covers typical application features (Ajax validation of elements *lol*, layouting a form, master/slave relationships)? Would make the whole thing a lot easier to learn than googling around for weeks...

              I'd suggest to start from here: http://www.jboss.org/community/wiki/RichFacesWikiHomePage and check "Reference card" and "Online demos" first.

              P.S. http://opensource.sys-con.com/node/1041893


              • 4. Re: Layouting and a4j:regions? (Newbie question?)
                Anton Trapp Newbie

                Thanks!

                I allready used the regions with the renderRegions because of the tutorial to validate each field seperate, so almost everything seems to work like I thought...

                The link to the region introduction is great, it inspired the sample I posted ;)

                It seems, that my problem is that process does only work with ajaxSingle and that there is no way to update something outside of a renderRegionOnly but plain Javascript.

                I think I try the a4j:outputpanel (the description of this component and the renderRegionOnly don't make it clear if it will work) and if that does not work I program the whole stuff with jQuery. Sad but true... (as Metallica would say).

                Best regards,

                Anton

                • 6. Re: Layouting and a4j:regions? (Newbie question?)
                  Anton Trapp Newbie

                  Thank you very much!

                  Would be a great new feature if this would work with regions too, but at the moment I can find my way around this limitation.

                  Regards,
                  Anton