Hi there,
I am using Struts, hibernate 3.0. In action, one form bean is generated and forwarded into one JSP, how can address the properties in the bean?
the following codes output nothing. It seems I am misusing the bean.
Any input are appreciated.
thanks
Fei
my from bean:
Code:
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import com.articy.vvm.Customer;
public class CustomerListForm extends ActionForm {
private static final long serialVersionUID = 1L;
private List customers = null;
public List getCustomers() {
return customers;
}
public void setCustomers(List customerValues) {
this.customers = customerValues;
}
private Customer customer=null;
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
customer = null;
}
}
Action
Code:
// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse 4.0.0/xslt/JavaClass.xsl
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.articy.vvm.bl.VVMManager;
import com.articy.vvm.struts.form.CustomerListForm;
public class CustomerListAction extends DispatchAction {
public ActionForward showallCustomer(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
CustomerListForm customerListForm = (CustomerListForm) form;
VVMManager vvmmanager = new VVMManager();
customerListForm.setCustomers(vvmmanager.getAllCustomers());
return mapping.findForward("golistCustomer");
}
public ActionForward showsingleCustomer(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
CustomerListForm customerListForm = (CustomerListForm) form;
System.out.println("Show single used vehicle");
/*
* Arthur Niu get id of the customer from request
*/
Long id = Long.valueOf(request.getParameter("id"));
// get business logic
VVMManager vvmManager = new VVMManager();
customerListForm.setCustomer(vvmManager
.getCustomerByPrimaryKey(id));
return mapping.findForward("goshowsingleCustomer");
}
}
jsp showsingleCustomer.jsp
Code:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ 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"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<script language="JavaScript" src="calendar.js"></script>
<logic:messagesPresent>
<bean:message key="errors.header" />
<ul>
<html:messages id="error">
<li><bean:write name="error" /></li>
</html:messages>
</ul>
<hr />
</logic:messagesPresent>
<%-- set the parameter for the dispatch action --%>
<table border="1">
<tbody>
<logic:present name="customerListForm" property="customer">
<tr>
<td><bean:message key="customerForm.customer_name.displayname" />:</td>
<td><bean:write name="customer" property="customer_name"/></td>
</tr>
<tr>
<td><bean:message key="customerForm.phone.displayname" />:
</td>
<td><bean:write name="customer" property="phone" /></td>
</tr>
</logic:present>
<%-- if customers cannot be found display a text --%>
<logic:notPresent name="customerListForm" property="customer">
<tr>
<td colspan="5">No customer found.</td>
</tr>
</logic:notPresent>
</tbody>
</table>