[JAVA] What to do when Method not found in f: ajax

Event: When I tried to run f: ajax, I got an error on the console and it didn't work.

--Environment - CentOS Linux release 7.8.2003 (Core) - Eclipse IDE for Enterprise Java Developers.Version: 2020-03 (4.15.0) - openjdk version "11.0.7" 2020-04-14 LTS - JSF 2.3.9

Eclipse console log


javax.el.MethodNotFoundException: /base.xhtml @17,113 listener="#{uploadBean.uploadFile}": Method not found: class brans.UploadBean.uploadFile(javax.faces.event.AjaxBehaviorEvent)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:69)
    at com.sun.faces.facelets.tag.jsf.core.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxHandler.java:403)
    at javax.faces.event.AjaxBehaviorEvent.processListener(AjaxBehaviorEvent.java:100)
    at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:82)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:481)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:847)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1395)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:58)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:76)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:177)
    at javax.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:707)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:451)
...abridgement...

UploadBean.java


...abridgement...
    public void uploadFile(FacesContext fc, UIComponent uic, Object value) throws IOException {
        if (!isUpload()) {
...abridgement...

base.xhtml


...abridgement...
<f:ajax event="change" execute="uploadArea" render="uploadArea" listener="#{uploadBean.uploadFile}" />
...abridgement...

Cause: The method parameters are different (overloaded)

"Method parameters are different" = "Different method" = "There is no method specified in the listener attribute" When I tried various things ... inadvertently ... when I thought about it, it was natural, but it turned out to be "uh?"

Countermeasure 1: Match not only the method name but also the argument with the listener attribute

UploadBean.java


    public void uploadFile() throws IOException {
//Or
    public void uploadFile(AjaxBehaviorEvent event) throws IOException {

If you receive javax.faces.event.AjaxBehaviorEvent, you can get the Faces context with getFacesContext.

AjaxBehaviorEvent represents the behavior of Ajax-specific components). AjaxBehaviorEvent (Jakarta EE 8 Specification API) --Javadoc Japanese translation

Countermeasure 2: Add an argument to the method specified in the listener attribute

base.xhtml


<f:ajax event="change" execute="uploadArea" render="uploadArea" listener="#{uploadBean.uploadFile(hoge, fuga, value)}" />

Recommended Posts

What to do when Method not found in f: ajax
What to do when Method not found in f: ajax
What to do when debugging "Source not found"
What to do when undefined method ʻuser_signed_in?'
What to do when the changes in the Servlet are not reflected
What to do when IllegalStateException occurs in PlayFramework
What to do when JSF tags do not become HTML
<f: ajax> Unable to attach <f: ajax> to non-ClientBehaviorHolder What to do when you become a parent
What to do when rails db: seed does not reflect in the database
What to do when Cannot apply expression operators to method binding
What to do when javax.batch.operations.JobStartException occurs
What to do when a could not find driver appears when connecting to a DB in a Docker environment
What to do when Rails on Docker does not reflect controller changes in the browser
What to do when an UnsupportedCharsetException occurs in a lightweight JRE
[Rails] What to do if data is not registered in DB
[Rails] What to do when rails s does not respond or does not stop
What to do when a javax.el.PropertyNotWritableException occurs
Do not return when memoizing in Ruby
What to do when "relation" hibernate_sequence "does not exist" in the ID column of PostgreSQL + JPA
What to do when you want to know the source position where the method is defined in binding.pry
What to do when javax.el.ELException: Not a Valid Method Expression: appears when the JSF screen is displayed
What to do if the prefix c is not bound in JSP
What to do when Blocked Host: "host name" appears in Ruby on Rails
What to do and how to install when an error occurs in DXRuby 1.4.7
What to do if tomcat process remains when tomcat is stopped in eclipse
Notes on what to do when a WebView ClassNotFoundException occurs in JavaFX 12
What to do if Operation not permitted is displayed when you execute a command in the terminal
What do you use when converting to String?
What to do when you think you can't do Groovy-> Java in IntelliJ IDEA CE
What to do if the changes are not reflected in the jar manifest file
What to do when the value becomes null in the second getSubmittedValue () in JSF Validator
[Grails] Error occurred running What to do when the Grails CLI does not start
What to do when is invalid because it does not start with a'-'
What to do if ffi installation fails when launching an application in Rails
What to do when The SSL certificate has expired
What to do if ClassNotFoundException occurs when starting Tomcat
What to do when a null byte error occurs
What to do when rails creates a 〇〇 2.rb file
Error ExecJS :: RuntimeUnavailable: What to do when it occurs
What to do if password authentication fails in Docker/Postgres
ParseException: What to do when Unparseable date is reached
[React.useRef] What to do when the latest state cannot be referenced in the event listener
What to do when "Fail to load the JNI shared library" is displayed in Eclipse
What to do when Address already in use is displayed after executing rails s
What to do when routing settings do not work after building Docker environment with Laravel
What to do when ‘Could not find’ in any of the sources appears in the development environment with Docker × Rails × RSpec
What to do when it becomes Unable to find CDI BeanManager.
What to do if you get a java.io.IOException in GlassFish
What to do when Git Repository cannot be displayed in Team Explorer for Eclipse in Azure
What to do when you launch an application with rails
What to do if audio is not available on discordrb
What to do when Cannot format given Object as a Date in convertDateTime of JSF
What to check when rails db: migration does not pass
What to do if FacesMessage is set but not displayed
[Ruby / Rails] What to do when NoMethodError appears when using a destructive method such as filter!
What happens when I do new => build => save! In ActiveRecord
When [command not found: composer] is displayed when [composer install] is displayed in Laravel
[Rails Tutorial Chapter 2] What to do when you make a mistake in the column name
Bluemix Infrastructure VPN does not connect because it does not support NPAPI! What to do when [Mac]
[Rails] What to do when the view collapses when a message is displayed with the errors method
[Rails] What to do when the error No database selected and Unknown database appears in db: migrate