facebook

Struts bean error

  1. MyEclipse IDE
  2.  > 
  3. Comments
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #214618 Reply

    Jason Price
    Member

    Hi
    I’m trying to develop a Struts application using myeclipse (3.8.1) and eclipse (3.0). I’ve created a new action, jsp and form using the new struts design view. All I have on the page at the moment is a input box, called InvoiceNo, which when using the wizard I created as type BigInteger. When I try to forward to this page I get “No getter method for property InvoiceNo of bean org.apache.struts.taglib.html.BEAN” even though both getter and setter is there in the bean class. Its almost as if the bean isn’t being associated with the form.

    I am new to both MyEclipse and Struts but I just can’t see what I’m doing wrong and I can’t find anything on the net about this.

    thanks

    #214645 Reply

    Riyad Kalla
    Member

    Funky,
    I’m moving this to Random Thoughts because its a Struts question, but am happy to help.

    First please post your form getter/setter method signatures, and post your JSP page contents where the bean is used, also your bean mapping from the struts-config.xml file wouldn’t hurt.

    #214663 Reply

    Jason Price
    Member

    OK here goes..

    Formbean:

    package com.novatech.struts.form;

    import java.math.BigInteger;

    import javax.servlet.http.HttpServletRequest;

    import org.apache.struts.action.ActionErrors;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.validator.ValidatorForm;

    /**
    * MyEclipse Struts
    * Creation date: 09-06-2004
    *
    * XDoclet definition:
    * @struts:form name=”postDispatchForm”
    */
    public class PostDispatchForm extends ValidatorForm {

    // ——————————————————— Instance Variables

    /** InvoiceNo property */
    private BigInteger InvoiceNo;

    // ——————————————————— Methods

    /**
    * Method validate
    * @param mapping
    * @param request
    * @return ActionErrors
    */
    public ActionErrors validate(
    ActionMapping mapping,
    HttpServletRequest request) {

    ActionErrors errors = new ActionErrors();

    //TODO validate invoice no and add any exceptions to errors

    return errors;
    }

    /**
    * Returns the InvoiceNo.
    * @return BigInteger
    */
    public BigInteger getInvoiceNo() {
    return InvoiceNo;
    }

    /**
    * Set the InvoiceNo.
    * @param InvoiceNo The InvoiceNo to set
    */
    public void setInvoiceNo(BigInteger InvoiceNo) {
    this.InvoiceNo = InvoiceNo;
    }

    }

    JSP Page:
    <%@ page language=”java”%>
    <%@ taglib uri=”http://jakarta.apache.org/struts/tags-bean&#8221; prefix=”bean”%>
    <%@ taglib uri=”http://jakarta.apache.org/struts/tags-html&#8221; prefix=”html”%>

    <html>
    <head>
    <title>Post Dispatch</title>
    </head>
    <body bgcolor=”#ABB8CA” text=”#000099″ leftmargin=”0″ topmargin=”0″
    marginwidth=”0″ marginheight=”0″ link=”#000099″ vlink=”#000099″
    bottommargin=”0″><center><H1><font face=”Tahoma, Verdana”>Dispatching by Post</font></H1>
    <P><font face=”Tahoma, Verdana”>Please scan or enter the Invoice No to continue</font></P>
    <html:form action=”/postDispatch”><table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”1″>
    <tr>
    <td><font face=”Tahoma, Verdana”><b>Invoice No</b></font></td>
    <td><font face=”Tahoma, Verdana”>
    <html:text property=”InvoiceNo”/>
    <html:errors property=”InvoiceNo”/>
    </font></td>
    </tr>
    <tr>
    <td><font face=”Tahoma, Verdana”>
    <html:cancel/>
    </font></td>
    <td><font face=”Tahoma, Verdana”>
    <html:submit value=”Get Order Details”/>
    </font></td>
    </tr>
    </table>
    </html:form></CENTER>
    </body>
    </html>

    relevant parts of stuts-config.xml
    <form-beans >
    <form-bean name=”postDispatchForm” type=”com.novatech.struts.form.PostDispatchForm” />

    </form-beans>

    <action-mappings >
    <action
    attribute=”postDispatchForm”
    input=”/dispatch/postDispatch.jsp”
    name=”postDispatchForm”
    path=”/postDispatch”
    scope=”request”
    type=”com.novatech.struts.action.PostDispatchAction” />
    <action
    path=”/dispatchView”
    type=”com.novatech.struts.action.DispatchViewAction”
    validate=”false”>
    <forward
    name=”PostDispatch”
    path=”/dispatch/postDispatch.jsp”
    redirect=”true” />
    </action>

    </action-mappings>

    which is basically pretty much all I have at the moment (I have the standard form login j2ee security and a couple of roles defined but thats it.)

    Thanks for your help rkalla

    #214684 Reply

    Riyad Kalla
    Member

    Ok,
    The first problem is that you have defined the type BigInteger, and you are actually entering a String on the webpage. So when your webpage goes to populate your bean, its looking for a method with a signature like:
    public void setInvoiceNo(String InvoiceNo)

    and has no knowledge of doign the conversion to BigInteger. You might try and change your setter bean types to String and getter bean type to BigInteger and do the conversion internally.

    #214687 Reply

    Jason Price
    Member

    Doh!
    sorry I should’ve seen that.
    Works pefectly now!

    Thanks for your help.

    #214688 Reply

    Riyad Kalla
    Member

    Great, I’m glad when things work.

    #214755 Reply

    Jason Price
    Member

    It started happening again, but I figured out what was happending so though I’d update incase anyone else had the smae problem. If you use the wizards to create the jsp form and start the field name with an Uppercase char the bean won’t find the getters or setter becuase the names should start with lowercase char.

    (I am such a dumbarse sometimes!)

    #214770 Reply

    Riyad Kalla
    Member

    Funky, Thank you for the followup. There are a lot of people getting started wtih Struts and beginner information is just as if not more important than advanced information. We appreciate you following up.

Viewing 8 posts - 1 through 8 (of 8 total)
Reply To: Struts bean error

You must be logged in to post in the forum log in