Home > Software design >  method not found exception while invoking method in springboot
method not found exception while invoking method in springboot

Time:02-17

Feb 17, 2022 10:06:40 AM com.sun.faces.lifecycle.InvokeApplicationPhase execute
WARNING: #{loginBean.validate}: javax.el.MethodNotFoundException: /index.xhtml @23,80 action="#{loginBean.validate}": Method not found: [email protected]()
javax.faces.FacesException: #{loginBean.validate}: javax.el.MethodNotFoundException: /index.xhtml @23,80 action="#{loginBean.validate}": Method not found: [email protected]()
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:110)

Here is my login.xhtml file

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
<body>
<h:form>
 <p:panel header="Login">  
 
        <p:messages id="msgs" showDetail="true"/>
        <h:outputText value="id" />
        <h:inputText id="id" value="#{loginBean.id}"></h:inputText>
        <h:message for="id"></h:message>
        <br></br>
        <br></br>

        <h:outputText value="name" />
        <h:inputText id="name" value="#{loginBean.name}"></h:inputText>
        <h:message for="name"></h:message>

        <p:commandButton action="#{loginBean.validate}" value="login" update="msgs" ></p:commandButton>
        </p:panel>
        <br></br>
        <br></br>
</h:form>
</body>
</html>

Here is my class

package ritu.login;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
@ManagedBean(name = "loginBean")
@SessionScoped
public class User implements Serializable{
    
    private static final long serialVersionUID = -7250065889869767422L;

    @Id
    private Long id;
    private String name;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String validate(Long id, String name) {

        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/any", "root", "jaygurudev1@");
            PreparedStatement ps = con.prepareStatement("Select id,name from user where id=? and name=?");
            ps.setLong(1, id);
            ps.setString(2, name);
            ResultSet rs = ps.executeQuery();

            if (rs.next()) {
                return "index.xhtml";
            } else {
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,
                        "Incorrect Username and Passowrd", "Please enter correct username and Password"));
                return "login.xhtml";
            }

        } catch (Exception e) {
            System.out.println("in exception");
        }
        return "ok";

    }
}

why this exception occur and what is this trying to said? i have use h tag in commandButton previosly but it did not work

Caused by: javax.faces.el.MethodNotFoundException: javax.el.MethodNotFoundException: /index.xhtml @23,80 action="#{loginBean.validate}": Method not found: [email protected]() at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) ... 29 more Caused by: javax.el.MethodNotFoundException: /index.xhtml @23,80 action="#{loginBean.validate}": Method not found: [email protected]() at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:109) at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87) ... 30 more

Feb 17, 2022 10:06:40 AM com.sun.faces.context.ExceptionHandlerImpl log 1100: JSF1073: javax.faces.FacesException caught during processing of INVOKE_APPLICATION 5 : UIComponent-ClientId=, Message=#{loginBean.validate}: javax.el.MethodNotFoundException: /index.xhtml @23,80 action="#{loginBean.validate}": Method not found: [email protected]() Feb 17, 2022 10:06:40 AM com.sun.faces.context.ExceptionHandlerImpl log

CodePudding user response:

You have to pass parameter near #{loginBean.validate} in login.xhtml.

Change:

<p:commandButton action="#{loginBean.validate}" value="login" update="msgs" ></p:commandButton>

To:

<p:commandButton action="#{loginBean.validate(loginBean.id, loginBean.name)}" value="login" update="msgs" ></p:commandButton>
  • Related