[ 
https://issues.apache.org/struts/browse/WW-2471?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=43149#action_43149
 ] 

Sami Dalouche commented on WW-2471:
-----------------------------------

The work-around I found was to move the converters to some other properties 
file (xwork-conversion-hack.properties, for instance), and to make sure the 
code is loaded before any action executes, by creating a filter such as :

public class Struts2HackFilter implements Filter {

    boolean initialized = false;
    
    public void destroy() {
        // TODO Auto-generated method stub
        
    }

    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain filterChain) throws IOException, ServletException {
        if(!initialized) {
            initXWorkConverter();
            initialized = true;
        }
            
        filterChain.doFilter(request, response);
        
    }

    
    
    public void initXWorkConverter() throws ServletException {
        try {
            XWorkConverter xworkConverter = 
Dispatcher.getInstance().getContainer().getInstance(XWorkConverter.class);
            
xworkConverter.loadConversionProperties("xwork-conversion-hack.properties");    
        } catch(IOException e) {
            throw new RuntimeException(e);
        }
    }

    public void init(FilterConfig arg0) throws ServletException {
        // TODO Auto-generated method stub
        
    }


and of course, it is necessary to map it in web.xml AFTER struts2 filter
<filter-mapping>
                <filter-name>struts2hack</filter-name>
                <url-pattern>/*</url-pattern>
        </filter-mapping>

This is the temporary solution I am using in the meanwhile....

> NPE in XWorkConverter.loadConversionProperties after adding DateConverter is 
> still not fixed in 2.1.0
> -----------------------------------------------------------------------------------------------------
>
>                 Key: WW-2471
>                 URL: https://issues.apache.org/struts/browse/WW-2471
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.1.0
>            Reporter: Sami Dalouche
>
> Same problem as : WW-1978, the problem is still not fixed in 2.1.0, nor in 
> 2.1.1-SNAPSHOT
> when xwork-conversion.properties contains an entry, Struts 2 startup throws a 
> NPE :
> [ERROR] [2008-02-03 17:09:16,181] 
> [com.opensymphony.xwork2.conversion.impl.XWorkConverter] (main,) : Conversion 
> registration error
> java.lang.NullPointerException
>         at 
> com.opensymphony.xwork2.conversion.impl.XWorkConverter.createTypeConverter(XWorkConverter.java:729)
>         at 
> com.opensymphony.xwork2.conversion.impl.XWorkConverter.loadConversionProperties(XWorkConverter.java:756)
>         at 
> com.opensymphony.xwork2.conversion.impl.XWorkConverter.<init>(XWorkConverter.java:184)
>         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native 
> Method)
>         at 
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>         at 
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>         at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>         at 
> com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector.construct(ContainerImpl.java:388)
>         at 
> com.opensymphony.xwork2.inject.ContainerBuilder$5.create(ContainerBuilder.java:211)
>         at com.opensymphony.xwork2.inject.Scope$2$1.create(Scope.java:49)
>         at 
> com.opensymphony.xwork2.inject.ContainerImpl$ParameterInjector.inject(ContainerImpl.java:431)
>         at 
> com.opensymphony.xwork2.inject.ContainerImpl.getParameters(ContainerImpl.java:446)
> So, it looks like the object factory is not set in XWorkConverter :
>         Object obj = objectFactory.buildBean(className, null);
> Is there a quick work-around ?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to