Solved

No getter method for property

Posted on 2008-10-02
7
1,932 Views
Last Modified: 2013-11-24
No getter method for property
       60 point fra fredand      

 X
Hello!

I have ran into a strange problem. (To me it looks strange beacuse this should be easy to solve, but perhaps I'm blind)

This is a small app that I use for testing at home.

The error I get is:

javax.servlet.jsp.JspException: No getter method for property name of bean AddNameFormWebService

Usally this means that I refer to a member in the Form-class with wrong method-name. In this case getName I guess?

To me this there is no method named getName in class AddNameFormWebService.

First this part works with a similar structure:
<html:form action="/AddNameActionEJB" method="post" >
    <html:errors/>
   
    <table border="0">
        <tr>
            <td align="right">
            <html:submit>Add Name</html:submit>
        </td>
        <td align="left">
            <html:text property="name" size="30" maxlength="30"/>
        </td>
    </tr>
        <tr>
            <td>
                &nbsp;
            </td>
            <td>
                <textarea name="namestextarea" cols="35" rows="5">
                    <logic:empty name="AddNameFormEJB" property="names">AddNameFormEJB - No names available</logic:empty>
                    <logic:notEmpty name="AddNameFormEJB" property="names">
                        <logic:iterate name="AddNameFormEJB" property="names" id="AddNameFormEJB">
                            <bean:write name="AddNameFormEJB" property="name"/>
                        </logic:iterate>
                    </logic:notEmpty>
                </textarea>
            </td>
        </tr>
    </table>
</html:form>

The Form class looks like:

package nameswebapplication.controller.form;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;

public class AddNameFormEJB extends ActionForm
{
    static final long serialVersionUID = 1l;
    private String name = null;
    private List names = null;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List getNames() {
        return names;
    }

    public void setNames(List names) {
        this.names = names;
    }
}

The above works fine.

But this do not work:

<html:form action="/AddNameActionWebService" method="post" >
    <html:errors/>
   
    <table border="0">
        <tr>
            <td align="right">
            <html:submit>Add Name</html:submit>
        </td>
        <td align="left">
            <html:text property="name" size="30" maxlength="30"/>
        </td>
    </tr>
        <tr>
            <td>
                &nbsp;
            </td>
            <td>
                <textarea name="namestextarea" cols="35" rows="5">
                    <logic:empty name="AddNameFormWebService" property="names">AddNameFormWebService - No names available</logic:empty>
                    <logic:notEmpty name="AddNameFormWebService" property="names">
                        <logic:iterate name="AddNameFormWebService" property="names" id="AddNameFormWebService">
                            <bean:write name="AddNameFormWebService" property="name"/>
                        </logic:iterate>
                    </logic:notEmpty>
                </textarea>
            </td>
        </tr>
    </table>
</html:form>

This Form class looks like:

package nameswebapplication.controller.form;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;

public class AddNameFormWebService extends ActionForm
{
    static final long serialVersionUID = 1l;
    private String name = null;
    private List names = null;
   
    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public List getNames()
    {
        return names;
    }

    public void setNames(List names)
    {
        this.names = names;
    }
}

Pretty much the same.

The row where it goes wrong is:
<bean:write name="AddNameFormWebService" property="name"/>

If you can spot the reason please let me know!

Best regards
Fredrik
0
Comment
Question by:fredand44
  • 4
  • 3
7 Comments
 
LVL 9

Expert Comment

by:brunoguimaraes
Comment Utility
Check if there is something missing in your struts-config.xml
0
 

Author Comment

by:fredand44
Comment Utility
Hello!

Thanks for your fast reply!

I have checked it and correct me if I'm worng when I say that there is 2 areas that needs to be set:
The fom beans:

   <form-beans >
           <form-bean name="AddNameFormEJB" type="nameswebapplication.controller.form.AddNameFormEJB" />
           <form-bean name="AddNameFormWebService" type="nameswebapplication.controller.form.AddNameFormWebService" />
   </form-beans>

The actions:
      <action
         path="/AddNameActionEJB"
         name="AddNameFormEJB"
         scope="request"
         type="nameswebapplication.controller.action.AddNameActionEJB"
         validate="true">
         <forward name="success" path="/index.do" />
      </action>
     
      <action
         path="/AddNameActionWebService"
         name="AddNameFormWebService"
         scope="request"
         type="nameswebapplication.controller.action.AddNameActionWebService"
         validate="true">
         <forward name="success" path="/index.do" />
      </action>

This should do the trick if I'm not right.
But there must be something that I have messed up.
/Fredrik
0
 
LVL 9

Accepted Solution

by:
brunoguimaraes earned 250 total points
Comment Utility
Apparently everything is right. Unless we're missing something.

You could try a few things:

1 - Clean your webserver's cache and temporary files, recompile the application and try again.
2 - Use <c:out> instead of <bean:write>.
3 - Add another property in your AddNameFormWebService bean and try to print it using <bean:write>

Sorry I couldn't be more helpful.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:fredand44
Comment Utility
Hello!
Still same problem.

Removed it all from my webserver and restarted it. (Wls 8.1.6)
Rebuild it with:

public class AddNameFormWebService extends ActionForm
{
      static final long serialVersionUID = 1l;
      private String name = null;
      private List names = null;
      
      String hello = "hello";
      
      public String getName()
      {
            return name;
      }

      public void setName(String name)
      {
            this.name = name;
      }
      
      public String getHello()
      {
            return hello;
      }

      public void setHello(String hello)
      {
            this.hello = hello;
      }.....

Also changed the jsp to:

                                                            <logic:empty name="AddNameFormWebService" property="names">AddNameFormWebService - No names available</logic:empty>
                                                            <logic:notEmpty name="AddNameFormWebService" property="names">
                                                                  <logic:iterate name="AddNameFormWebService" property="names" id="AddNameFormWebService">
                                                                        <bean:write name="AddNameFormWebService" property="hello"/>
                                                                  </logic:iterate>
                                                            </logic:notEmpty>

Deployed it again.

But I still get the same error:

No getter method for property hello of bean AddNameFormWebService

Very strange since I have en other example that works fine as I mentioned above.

So if you guys get any ides, please let me know!

Best regards
Fredrik

0
 
LVL 9

Expert Comment

by:brunoguimaraes
Comment Utility
You could try on a different webserver, like JBoss or Glassfish, just in case.

Well, if I have a better idea, I'll let you know.
0
 

Author Comment

by:fredand44
Comment Utility
Hello!

Stupid me!

It turned out that in the list put into "public void setNames(List names)" at AddNameFormWebService was a List of String.

In my other form it was a List of objects of class myapp.Name with a method called getName.

Thank you all!

Best regards
Fredrik
0
 

Author Closing Comment

by:fredand44
Comment Utility
Thanks mate!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now