如何将参数传递给 JSF 2.0 页面上的 javascript 函数

发布于 2024-10-31 19:55:21 字数 2139 浏览 1 评论 0原文

我正在制作一个自定义登录对话框,类似于 http://www.primefaces 上找到的对话框.org/showcase/ui/dialogLogin.jsf 但我在构建时遇到错误:

javax.el.PropertyNotFoundException:/WEB-INF/templates/BasicTemplate.xhtml @58,83 oncomplete =“handleLoginRequest(#{securityController.logIn})”:类“managementbeans.SecurityController”没有属性“登录'。

我认为错误在于我尝试触发日志记录程序的方式。有人可以看看我的语法是否正确吗?

  <p:dialog id="dialog" header="Login" widgetVar="dlg" modal="true" width="400" resizable="false" draggable="false" fixedCenter="true">  
<h:form>    
    <h:panelGrid columns="2" cellpadding="5">  
        <h:outputLabel for="username" value="Em@il: *" />  
        <p:inputText value="#{securityController.email}"   
                id="email" required="true" label="email" />  

        <h:outputLabel for="password" value="Password: * " />  
        <h:inputSecret value="#{securityController.password}"   
                id="password" required="true" label="password" />  

        <f:facet name="footer">  
            <p:commandButton value="Login" update="growl"                       
                oncomplete="handleLoginRequest(#{securityController.logIn})"/>  
        </f:facet>  
    </h:panelGrid>           
</h:form>  
</p:dialog> 
<script type="text/javascript">  
function handleLoginRequest(input) {  
    if(input == false) {  
        jQuery('#dialog').parent().effect("shake", { times:3 }, 100);  
    } else {  
        dlg.hide();  
        jQuery('#loginLink').fadeOut();  
    }  
 }  
</script> 

这是托管 bean,它保存正在调用 onComplete 事件的方法:

@ManagedBean
@RequestScoped
public class SecurityController {

@EJB
private IAuthentificationEJB authentificationEJB;
private String email;
private String password;
private String notificationValue;   

public void logIn() {
    if(authentificationEJB.saveUserState(email, password)) {
        notificationValue = "Dobro dosli";
    }   
}
    //getters and setters...

I am making a custom login dialog, similar to the one found on http://www.primefaces.org/showcase/ui/dialogLogin.jsf but i get an error when building:

javax.el.PropertyNotFoundException: /WEB-INF/templates/BasicTemplate.xhtml @58,83 oncomplete="handleLoginRequest(#{securityController.logIn})": The class 'managedbeans.SecurityController' does not have the property 'logIn'.

I think the mistake is in the way i try to trigger the logging procedure. Could someone have a look if my syntax is correct?

  <p:dialog id="dialog" header="Login" widgetVar="dlg" modal="true" width="400" resizable="false" draggable="false" fixedCenter="true">  
<h:form>    
    <h:panelGrid columns="2" cellpadding="5">  
        <h:outputLabel for="username" value="Em@il: *" />  
        <p:inputText value="#{securityController.email}"   
                id="email" required="true" label="email" />  

        <h:outputLabel for="password" value="Password: * " />  
        <h:inputSecret value="#{securityController.password}"   
                id="password" required="true" label="password" />  

        <f:facet name="footer">  
            <p:commandButton value="Login" update="growl"                       
                oncomplete="handleLoginRequest(#{securityController.logIn})"/>  
        </f:facet>  
    </h:panelGrid>           
</h:form>  
</p:dialog> 
<script type="text/javascript">  
function handleLoginRequest(input) {  
    if(input == false) {  
        jQuery('#dialog').parent().effect("shake", { times:3 }, 100);  
    } else {  
        dlg.hide();  
        jQuery('#loginLink').fadeOut();  
    }  
 }  
</script> 

And this the managed bean that holds the method that is being called onComplete event:

@ManagedBean
@RequestScoped
public class SecurityController {

@EJB
private IAuthentificationEJB authentificationEJB;
private String email;
private String password;
private String notificationValue;   

public void logIn() {
    if(authentificationEJB.saveUserState(email, password)) {
        notificationValue = "Dobro dosli";
    }   
}
    //getters and setters...

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

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

发布评论

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

评论(2

指尖微凉心微凉 2024-11-07 19:55:21

您必须从 p:commandButtonactionListener 属性调用登录方法,而不是在 oncomplete 属性内调用。示例中的 javascript 函数无需更改即可使用。仅用于展示效果。

以这种方式更改您的 p:commandButton

<p:commandButton value="Login" update="growl"                       
       oncomplete="handleLoginRequest(xhr, status, args)"
       actionListener="#{securityController.logIn}"
/>

并使用与 primefaces 展示中完全相同的 js 函数:

<script type="text/javascript">  
    function handleLoginRequest(xhr, status, args) {  
        if(args.validationFailed || !args.loggedIn) {  
            jQuery('#dialog').parent().effect("shake", { times:3 }, 100);  
        } else {  
            dlg.hide();  
            jQuery('#loginLink').fadeOut();  
        }  
    }  
</script>  

You have to call your login method from the actionListener attribute of p:commandButton and not inside the oncomplete attribute. The javascript function from the example can be used without changes. It is only for displaying the effect.

Change your p:commandButton this way:

<p:commandButton value="Login" update="growl"                       
       oncomplete="handleLoginRequest(xhr, status, args)"
       actionListener="#{securityController.logIn}"
/>

And use the js function exactly as in the primefaces showcase:

<script type="text/javascript">  
    function handleLoginRequest(xhr, status, args) {  
        if(args.validationFailed || !args.loggedIn) {  
            jQuery('#dialog').parent().effect("shake", { times:3 }, 100);  
        } else {  
            dlg.hide();  
            jQuery('#loginLink').fadeOut();  
        }  
    }  
</script>  
暮光沉寂 2024-11-07 19:55:21

如果您想在 javascript 事件上执行方法,请使用

示例 此处

If you want to execute method on a javascript event then use <a4j:jsfunction>

Example here.

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