[opencms-dev] CmsSelectWidget: setConfiguration called twice?

Paul-Inge Flakstad flakstad at npolar.no
Thu Jul 16 13:13:13 CEST 2009


Hi Marc

I've seen this problem, and my guess is there's nothing wrong with the code. I believe the issue lies within the widget configuration.

In my book's code there seems to be a typo on the example of the <layout> section: it says source='....sources.ContentListDS', but it should say source='....sources.ContentFieldListDS'. Using the code from this example in the book will produce an error like yours, since an attempt will be made to create an instance of a non-existing class. (If you look at the source code provided with the book, you'll see that there's no file called ContentListDS.java - but there is indeed a ContentFieldListDS.java.)

BTW: The 'fieldname' part in the configuration should be set to match the name of the element that you want to fetch the list values from. If you are unsure of that element's name, you can just have a look at the .xsd or the control code.

As for why the method is called twice: I haven't studied the code for a while, and I didn't look into it right now - but the same happened in my case when I tried to duplicate your problem. Everything works fine though, after changing the 'source' part in the config as explained above.

Hope this helps you along. :-)

Cheers,
Paul


> -----Original Message-----
> From: opencms-dev-bounces at opencms.org 
> [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Marc.Schlegel
> Sent: 15. juli 2009 19:11
> To: The OpenCms mailing list
> Subject: [opencms-dev] CmsSelectWidget: setConfiguration called twice?
> 
> Hello Everyone
> 
> I am including the CmsCustomSelectSourceWidget form the OpenCms 7 book
> (packtpub) but when I am trying to use it the the list is 
> empty and the
> log tells me that there is NullPointerException.
> 
> 14 Jul 2009 00:04:20,016 ERROR [ts.CmsCustomSourceSelectWidget:  45]
> mine a.widgets.sources.ContentListDS
> 14 Jul 2009 00:04:20,029 ERROR [ts.CmsCustomSourceSelectWidget:  45]
> mine null
> 14 Jul 2009 00:04:20,030 ERROR [ts.CmsCustomSourceSelectWidget:  50]
> Error instantiating DataSource object of class "null" - "{1}"
> java.lang.NullPointerException
> 
> The code is just copied from the book, except the logging 
> after the try-line
> 
>     @Override
>     public void setConfiguration(String configuration){
>         super.setConfiguration(configuration);
>         if(iDataSource == null){
>             config = new CustomSourceConfiguration(configuration);
>             String strClassName = config.getConfigValue("source");
>             // read the class name for the data source and 
> instantiate it
>             Class<I_WidgetSelectSource> sourceClazz;
>             try{
>                 LOG.error("mine " + strClassName);
>                 sourceClazz = (Class<I_WidgetSelectSource>)
> Class.forName(strClassName);
>                 iDataSource = sourceClazz.newInstance();
>             }catch(Exception e){
>                 // Log the error
>                
> LOG.error(Messages.getInstance().getBundle().key(Messages.LOG_
> DATASOURCE_INIT_ERROR_2,
> strClassName), e);
>                 // since it failed, use the default source provider
>                 iDataSource = new DefaultDS();
>             }
>             // set the configuration
>             iDataSource.setConfiguration(config);
>         }
>     }
> 
> So, somehow, this method is called twice, and I have no clue why.
> Can anybody be of any assistance?
> 
> 
> Maybe the layout-section where I actualy use that widget is helpfull
> <layout element="Category" widget="CustomSourceSelectWidget"
>                     
> configuration="source='a.widgets.sources.ContentListDS'|
>                    
> contenttype='ValueList'|location='/_news/newscategories'|
>                     fieldname='Value'"  <!-- tried Category 
> here as well -->
> />
> 
> Thanks
> 
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, 
> please visit
> http://lists.opencms.org/mailman/listinfo/opencms-dev
> 


More information about the opencms-dev mailing list