You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Holger Wiechert <hw...@iks-gmbh.com> on 2001/07/20 14:48:50 UTC

Bug in Struts when using base class for forms?

Hi,

I'm in some kind of a hurry, so I didn't check the bug list or the archive.
In case, that this is a known issue, just forget about it.

So here's the apparent bug:

I'm using a base form class with some static fields and the
getters and setters:


MyBaseForm extends ActionForm implements java.io.Serializable
{

    private static List someLabels = new ArrayList();
    private static List someValues = new ArrayList();
    private static String value = null;

    public static final void setSomeLabels(List someLabels_param)
    {
        someLabels = someLabels_param;
    }

    public static final List getSomeLabels()
    {
        return someLabels;
    }

    public static final void setSomeValues(List someValues_param)
    {
        someValues = someValues_param;
    }

    public static final List getSomeValues()
    {
        return someValues ;
    }

    public static final void setValue(String value_param)
    {
        value= value_param;
    }

    public static final String getValue()
    {
        return value;
    }

    
}

Then I have another form class 
MyNewFormClass extends MyBaseForm implements java.io.Serializable
{
 //...
}

When I use MyNewFormClass within an JSP with the select/options tag
(
<TD vAlign=top>
    <html:select property="value" size="1">
        <html:options property="someValues" labelProperty="someLabels"/>
    </html:select>
</TD>

I get the following error message:

Root cause: 

javax.servlet.jsp.JspException: No getter method available for property someValues for bean under name null
	at org.apache.struts.taglib.html.OptionsTag.getIterator(OptionsTag.java:360)


However, this does not happen, when the getters are not static!

So, is this a bug? I guess, because it doesn't allow me an important feature (static getters for static fields).
Well, I can make my way around by doubling the getters: once static and once not static....

Holger


Re: Bug in Struts when using base class for forms?

Posted by Levi Cook <le...@papajo.com>.
FYI, this is a known, non-struts, issue- Bascically, properties, getters and
setters can't be static per the bean spec... Therfore, struts cannot use
normal bean introspection to populate your form.

Definitely search the archive for more info if you need it, its there.

Regards,
Levi

----- Original Message -----
From: "Holger Wiechert" <hw...@iks-gmbh.com>
To: <st...@jakarta.apache.org>
Sent: Friday, July 20, 2001 5:48 AM
Subject: Bug in Struts when using base class for forms?


Hi,

I'm in some kind of a hurry, so I didn't check the bug list or the archive.
In case, that this is a known issue, just forget about it.

So here's the apparent bug:

I'm using a base form class with some static fields and the
getters and setters:


MyBaseForm extends ActionForm implements java.io.Serializable
{

    private static List someLabels = new ArrayList();
    private static List someValues = new ArrayList();
    private static String value = null;

    public static final void setSomeLabels(List someLabels_param)
    {
        someLabels = someLabels_param;
    }

    public static final List getSomeLabels()
    {
        return someLabels;
    }

    public static final void setSomeValues(List someValues_param)
    {
        someValues = someValues_param;
    }

    public static final List getSomeValues()
    {
        return someValues ;
    }

    public static final void setValue(String value_param)
    {
        value= value_param;
    }

    public static final String getValue()
    {
        return value;
    }


}

Then I have another form class
MyNewFormClass extends MyBaseForm implements java.io.Serializable
{
 //...
}

When I use MyNewFormClass within an JSP with the select/options tag
(
<TD vAlign=top>
    <html:select property="value" size="1">
        <html:options property="someValues" labelProperty="someLabels"/>
    </html:select>
</TD>

I get the following error message:

Root cause:

javax.servlet.jsp.JspException: No getter method available for property
someValues for bean under name null
at org.apache.struts.taglib.html.OptionsTag.getIterator(OptionsTag.java:360)


However, this does not happen, when the getters are not static!

So, is this a bug? I guess, because it doesn't allow me an important feature
(static getters for static fields).
Well, I can make my way around by doubling the getters: once static and once
not static....

Holger