-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: How to address formbean's properties in JSTL
PostPosted: Wed Feb 01, 2006 2:57 pm 
Newbie

Joined: Tue Oct 25, 2005 10:49 pm
Posts: 9
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>





Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 3:03 pm 
Newbie

Joined: Wed Feb 01, 2006 10:22 am
Posts: 6
which method are you calling when you forward to the jsp?
more info please.


Top
 Profile  
 
 Post subject: I'd like to use bean:write
PostPosted: Wed Feb 01, 2006 4:09 pm 
Newbie

Joined: Tue Oct 25, 2005 10:49 pm
Posts: 9
I prefer to using bean:write to display the customer information.




Code:
   <table border="1">
      <tbody>
      <logic:present name="customerListForm" property="customer">

         <tr>
            <td><bean:message key="customerForm.customer_name.displayname" />:</td>
            <td[color=red]><bean:write name="customer" property="customer_name"/>[/color]</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>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 4:10 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
I think, this is wrong
<bean:write name="customer" property="phone" />
it should be
<bean:write name="custmoerForm "property="customer.phone" />

Regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject: it works
PostPosted: Wed Feb 01, 2006 5:09 pm 
Newbie

Joined: Tue Oct 25, 2005 10:49 pm
Posts: 9
Thanks, LaLiLuna

it works now.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.