简体   繁体   English

JSF / a4j混搭-查看状态ID已过期

[英]JSF/a4j Mashups - View State ID Expired

We have a group of web modules that are peer applications to one another. 我们有一组Web模块,它们是彼此的对等应用程序。 We mash them together using jQuery. 我们使用jQuery将它们融合在一起。 These differing modules all use JSF. 这些不同的模块都使用JSF。 The different modules may be deployed on different Java EE application servers. 不同的模块可以部署在不同的Java EE应用程序服务器上。

Imagine a JSF page for opening an account. 想象一下一个用于开设帐户的JSF页面。 That page might make use of a customer search feature to look up the customer the account is to be opened for. 该页面可能利用客户搜索功能来查找要为其打开帐户的客户。 The JSF page with the account open form on it is served from one web module, and the client search page is served up from another. 从一个Web模块提供带有开户表格的JSF页面,从另一个Web模块提供客户搜索页面。

...jsf page loaded from http://openaccount.com/openForm.xhtml

... code to load a search from from elsewhere...
<script type="text/javascript">
   jQuery(document).ready(function () {
      jQuery('#search_gadget').load('http://search.com/searchForm.xhtml');
                        });
</script>
<search_gadget/>
<br/> .. the rest of the open account form...

...both searchForm and openForm are JSF/a4j pages. ... searchForm和openForm都是JSF / a4j页面。

Now, the trouble is that when the searchForm 'gadget' does makes a4j calls to perform searches and new view state id's are returned by it, the view state id's of the openForm.xhtml are updated as well. 现在,麻烦在于,当searchForm'gadget'确实执行了a4j调用以执行搜索并由此返回了新的视图状态ID时,openForm.xhtml的视图状态ID也将被更新。 When the openForm.xhtml is then used to post the form to the server the view state id's are out of synch (since they were last updated by a4j calls to a different web module, which has a differing server side view state). 然后使用openForm.xhtml将表单发布到服务器时,视图状态ID不同步(因为它们最后一次通过a4j调用而更新到另一个Web模块,该Web模块具有不同的服务器侧视图状态)。

Is there a way to isolate view state id's appropriate for the manner described above? 有没有办法隔离适用于上述方式的视图状态ID? where we want to be able to isolate jsf view state to mashed-in components from different web modules? 在哪里我们希望能够将jsf视图状态隔离到来自不同Web模块的混搭组件中?

So, here is what we ended up doing... 所以,这就是我们最终要做的...

All our discrete web modules have the same domain, but each has a unique context root www.bank.com/ waw/accounts /somepage.xhtml, or www.bank.com/ waw/transfers /somepage.xhtml. 我们所有离散的Web模块都具有相同的域,但是每个模块都有唯一的上下文根www.bank.com/ waw / accounts /somepage.xhtml或www.bank.com/ waw / transfers /somepage.xhtml。 We use these context roots to scope which forms should have their view state updated. 我们使用这些上下文根来确定应该更新其视图状态的表单的范围。

like so (this solution wont work for all ppl that want to mash, but it works for us)... 像这样(此解决方案不适用于所有想要混搭的人,但它对我们有用)...

var wlf_a4jAjaxProcessResponse = A4J.AJAX.processResponse;

function wlf_ajaxIsolate(req){

wlf_saveViewState(req.form);
wlf_a4jAjaxProcessResponse(req);
wlf_restoreViewState();
}

A4J.AJAX.processResponse = wlf_ajaxIsolate;     


function wlf_saveViewState(form) {

  var action = form.baseURI;

  if (typeof action !== 'undefined') {

        var i1 = action.indexOf("/waw/");
        var i2 = action.indexOf("/", i1+5);
        var currentPwa = action.substring(i1+5, i2);

        jQuery("#javax\\.faces\\.ViewState").each(function() {

              var form = jQuery(this).closest("form");
              var formAction = jQuery(form).attr('action');
              var i3 = formAction.indexOf("/waw/");
              var i4 = formAction.indexOf("/", i3+5);
              var pwa = formAction.substring(i3+5, i4);

              if (pwa !== currentPwa) {
                jQuery(this).attr('id',"_javax.faces.ViewState_");
                jQuery(this).attr('name',"_javax.faces.ViewState_");    
              }
        });
  }
};


function wlf_restoreViewState() {

  jQuery("#_javax\\.faces\\.ViewState_").each(function() {

        jQuery(this).attr('id',"javax.faces.ViewState");
        jQuery(this).attr('name',"javax.faces.ViewState");            
  });
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM