我已经在控制器中创建了侦听器,诸如此类.
I have created listener in my controller, something like that..
public class FooController { public void doSomething(AjaxBehaviorEvent evt) { closeDialogFlag = true; .. if(!isValid){ closeDialogFlag = false; } } }还有我的JSF按钮.
<h:commandButton value="Do somenthing"> <f:ajax listener="#{fooController.doSomething}" execute=":editDialogForm:processTab" render="@this :editDialogForm:processTab :messageViewer:messageViewerPanel :results" onevent="function(data){ if(data.status === 'success' && #{fooController.closeDialogFlag} ) { $('#migrationEditDialogModal').modal('hide'); } }" /> </h:commandButton>但是我的 closeDialogFlag 在ajax请求完成后不起作用,因为值#{fooController.closeDialogFlag} 会在页面加载时提取,并且在AJAX之后不会更新要求.我需要刷新页面才能在输出代码中看到新值.
But my closeDialogFlag doesn't work after ajax request is completed, bacause value #{fooController.closeDialogFlag} is extracted when page is loading and is not updated after AJAX request. I need to refresh a page to see new value in output code.
问题是:如何在侦听器的 onevent = function(data)中将其他信息传递给 data ?(此解决方案更适合我,因为它在各种情况下都会有用) OR 是否可以通过任何方法在侦听器中终止我的请求并强制我的AJAX请求返回除 success ?
The question is: How can I pass additional information to data in onevent=function(data) in my listener? (This solution is more appropriate to me because it will be useful in various cases) OR Is any way to abort my request in my listener and force my AJAX request to return another status than success?
PS:我不想使用Primefaces,Richfaces等.
PS: I don't want use Primefaces, Richfaces etc.
修改:小修正.如果我添加到我的 f:ajax 中以赋予属性 render 值 @this ,则成功提取我的标志为 true 但实际上在我的AJAX请求之后,我的对话框没有被JavaScript函数隐藏.
Edit: small correction. If i add to my f:ajax to attribute render value @this, than my flag is extracted successful as true but in fact after my AJAX request my dialog is not hidding by JavaScript function.
推荐答案以下是针对您的特定问题的小技巧:
Here's a little trick for your specific problem:
您将必须更改 $('input#closeDialogFlag')指向正确的ID(取决于父母的ID).
You will have to change $('input#closeDialogFlag') to point to the correct ID (will depend on the parents' id).
之所以可行,是因为当 data.status ==='成功'时,组件已经使用其新值进行渲染.
This works because when data.status === 'success', the components are already rendered with their new values.
更多推荐
有什么方法可以中止AjaxBehaviorEvent侦听器或将其他信息传递给f:ajax onevent?
发布评论