Introduction
There is a specific error message where the description to solve the problem exist in this article. That error message exist as part of the title of this article. Specifically, the error message is ‘/basic-input-text-db.xhtml @25,83 value=”#{basicInputTextDBView.names}”: The class ‘com.company.web.view.BasicInputTextDBView’ does not have the property ‘names’.’ The cause exist in the file with the name of ‘basic-input-text-db.xhtml’ as the JSF file acting as a front-end of the user. But upon accessing the ‘basic-input-text-db.xhtml’, it will display the error as it exist in the following display :
Before getting on further, the following is the content of the file with the name of ‘basic-input-text-db.xhtml’ as follows :
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/html" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui"> <head> <title>TODO supply a title</title> <meta name="viewport" content="width-device-width, initial-scale=1.0"> </head> <body> <div>TODO content</div> <div class="card"> <h:form> <h5>Form User with only Basic InputText</h5> <h5>Hello, <p:outputLabel for="username" value="#{basicInputTextDBView.names}"></p:outputLabel></h5> <p:inputText id="username" value="#{basicInputTextDBView.names}"/> <p:commandButton actionListener="#{basicInputTextDBView.submit()}" value="Submit" /> </h:form> </div> <div class="card"> <p:panel header="User List"> <p:dataTable var="user" value="#{userBean.userList}"> <p:column> <f:facet name="header"> <h:outputText value="Username" /> </f:facet> <h:outputText value="#{user.name}" /> </p:column> </p:dataTable> </p> </div> </body> </html>
Solution
So, the solution for solving the above error message is very easy. It is by changing the reference value of the inputText component above. Actually, there is a backing bean in the form of a Java file with the name of ‘BasicInputTextDBView.java’. So, in order to define the value of theme as ‘names’, there must be also a variable definition in that Java file. The following is the content of the Java file with the name of ‘BasicInputTextDBView.java’ :
package com.mycompany.web.view; import com.mycompany.web.bean.UserBean; import com.mycompany.web.db.DBConnection; import com.mycompany.web.model.User; import java.io.Serializable; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.faces.view.ViewScoped; import javax.inject.Named; /** * * @author Mark Spectre */ @Named(value = "basicInputTextDBView") @ViewScoped public class BasicInputTextDBView implements Serializable { private Connection connection; private Statement statement; private ResultSet resultSet; private final String TABLE_NAME = "employee"; private User user; private List userList; private String name; public BasicInputTextDBView() { connection = DBConnection.getConnection(); user = new User(); userList = user.getUserList(); } public String getName() { return name; } public void setName(String name) { this.name = name; } public void submit() { try { String query = "INSERT INTO " + TABLE_NAME + "(name) " + " values(?)"; System.out.println(query); System.out.println("Name : "+name); connection = DBConnection.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(query); preparedStatement.execute(); preparedStatement.close(); preparedStatement.setString(1, name); //getName()); User user = new User(); user.setUsername(name); userList.add(user); } catch (SQLException ex) { Logger.getLogger(BasicInputTextDBView.class.getName()).log(Level.SEVERE, null, ex); } } }
]
So, in order to correct it and solve the problem of the appearance of the error message, just make sure that the value of the inputText element in the JSF file is exist as a variable declaration in the Java file. There is a declaration of the inputText element in the JSF file exist as follows :
<p:inputText id="username" value="#{basicInputTextDBView.names}"/>
On the other hand, there is no variable with the name of ‘names’. Instead of ‘names’, there is only a variable with the name of ‘name’. In that case, change the variable name in the inputText element’s value as follows :
<p:inputText id="username" value="#{basicInputTextDBView.name}"/>
Build, compile and run it once more. If there are no further error available, the application will run properly.