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

发布于 2024-11-30 09:31:45 字数 923 浏览 1 评论 0原文

我们有一组 Web 模块,它们彼此是对等应用程序。我们使用 jQuery 将它们混合在一起。这些不同的模块都使用 JSF。不同的模块可以部署在不同的Java EE应用服务器上。

想象一个用于开设帐户的 JSF 页面。该页面可能会利用客户搜索功能来查找要为其开设帐户的客户。带有帐户开立表单的 JSF 页面由一个 Web 模块提供,而客户端搜索页面由另一个 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...

...searchForm 和 openForm 都是 JSF/a4j 页面。

现在,问题在于,当 searchForm 'gadget' 确实调用 a4j 来执行搜索并且它返回新的视图状态 id 时,openForm.xhtml 的视图状态 id 也会更新。当使用 openForm.xhtml 将表单发布到服务器时,视图状态 ID 不同步(因为它们最后是通过 a4j 调用不同的 Web 模块更新的,该模块具有不同的服务器端视图状态)。

有没有一种方法可以隔离适合上述方式的视图状态 id?我们希望能够将 jsf 视图状态与来自不同 Web 模块的混搭组件隔离开来?

We have a group of web modules that are peer applications to one another. We mash them together using jQuery. These differing modules all use JSF. The different modules may be deployed on different Java EE application servers.

Imagine a JSF page for opening an account. 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.

...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.

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. 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).

Is there a way to isolate view state id's appropriate for the manner described above? where we want to be able to isolate jsf view state to mashed-in components from different web modules?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

并安 2024-12-07 09:31:45

所以,这就是我们最终要做的...

我们所有的离散 Web 模块都具有相同的域,但每个模块都有一个唯一的上下文根 www.bank.com/waw/accounts/somepage.xhtml,或 www.bank.com/waw/transfers/somepage.xhtml。我们使用这些上下文根来确定哪些表单应该更新其视图状态。

像这样(这个解决方案不适用于所有想要混搭的人,但它适用于我们)...

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");            
  });
};

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. 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");            
  });
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文