I am aware that, when applying request parameters to an action, Struts
cannot guess the actual type of parameters determined by a generic type
(because of erasure at compile time).

However, I am assuming that if a non-generic action class extends an
abstract generic one, it should be possible in the non-generic child to
force the type conversion explicitely.  Isn't that the case?  At the moment,
I seemingly cannot get Struts to realize that I did specify a type
conversion and I keeping getting the following exception (whether my forced
conversion is in place or not):
java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to
java.lang.Integer

Underneath are the relevant parts of my setup.
*What am I forgetting?*  (For example, am I missing an interceptor
somewhere?)*
Can anyone suggest how to trace what's happening at the point when a
converter should be applied (and is clearly not)?
*

In web.xml, I specify the location of the action package:

    <filter>
        <filter-name>action2</filter-name>

<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
        <init-param>
            <param-name>actionPackages</param-name>
            <param-value>com.mywebapp.actions2</param-value>
        </init-param>
    </filter>


In struts.xml, here's the bit about the concrete (non-generic) child:

    <package name="contrib" extends="struts-default" abstract="false"
namespace="/contrib" >
        <interceptors>
            <interceptor name="autoLogin"
class="com.mywebapp.interceptors.AutoLoginInterceptor" />
            <interceptor-stack name="contribStack">
                <interceptor-ref name="autoLogin"/>
                <interceptor-ref name="paramsPrepareParamsStack"/>
            </interceptor-stack>
        </interceptors>
        <default-interceptor-ref name="contribStack" />
        <action name="groupContrib" class="groupContribAction">
            <result>/struts2/groupContrib2.jsp</result>
        </action>
    </package>


The previous reference to "groupContribAction" is in fact a Spring bean:

    <bean id="groupContribAction"
class="com.mywebapp.actions2.GroupContribAction"
parent="abstractContribAction" scope="prototype">
        <property name="contrib" ref="groupContrib" />
        <property name="contribService" ref="groupContribService" />
    </bean>


Here is an excerpt of the concrete action class itself.  Notice the
conversion annotations.  (I also half-heartedly tried without annotations,
using instead GroupContribAction-conversion.properties.)

@Conversion
public class GroupContribAction extends ContribAction<Integer> {
    private Integer propertyId;

    @Override
    public Integer getPropertyId() { return propertyId; }

    @Override
    @TypeConversion(converter =
"com.mywebapp.converters.StringToIntegerConverter")
    public void setPropertyId(Integer propertyId) { this.propertyId =
propertyId; }
}


And finally, here is an excerpt of the abstract generic parent:

public abstract class ContribAction<K extends Serializable>
            extends ActionSupport implements ServletRequestAware, Preparable
{

    public abstract void setPropertyId(K propertyId);
    public abstract K getPropertyId();
}

Reply via email to