在页面加载时调用的PrimeFaces oncomplete支持方法 [英] PrimeFaces oncomplete backing method called on page load

查看:249
本文介绍了在页面加载时调用的PrimeFaces oncomplete支持方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PrimeFaces 5.0, JSF 2.2, Glassfish 4.1.1,

PrimeFaces 5.0, JSF 2.2, Glassfish 4.1.1,

我假设我的设置中的某些东西配置不正确,但是我不确定要看什么...

I'm assuming that something in my setup isn't configured correctly but I'm not sure what to look at...

因此,我正在使用Managedbeans来支持JSF页面.如果我使用oncomplete属性,则在页面上的PrimeFace元素内,该方法所引用的方法将在页面加载时调用.我不希望它在每次页面加载时都调用该方法,而且我不认为应该如此!

So I'm using managedbeans to back JSF pages. Within the PrimeFace elements on the page if I use an oncomplete property the method it refers to gets called on the page load. I don't want it to call the method on each page load and i don't believe it should be!

我已经通过几页并在不同元素中对此进行了测试. 我首先注意到一个带有<p:fileupload>元素的问题,当所有文件上传完毕后,我尝试使用oncomplete调用方法. 我随后在<p:commandbuttons>上尝试过此操作,并且在加载页面时调用了oncomplete.

I have tested this through several pages and within different elements. I first noticed this issue with a <p:fileupload> element where I was trying to call a method, using oncomplete, once all the files had been uploaded. I have subsequently tried this on <p:commandbuttons> and the oncomplete is called when the page is loaded.

我已经检查了结果HTML,并且有一个格式正确的<head>标签对.

I have checked the resulting HTML and there is a properly formatted <head> tag pair.

我还完成了带有和不带有oncomplete属性的生成HTML的区别.

I have also completed a diff on the generated HTML with and without the oncomplete property present.

使用:

<button id="j_idt21:j_idt26" 
    name="j_idt21:j_idt26" 
    class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
    onclick="PrimeFaces.ab({s:'j_idt21:j_idt26',onco:function(xhr,status,args){;}});
    return false;" 
    type="submit">`

没有:

<button id="j_idt21:j_idt26" 
    name="j_idt21:j_idt26" 
    class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" 
    onclick="PrimeFaces.ab({s:'j_idt21:j_idt26'});
    return false;" 
    type="submit">

以下是上述HTML的代码,显示了oncomplete在加载任何页面时都会调用该方法.这是我的登录页面.

Here is the code for the above HTML showing that oncomplete invokes a method on any page when it is loaded. This is my login page.

<p:commandButton validateClient="true" value="Login" 
    action="#{loginJSFManagedBean.validateCredentials}" 
    type="submit" 
    ajax="true" 
    oncomplete="#{loginJSFManagedBean.validateCredentials}">
</p:commandButton>

每次登录页面被加载时,即使在页面渲染完成之前,也会调用validateCredentials方法.

Each time the login page is loaded the validateCredentials method is called, even before the page has finished rendering...

这是我的JSF文件上传片段:

here is an snippet of my JSF for my file upload:

<h:form enctype="multipart/form-data">
<p:fileUpload oncomplete="#{JSFManagedBean.extract()}" 
fileUploadListener="#{JSFManagedBean.handleTarFileUpload}" 
mode="advanced"  ></p:fileUpload>
</h:form>

每次加载页面时都会调用extract()方法...

Each time the page loads the extract() method is called...

推荐答案

oncomplete是客户端的JavaScript回调.呈现页面时,您的方法会被调用,因为服务器会评估那些EL表达式,希望它们产生带有要发送的javascript代码的字符串.

oncomplete is a client-side javascript callback. Your methods get called when the page is rendered, because the server evaluates those EL expressions expecting them to result in strings with javascript code to send.

您可能根本不需要这些oncomplete处理程序.对于登录按钮,动作处理程序应该足够了.对于fileUpload,如果您的目标只是按照方法名称的建议提取"上载的文件,则fileUploadListener可能就足够了.

You probably don't need these oncomplete handlers at all. For the login button the action handler should be sufficient. For the fileUpload the fileUploadListener may be sufficient, if your goal is simply to "extract" the uploaded file as the method name suggests.

这篇关于在页面加载时调用的PrimeFaces oncomplete支持方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆