This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

No getter method for property - Problem

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

I'm new working with Struts and I get an error "No getter method for property author."

Sorry to post the code, but I'm hoping that someone could tell me what
I'm doing wrong. I haven't been able to figure this out and the solutions
in another thread about this don't work.

The code is as follows:


-- Book.java:

package com.mycompany;

public class Book implements java.io.Serializable {

private static final long serialVersionUID = 1L;

private long id;
private String title;
private String author;
private char available;

public Book() {}

public Book(long id, String title, String author, char available) {
this.id = id;
this.title = title;
this.author = author;
this.available = available;
}

public long getId() {
return id;
}

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

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getAuthor() {
return author;
}

public void setAuthor(String author) {
this.author = author;
}

public char getAvailable() {
return available;
}

public void setAvailable(char available) {
this.available = available;
}
}

============================================================

-- BookListForm.java

package com.mycompany.struts.form;

import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

/**
* MyEclipse Struts
* Creation date: 06-24-2008
*
* XDoclet definition:
* @struts.form name="bookListForm"
*/

public class BookListForm extends ActionForm {

private Collection books;

/**
* @return the books
*/
public Collection getBooks() {
return books;
}

/**
* @param books the books to set
*/
public void setBooks(Collection books) {
this.books = books;
}

public void reset(ActionMapping mapping, HttpServletRequest request) {
books = new ArrayList();
}

}

============================================================

-- BookListAction.java


package com.mycompany.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.mycompany.form.BookListForm;
import com.mycompany.hibernate.*;
import org.hibernate.SessionFactory;
import org.hibernate.Session;
import java.util.Collection;

/**
* MyEclipse Struts
* Creation date: 06-24-2008
*
* XDoclet definition:
* @struts.action path="/bookList" name="bookListForm" input="/jsp/bookList.jsp" scope="request" validate="true"
*/

public class BookListAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse
response) {

BookListForm bookListForm = (BookListForm) form;

SessionFactory factory = null;
Session session = null;
Collection books = null;

try {

factory = HibernateUtil.getSessionFactory();

session = (Session) factory.openSession();

books = session.createQuery("select id, title, author, available from Book t ").list();

bookListForm.setBooks(books);

} finally {
session.close();
}

return mapping.findForward("showList");

}
}

============================================================

-- bookList.jsp

<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>

<html>
<head>
<title>Show book list</title>
</head>
<body>
<table border="1">
<tbody>
<%-- set the header --%>
<tr>
<td>Author</td>
<td>Book name</td>
<td>Available</td>
<td> </td>
<td> </td>
</tr>
<%-- check if book exists and display message or iterate over books --%>
<logic:empty name="bookListForm" property="books">
<tr>
<td colspan="5">No books available</td>
</tr>
</logic:empty>
<logic:notEmpty name="bookListForm" property="books">
<logic:iterate name="bookListForm" property="books" id="book">
<tr>
<%-- print out the book information --%>
<td><bean:write name="book" property="author" /></td>
<td><bean:write name="book" property="title" /></td>
<td><html:checkbox disabled="true" name="book" property="available" />
</td>

<%-- print out the edit and delete link for each book --%>
<td><html:link action="bookEdit.do?do=editBook" paramName="book"
paramProperty="id" paramId="id">Edit</html:link></td>
<td><html:link action="bookEdit.do?do=deleteBook" paramName="book"
paramProperty="id" paramId="id">Delete</html:link></td>
</tr>
</logic:iterate>
</logic:notEmpty>

<%-- print out the add link --%>
<tr>
<td colspan="5"><html:link action="bookEdit.do?do=addBook">Add a new book</html:link>
</td>
</tr>

<%-- end interate --%>

</tbody>
</table>
</body>
</html>

============================================================

Sorry for posting the code. Thanks in advance for any help.

Best regards,

Rudi
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi R Diaz,
This is common problem with list in action form, if contains another Bean.
nested tags will help you.
google on struts nested tags.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I get the same error but my getters and setters are well defined. And both "sender" and "retard" are defined as String(s) in my ActionForm.

When it comes to doing <html:text property="sender" /> in my jsp page, it works fine but when I write <html:text property="retard" />, Tomcat gives me the no getter error and I absolutely don't know why as "sender" and "retard" have similar and interchangeable roles.

I have tried turning tomcat off and on again but nothing improved so I'm wondering if there's some tweak I should know to make this work because it's really driving me crazy at the moment.

Thanks in advance.

Regards,
-- Alain
 
I RELEASE YOU! (for now .... ) Feel free to peruse this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!