struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lukasz Lenart <lukaszlen...@apache.org>
Subject Re: Why is the Action not being populated correctly with a List<Interface>?
Date Sun, 04 Dec 2016 10:13:32 GMT
I think you should rather use xwork-conversion.properties and
com.package.model.Record=com.package.web.RecordConverter

Struts will try to automatically convert elements of the list to given type


Regards
-- 
Ɓukasz
+ 48 606 323 122 http://www.lenart.org.pl/

2016-12-02 20:47 GMT+01:00 Nuno Oliveira <noliveira@itclinical.com>:
> Hi, I have an DummyAction{
>
> private List<Record> records;
> }
>
> which has the following converter
>
> DummyAction-conversion.properties:
> KeyProperty_records=id
> Element_records=com.package.model.RecordImpl
> CreateIfNull_records=true
>
> When the value stack is being populated in the ParametersInterceptor
> method setParameter()
>
>
> newStack.setParameter(name, value);
>
> the list records is not populated correctly.
> Looking for the problem I see that in the OgnlValueStack class an
> exception is caught telling me that the Interface Record cannot be
> instantiated.
> The method is:
>
> private void setValue(String expr, Object value, boolean
> throwExceptionOnFailure, boolean evalExpression) {
>         Map<String, Object> context = getContext();
>         try {
>             trySetValue(expr, value, throwExceptionOnFailure, context,
> evalExpression);
>         } catch (OgnlException e) {
>             handleOgnlException(expr, value, throwExceptionOnFailure,
> e);
>         } catch (RuntimeException re) { //XW-281
>             handleRuntimeException(expr, value, throwExceptionOnFailure,
> re);
>         } finally {
>             cleanUpContext(context);
>         }
>     }
>
> And the exception is:
>
> Error creating bean with name 'com.package.model.Record':
> Instantiation of bean failed; nested exception is
> org.springframework.beans.BeanInstantiationException: Could not
> instantiate bean class [com.package.model.Record]: Specified
> class is an interface - Class:
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
> File: AbstractAutowireCapableBeanFactory.java
> Method: instantiateBean
> Line: 1037 -
> org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java:1037:-1
>
> Now I know I can't instantiate interfaces and changing the list type to:
>
> private List records;
>
> there is no exception and the list records has the correct values but,
> in both ways my converter does not seen to be used (I'm testing this
> using a breakpoint in XWorkConverter).
>
> So my questions are:
> 1) Which is the proper way of using the conversion when declaring the
> List type as an interface, List<Record>?
> 2) Why is my converter not being used in either situation of declaring
> List and List<Record>?
>
> This question is related to Miguel Almeida post if you want to check
> additional context, but I think this information should be sufficient.
>
> Thanks
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message