我希望显示一个列表,其中包含我放在InputText中的名称。 但是当我调用该方法时,我收到错误:找不到方法 任何人都可以帮助我吗?
为myBean
@ManagedBean(name="guestBean")public class Exer02_30 {
public String name;
public String email;
public String message;
public String nameSearch;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getNameSearch() {
return nameSearch;
}
public void setNameSearch(String nameSearch) {
this.nameSearch = nameSearch;
}
public ResultSet getContacts() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/GuestBook", "root", "Ds881536");
try{
PreparedStatement getContacts = conn.prepareStatement("SELECT NAME, EMAIL, MESSAGE FROM CONTACTS");
CachedRowSet rowSet = new com.sun.rowset.CachedRowSetImpl();
rowSet.populate(getContacts.executeQuery());
return rowSet;
}
finally{
conn.close();
}
}
public String save() throws SQLException, ClassNotFoundException, Exception{
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/GuestBook", "root", "Ds881536");
try{
PreparedStatement addEntry = conn.prepareStatement("INSERT INTO CONTACTS (NAME, EMAIL, MESSAGE) VALUES(?, ?, ?)");
addEntry.setString(1, getName());
addEntry.setString(2, getEmail());
addEntry.setString(3, getMessage());
addEntry.executeUpdate();
return "exer02_30.xhtml";
}
finally{
conn.close();
}
}
public ResultSet getSearch()throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/GuestBook", "root", "Ds881536");
try{
PreparedStatement getSearch = conn.prepareStatement("SELECT NAME, EMAIL, MESSAGE FROM CONTACTS WHERE NAME = ?");
getSearch.setString(1, getNameSearch());
CachedRowSet rowSet = new com.sun.rowset.CachedRowSetImpl();
rowSet.populate(getSearch.executeQuery());
return rowSet;
}
finally{
conn.close();
}
}
}
JSF FILE
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Guest Book: Add Entry</title>
</h:head>
<h:body>
<h1>Guest Book: Add Entry</h1>
<h:form>
<h:panelGrid columns="3">
<h:outputText value="Name:"/>
<h:inputText id="nameInputText" value="#{guestBean.name}"/>
<br/>
<h:outputText value="Email:"/>
<h:inputText id="emailInputText" value="#{guestBean.email}"/>
<br/>
<h:outputText value="Message:"/>
<h:inputText id="messageInputText" value="#{guestBean.message}"/>
<br/>
</h:panelGrid>
<br/>
<h:commandButton id="ajax" value="Save Contact" action="#{guestBean.save()}">
<f:ajax execute="@form" render="@form"/>
</h:commandButton>
<h:dataTable value="#{guestBean.contacts}" var="contacts"
rowClasses="oddRows.evenRows" headerClass="header"
styleClass="table" cellpadding="5" cellspacing="0"
>
<h:column>
<f:facet name="header">Name</f:facet>
#{contacts.NAME}
</h:column>
<h:column>
<f:facet name="header">Email</f:facet>
#{contacts.EMAIL}
</h:column>
<h:column>
<f:facet name="header">Message</f:facet>
#{contacts.MESSAGE}
</h:column>
</h:dataTable>
</h:form>
<h:form id="form">
<h:panelGroup id="wrapper">
<h:dataTable value="#{guestBean.search}" var="contacts"
rowClasses="oddRows.evenRows" headerClass="header"
styleClass="table" cellpadding="5" cellspacing="0"
>
<h:column>
<f:facet name="header">Name</f:facet>
#{contacts.NAME}
</h:column>
<h:column>
<f:facet name="header">Email</f:facet>
#{contacts.EMAIL}
</h:column>
<h:column>
<f:facet name="header">Message</f:facet>
#{contacts.MESSAGE}
</h:column>
</h:dataTable>
<h:commandButton id="ajax2" value="Save Contact" action="#{guestBean.search}">
<f:ajax render=":form:wrapper"/>
</h:commandButton>
<h:outputText value="Search:"/>
<h:inputText id="searchInputText" value="#{guestBean.nameSearch}"/>
</h:panelGroup>
</h:form>
</h:body>
</html>
答案 0 :(得分:-2)
你试过这个(没有括号)吗?
<h:commandButton id="ajax" value="Save Contact" action="#{guestBean.save}">
<f:ajax execute="@form" render="@form"/>
</h:commandButton>