2

I want to process the value of an inputSecret using onblur functionality but I obtain the error Couldn't invoke method getOnblur

<b:column span="3">
     <p:outputLabel value="#{msg.confirmPassword}" />
     <b:inputSecret value="#{workerDetail.confirmPassword}" onblur="#{workerDetail.checkPassword}"/>
</b:column>

This is the method on the backing bean:

public void checkPassword(AjaxBehaviorEvent event)
{
    System.out.println(confirmPassword);
}

How can I solve?

xc93hil
  • 105
  • 1
  • 9

1 Answers1

1

BootsFaces takes a slightly different approach to AJAX than the other JSF frameworks. The idea is to simply use the JavaScript callback functions to call a method in a Java backend bean. However, we also want to preserve compatibility to other JSF frameworks, so we couldn't follow you approach, as tempting as it may be. Instead, we decided to precede the AJAX call by an ajax: prefix. It's followed by an EL expression which also defines the parameter list. In other words: other than standard JSF, BootsFaces doesn't pass the event parameter.

TL;DR: Simply change your onblur attribute like so:

<b:column span="3">
     <p:outputLabel value="#{msg.confirmPassword}" />
     <b:inputSecret value="#{workerDetail.confirmPassword}" onblur="ajax:workerDetail.checkPassword()"/>
</b:column>

Please note the brackets following checkPassword. It's an EL expression which is executed when the event has been triggered and sent to the Java backend.

The resulting backing bean method doesn't need the event parameter:

public void checkPassword()
{
    System.out.println(confirmPassword);
}

The difference to your approach is that your EL expression was evaluated when the page is rendered - which is a tad to early.

Stephan Rauh
  • 3,069
  • 2
  • 18
  • 37
  • I follow your instructions but method checkPassword is never called! – xc93hil Aug 24 '16 at 07:49
  • It's hard to track down your problem without knowing what you did precisely. So I suggest you share a little reproducer of your problem on GitHut. In most cases, this allows us to find the mistake quickly. Thanks in advance, Stephan – Stephan Rauh Aug 25 '16 at 19:06
  • Now it works! The method checkPassword is called regularly. I inserted in this method also a Faces Message: FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, title, message)); but any growl is shown. Here the GitHub repo: https://github.com/cler27/TestWeb – xc93hil Aug 31 '16 at 10:31
  • What do I have to do to reproduce the error? Tomcat shows an error message because I don't have MySQL installed. Do I need it? After that, I tried to start the application using the URL 127.0.0.1 and 127.0.0.1/login.jsf, but nothing happened. Any hints? – Stephan Rauh Sep 01 '16 at 20:30
  • Yes, You need to install a database, choose your favourite and then configure driver in file application.properties – xc93hil Sep 09 '16 at 15:34