jsf 使用jquery ajax,如何使用jQuery的AJAX将一个JSF2页面注入另一个页面(How to inject one JSF2 page into another with jQue...

如何使用jQuery的AJAX将一个JSF2页面注入另一个页面(How to inject one JSF2 page into another with jQuery's AJAX)

我正在使用jQuery的.load函数将一个JSF页面加载到另一个页面。

在加载的JSF页面使用某些AJAX功能之前,这非常有效。 发生这种情况时,父JSF页面的AJAX停止工作。 实际上,在将两个页面组合在一起之后,其下一个名为AJAX的页面就是继续工作的页面。 另一页停止工作。 如果我首先使用父页面,则孩子会中断。 如果我先使用孩子,父母就会休息。

难道我做错了什么? 我猜测JSF不是为这种行为而设计的,那很好,但那我该如何去做我想要的呢?

基本上,我们有一个报告页面。 当用户单击指向报表的链接时,我们希望报表动态加载到现有页面中。 这样,用户就不会体验页面刷新。 这是一个相当光滑的行为,但由于页面破坏,显然不太理想。

我想我可以使用包含输出面板中每个报表的页面来执行此操作,然后根据辅助bean中的值确定哪个报表呈现,但我可以看到很多我希望能够“注入”的情况将一个页面转换为另一个页面(例如,对于动态对话框),并且必须将所有内容保存在一个巨大的模板中。

还有其他人遇到过这种问题吗? 你是怎么解决的?

I'm using jQuery's .load function to load one JSF page into another.

This works really well until the loaded JSF page uses some AJAX functionality. When this happens, the parent JSF page's AJAX stops working. In fact, after the two pages are combined whichever page has its AJAX called next is the one that continues to work. The other page stops working. If I use the parent page first, the child breaks. If I use the child first, the parent breaks.

Am I doing something wrong? I'm guessing JSF isn't designed for this sort of behaviour and that's fine but then how do I go about doing what I want?

Basically, we have a report page. When the user clicks the link to a report we would like the report to load dynamically into the existing page. That way, the user doesn't experience a page refresh. It's a pretty slick behaviour BUT obviously isn't ideal due to the pages breaking.

I suppose I could do this with a page that contains every report in an outputpanel and then determine which one is rendered based on a value in the backing bean but I can see lots of occasions where I'd like to be able to "inject" one page into another (for dynamic dialogs for instance) and it would suck to have to keep everything in one giant template.

Has anyone else come across this sort of problem? How did you solve it?

原文:https://stackoverflow.com/questions/7561898

更新时间:2020-09-12 07:09

最满意答案

不要使用jQuery.load() 。 它根本不考虑JSF视图状态,因此所有表单都将无法工作。 而是使用和rendered属性。 这是一个基本的例子:

#{report.name}

...

如有必要,您可以将内容拆分为 。

Do not use jQuery.load(). It does not take JSF view state into account at all, so all forms will fail to work. Rather make use of and rendered attribute instead. Here's a basic example:

#{report.name}

...

You can if necessary split off the content into an .

相关问答

在复合实现中,您需要#{cc.clientId}而不是#{cc.attrs.id} 。

否则它将以而不是 ,然后JavaScript无法再找到它,从而导致此malformedXML错误。 一旦你修复了那个部分,那么你可以在引用它,就像你在同一个表单中引用任何其他非复合组件一样: 按钮是表单中的第一个按钮。 我用原型来实现这一目标。 下面是按下Enter键时将处理表单提交的脚本示例: var FormSubmissionHandler = Class.create({

initialize: function(formId, submitterId) {

this.form =

...

不要使用jQuery.load() 。 它根本不考虑JSF视图状态,因此所有表单都将无法工作。 而是使用和rendered属性。 这是一个基本的例子:

#{report.name}

...

我们转到另一个组件lib。 我们正在部署到WAS,所以无论如何这都很令人头痛。 We moved on to another component lib. We were deploying to WAS, so it was a headache anyway.

试试这个:用h:panelGroup wrapGroup包装drop2给它一个Id并渲染它 而不是render="drop2" do render="drop2_wrapper" 这应该消除重复 Try this : wrap the drop2 with a h:panelGroup give it an Id and render it Instead of render="drop2" do render="drop2_wrapper" that should eliminate dupli

...

我不是JSF 2专家,因为我们仍在使用1.2但是我猜它们在这里具有相同的属性:经常调用getter,例如在恢复视图阶段重建视图时。 因此,您不能仅依赖于为实际渲染的部件调用的getter。 实际上,您不应该在getter中执行任何代价高昂的操作(例如db访问) - 在大多数情况下,您不知道它们在一个循环中实际调用的频率。 特别是你的getStuff()方法应该被改变,让getter引起副作用的几乎总是糟糕的设计,比如在这种情况下添加到内部列表中的东西。 编辑:澄清对getter的评论: 通常情况下

...

一个方便的技巧是使用动态ui:include标签,如:

其中content1是一个带有路径和.xhtml文件名的字符串(通常类似于/WEB-INF/content/page1.xhtml),并且父div可用于更新。 A handy trick for this is using a dynamic ui:include tag like

...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值