javing
javing

Reputation: 12423

How to pass a parameter to a javascript function on a JSF 2.0 page

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

Upvotes: 2

Views: 8055

Answers (2)

Matt Handy
Matt Handy

Reputation: 30025

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>  

Upvotes: 3

niksvp
niksvp

Reputation: 5563

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

Example here.

Upvotes: 0

Related Questions