0

I have a jsf 1.2 application with some links in the index page. This links are oppened by clicks, on new jquery dialogs. Every link open a new page of my app in a distinct dialog, so, the application can open many links in many dialogs in a single page. All my managed beans have session scope.

My problem is, when i open a new dialog and click in any link inside, my application still works fine, but after this, if i click in other link in my index page to open another dialog, the app shows me a ViewExpiredException. I have tried update my jsf to 2.0, set EnableRestoreView11Compatibility in web.xml to true, use keepAlive in my beans, but nothing works.

I think its happened because i have a main page with one state and, when i click to open a new page in a jquery dialog, it loads the entire page and put the html inside. So, the request made no reference to the state of main page. How can i resolve this?

Avinash Singh
  • 3,421
  • 2
  • 20
  • 21
Pedro Vítor
  • 191
  • 1
  • 6
  • Are you using ? Are you making a service call while clicking the link or just showing a static page as pop-up? – Dinal Jun 09 '14 at 13:37
  • Hi @Dinal, thanks for answer. I'm using a function to open the dialog. This function creates a div, fill this with other page and open the jquery dialog. I'm using a4j:commandButton. And yes, the page is a jsp page that is sent to server. – Pedro Vítor Jun 09 '14 at 13:41
  • I think its a pure javascript functionality. If you are not using any actionListener calls why use richfaces. Normal tags would server the purpose rt? – Dinal Jun 09 '14 at 13:52
  • No, because i have a actionListener method in my managed beans to do some actions when the user click on the link. My a4j:commandLink has a actionListener to process the request and a oncomplete to call the javascript function. – Pedro Vítor Jun 09 '14 at 13:58
  • 1
    Have a look at this answer from @BalusC http://stackoverflow.com/questions/11408130/jsf-commandbutton-works-on-second-click – Avinash Singh Jun 09 '14 at 18:54
  • @AvinashSingh It seems to work with jsf 2.x... I'm using jsf 1.2. But i will try this, thanks! – Pedro Vítor Jun 09 '14 at 20:48

1 Answers1

1

It seems like the bug in JSF which is not fixed yet , it is planned for fix in JSF 2.3

You can use the below workaround posted in java.net for the jquery.

http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-790

var patchJSF = function () {
  jsf.ajax.addOnEvent(function (e) {
    if (e.status === 'success') {
      $("partial-response:first changes:first update[id='javax.faces.ViewState']", 
       e.responseXML).each(function (i, u) {
        // update all forms
        $(document.forms).each(function (i, f) {
          var field = $("input[name='javax.faces.ViewState']", f);
          if (field.length == 0) {
           field = $("<input type=\"hidden\" name=\"javax.faces.ViewState\" />").
                    appendTo(f);
          }
          field.val(u.firstChild.data);
        });
      });
    }
  });
}
Avinash Singh
  • 3,421
  • 2
  • 20
  • 21
  • Thanks to answer, but this is not the problem... I have tried this. The problem is, when my dialog shows, a new viewstate is created. When i work with this new dialog, jsf changes and update this viewstate but not the others (in case i have many dialogs, each dialog have your viewstate). So, when i close my dialog and click in the main page (with a non-updated viewstate) the stacktrace is shown. I found this link about this problem: http://www.irian.at/en/blog/-/blogs/jsf-ajax-and-multiple-forms – Pedro Vítor Jun 09 '14 at 18:22
  • @PedroVítor I missed that you were using Ajax to update multiple forms on page. I have edited my answer with reference from java.net – Avinash Singh Jun 09 '14 at 19:08
  • Well, i read this and seems to be exactly what i need! I cant do the changes right now but will do it tomorrow. Hope this works with JSF 1.2... – Pedro Vítor Jun 09 '14 at 20:46