10 Replies Latest reply on Mar 29, 2007 8:14 PM by James May

    ajax4jsf menu link

    James May Newbie

      Hello,

      I was wondering if there is anyway to make a really simple ajax call with ajax4jsf on a menu link? Implementing it without a form and without a backing bean.

      Maybe use it with something like an output link. Then after the link is clicked, the response would update a part of a page.

      I don't want to pass view state or anything else. Just a click a link with a querystring and get the response and update part of a page.

      Is this possible? If so, which is the best way to implement.

      Jim

        • 1. Re: ajax4jsf menu link
          Igor Shabalov Apprentice

          Use jsFunction component, see there
          http://labs.jboss.com/file-access/default/members/jbossajax4jsf/freezone/docs/tlddoc/index.html
          You can render function call and call it onclick at any link.
          That call some action on server and re-render portion on screen.
          If you do not need an action, just create an empty one.

          • 2. Re: ajax4jsf menu link
            James May Newbie

            If not mistaken, the jsFunction needs to be in a form.

            Wouldn't that also pass along the view state?

            Can you give an example of how to implement this? I downloaded the demo but the code doesn't reflect my problem.

            Jim

            • 3. Re: ajax4jsf menu link
              Sergey Smirnov Master

              You are right. It requires the form and keeps the state updated.

              What you want names "Non-Faces Request generates Faces Response" in JSF Specification. According to specification, the lifecycle has a shortcut for this case. Just after Restore Phase, the lifecycle create a new view and jumps to Render Response phase and render the whole view.
              So, where is no room for Ajax response in this scheme if the standard JSF lifecycle is not modified. Ajax4jsf has a custom lifecycle only for getting the resources.

              • 4. Re: ajax4jsf menu link
                James May Newbie

                SergeySirnov,

                Not sure what the answer to your reply is... Are you saying there's no way to do what I want to implement with ajax4jsf? Or that I have to modify the lifecycle to get what I need? (which I have no idea where to start)

                Basically I just want to have different links each with different query strings that update an div element responsible for being updated with content from the ajax response. The response could contain a form.

                My goal is to have one main page for my app. That main page updates itself with the content from other pages. I want to make the app pure ajax.

                So what do you recommend I do?
                I know I could always modify the dom on the main page to include an iframe and then have every page in the iframe use ajax. I'm trying to avoid that. Seems like a ghetto solution.

                Jim

                • 5. Re: ajax4jsf menu link
                  Sergey Smirnov Master

                  Jim,
                  Ajax4jsf is "Ajax for JSF". What you are going to accomplish is not about JSF.
                  Using JSF and following non-JSF approaches is really not anoptimal way to go. So, I recommend do not follow this way.

                  • 6. Re: ajax4jsf menu link
                    James May Newbie

                    sounds good. I guess I will just have to change my app then.

                    • 7. Re: ajax4jsf menu link
                      Igor Shabalov Apprentice

                      May be you just need a form on your main page?

                      • 8. Re: ajax4jsf menu link
                        James May Newbie

                        The direction I took was to keep Ajax4jsf FOR JSF.

                        I found a solution using Prototype. I use that framework for other NON-JSF related javascript operations.

                        Even though the Prototype framework is completely different than Ajax4jsf and for different purposes (lemons and apples) - I find that for most of my requirements (this problem and others) that Prototype can wield the same end results. Even when it comes to form submissions and viewstates.

                        So I'm still using for ajax4jsf for the few certain things (JSF Related), but maybe one day I will find a replacement for that.

                        Jim

                        • 9. Re: ajax4jsf menu link
                          Sergey Smirnov Master

                           

                          "jim.webguru" wrote:

                          I found a solution using Prototype. I use that framework for other NON-JSF related javascript operations.


                          Ajax4jsf uses Prototype. However, it is about 0.3% of the whole functionality.
                          If you replace part of the page using non-JSF request, the new view will be created on the server. As a result, your page will contain representation of several views. JSF architecture does not presume this situation is possible. Some glitches might happen sooner or later.

                          • 10. Re: ajax4jsf menu link
                            James May Newbie

                            I can see that happening. I just need to be really careful that it doesn't.