Why is the Action not being populated correctly with a List?

2016-12-02 Thread Nuno Oliveira
Hi, I have an DummyAction{

private List 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 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?
2) Why is my converter not being used in either situation of declaring
List and List?

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-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: Can you use type conversion with JSONInterceptor?

2016-12-02 Thread Lukasz Lenart
Super cool, thanks :)

2016-12-02 11:40 GMT+01:00 Miguel Almeida :
> Thank you Lukasz!
>
> I will check if/how we can inject the converter there. If we manage to
> get it working in a way that helps the ticket resolution I'll also post
> the information there.
>
>
>
> On Sex, 2016-12-02 at 09:50 +0100, Lukasz Lenart wrote:
>
>> Hi,
>>
>> JSON plugin uses its own conversation mechanism, check JSONPopulator
>> but I think it should be possible to inject XWorkConverter and use it
>> to convert objects - this requires implementing your own
>> JSONPopulator.
>>
>> There is a task to do it so it should happen in Struts 2.5 ;-)
>> https://issues.apache.org/jira/browse/WW-3364
>>
>>
>> Regards

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



Re: Can you use type conversion with JSONInterceptor?

2016-12-02 Thread Miguel Almeida
Thank you Lukasz!

I will check if/how we can inject the converter there. If we manage to
get it working in a way that helps the ticket resolution I'll also post
the information there.



On Sex, 2016-12-02 at 09:50 +0100, Lukasz Lenart wrote:

> Hi,
> 
> JSON plugin uses its own conversation mechanism, check JSONPopulator
> but I think it should be possible to inject XWorkConverter and use it
> to convert objects - this requires implementing your own
> JSONPopulator.
> 
> There is a task to do it so it should happen in Struts 2.5 ;-)
> https://issues.apache.org/jira/browse/WW-3364
> 
> 
> Regards


Re: Can you use type conversion with JSONInterceptor?

2016-12-02 Thread Lukasz Lenart
Hi,

JSON plugin uses its own conversation mechanism, check JSONPopulator
but I think it should be possible to inject XWorkConverter and use it
to convert objects - this requires implementing your own
JSONPopulator.

There is a task to do it so it should happen in Struts 2.5 ;-)
https://issues.apache.org/jira/browse/WW-3364


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

2016-12-01 20:07 GMT+01:00 Miguel Almeida :
> Imagine SearchAction{
>
> private List evaluatedRecords;
> }
>
> Record is an interface so to get auto-wiring to work you'd usually
> set-up a
>
> SearchAction-conversion.properties:
> KeyProperty_evaluatedRecords=id
> Element_evaluatedRecords=com.bibliovigilance.model.RecordImpl
> CreateIfNull_evaluatedRecords=true
>
>
> I now want to create an Ajax post on this action. I tried the following:
>
> var evaluatedRecords = [
>  {"id": "10672"}
>  ]
>
>  var json_parameters = {evaluatedRecords:
> evaluatedRecords};
>
> $.ajax({
>   url: 'SearchmarkSelectedArticlesJSON.action',
>   cache: false,
>   contentType: 'application/json',
>   data: JSON.stringify(json_parameters),
>   type: "POST"
> });
>
> I believe I need to set-up the JSON interceptor on my action, so I
> added:
>  method="markSelectedArticles">
> 
> 
>
> The problem is that this interceptor doesn't seem to be using the
> -conversion.properties, so it throws an error when it tries to
> instantiate the Record class:
>
> java.lang.InstantiationException: com.bibliovigilance.model.Record
> at java.lang.Class.newInstance(Class.java:368)
> at
> org.apache.struts2.json.JSONPopulator.convertToCollection(JSONPopulator.java:250)
>
>
> I also tried removing the Record type in the List ( List
> evaluatedRecords). But in this case the JSON deserialization of the
> above mentioned ajax call will create a List evaluatedRecords with 1
> element, but that element is a Map (I didn't investigate, but I suppose
> it'll have id in the key and 10672 in the value).
>
> How would we configure this correctly? Is it possible for the JSON
> interceptor to be aware of the -conversion.properties? If not, what
> alternatives do you envision?
>
> Thanks!
>
> Miguel

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