You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by lchalupa <lc...@seelink.org> on 2011/01/15 02:08:20 UTC
Can't get a SortableDataProvider class to accept DI of service
class
The class SortableDataProvider throws a NPE. The PersonService and the
GUIService that should be getting injected both end up being null values.
I've tried both annotations @Autowired and @SpringBean. Neither seems to
work.
I turned on logging and I can see in the log that SortableDataProvider being
injected but obviously it isn't happening.
Not sure how to diagnose this problem? Any Ideas?
Lee
Here is the SortableDataProvider Class:
package org.seelink.web2.ui.user;
import
org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
import org.apache.wicket.model.IModel;
import org.seelink.web2.model.role.Person;
import org.seelink.web2.serv.GuiService;
import org.seelink.web2.serv.PersonService;
import org.seelink.web2.ui.appadm.DetachablePersonModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.Serializable;
import java.util.Iterator;
/**
* Created by IntelliJ IDEA.
* User: lchalupa
* Date: 1/12/11
* Time: 4:31 PM
* To change this template use File | Settings | File Templates.
*/
@Component("sortablePersonDataProvider")
public class SortablePersonDataProvider extends SortableDataProvider<Person>
implements Serializable{
@Autowired(required=true)
private PersonService personService;
@Autowired(required=true)
private GuiService guiService;
/**
* constructor
*/
public SortablePersonDataProvider() {
// set default sort
setSort("lastName", true);
}
/**
* @see
org.apache.wicket.markup.repeater.data.IDataProvider#iterator(int, int)
*/
public Iterator<Person> iterator(int first, int count) {
return getPersonService().findPersonSubset(first, count, getSort());
}
/**
* @see org.apache.wicket.markup.repeater.data.IDataProvider#size()
*/
public int size() {
if (personService == null ) throw new
RuntimeException("personService is null value");
return getPersonService().personCount();
}
/**
* @see
org.apache.wicket.markup.repeater.data.IDataProvider#model(java.lang.Object)
*/
public IModel<Person> model(Person object) {
return new DetachablePersonModel(object);
}
public PersonService getPersonService() {
System.out.println("Person Service getter");
return personService;
}
public void setPersonService(PersonService personService) {
this.personService = personService;
System.out.println("Person Service setter");
}
public GuiService getGuiService() {
System.out.println("Gui Service getter");
return guiService;
}
public void setGuiService(GuiService guiService) {
this.guiService = guiService;
System.out.println("Gui Service setter");
}
}
Here is the stackTrace:
Caused by: java.lang.NullPointerException
at
org.seelink.web2.ui.user.SortablePersonDataProvider.iterator(SortablePersonDataProvider.java:47)
at
org.apache.wicket.markup.repeater.data.DataViewBase$ModelIterator.<init>(DataViewBase.java:109)
at
org.apache.wicket.markup.repeater.data.DataViewBase.getItemModels(DataViewBase.java:76)
at
org.apache.wicket.markup.repeater.AbstractPageableView.getItemModels(AbstractPageableView.java:107)
at
org.apache.wicket.markup.repeater.RefreshingView.onPopulate(RefreshingView.java:94)
at
org.apache.wicket.markup.repeater.AbstractRepeater.onBeforeRender(AbstractRepeater.java:131)
at
org.apache.wicket.markup.repeater.AbstractPageableView.onBeforeRender(AbstractPageableView.java:121)
at
org.apache.wicket.Component.internalBeforeRender(Component.java:1073)
at org.apache.wicket.Component.beforeRender(Component.java:1107)
at
org.apache.wicket.MarkupContainer.onBeforeRenderChildren(MarkupContainer.java:1753)
Here is the log entries that show the Beans getting injected:
DEBUG - DefaultListableBeanFactory - Creating shared instance of singleton
bean 'sortablePersonDataProvider'
DEBUG - DefaultListableBeanFactory - Creating instance of bean
'sortablePersonDataProvider'
DEBUG - InjectionMetadata - Found injected element on class
[org.seelink.web2.ui.user.SortablePersonDataProvider]: AutowiredFieldElement
for private org.seelink.web2.serv.PersonService
org.seelink.web2.ui.user.SortablePersonDataProvider.personService
DEBUG - InjectionMetadata - Found injected element on class
[org.seelink.web2.ui.user.SortablePersonDataProvider]: AutowiredFieldElement
for private org.seelink.web2.serv.GuiService
org.seelink.web2.ui.user.SortablePersonDataProvider.guiService
DEBUG - DefaultListableBeanFactory - Eagerly caching bean
'sortablePersonDataProvider' to allow for resolving potential circular
references
DEBUG - InjectionMetadata - Processing injected method of bean
'sortablePersonDataProvider': AutowiredFieldElement for private
org.seelink.web2.serv.PersonService
org.seelink.web2.ui.user.SortablePersonDataProvider.personService
DEBUG - DefaultListableBeanFactory - Returning cached instance of singleton
bean 'personService'
DEBUG - nnotationBeanPostProcessor - Autowiring by type from bean name
'sortablePersonDataProvider' to bean named 'personService'
DEBUG - InjectionMetadata - Processing injected method of bean
'sortablePersonDataProvider': AutowiredFieldElement for private
org.seelink.web2.serv.GuiService
org.seelink.web2.ui.user.SortablePersonDataProvider.guiService
DEBUG - DefaultListableBeanFactory - Returning cached instance of singleton
bean 'guiServiceImpl'
DEBUG - nnotationBeanPostProcessor - Autowiring by type from bean name
'sortablePersonDataProvider' to bean named 'guiServiceImpl'
DEBUG - DefaultListableBeanFactory - Returning cached instance of singleton
bean 'org.springframework.transaction.config.internalTransactionAdvisor'
DEBUG - DefaultListableBeanFactory - Finished creating instance of bean
'sortablePersonDataProvider'
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Can-t-get-a-SortableDataProvider-class-to-accept-DI-of-service-class-tp3218602p3218602.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Can't get a SortableDataProvider class to accept DI of service
class
Posted by Alexander Morozov <al...@gmail.com>.
1. Replace @Autowired with @SpringBean (do not forget to configure spring
instanciation listener in WebApplication)
2. Call InjectorHolder.getInstance().inject(this) from SortableDataProvider
ctor.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Can-t-get-a-SortableDataProvider-class-to-accept-DI-of-service-class-tp3218602p3218766.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Can't get a SortableDataProvider class to accept DI of service
class
Posted by lchalupa <lc...@seelink.org>.
Thanks. I got it working. I used the InjectorHolder.
Lee
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Can-t-get-a-SortableDataProvider-class-to-accept-DI-of-service-class-tp3218602p3219293.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Can't get a SortableDataProvider class to accept DI of service class
Posted by James Carman <ja...@carmanconsulting.com>.
Only components are automatically injected. Google a bit
On Jan 14, 2011 8:08 PM, "lchalupa" <lc...@seelink.org> wrote:
>
> The class SortableDataProvider throws a NPE. The PersonService and the
> GUIService that should be getting injected both end up being null values.
> I've tried both annotations @Autowired and @SpringBean. Neither seems to
> work.
>
> I turned on logging and I can see in the log that SortableDataProvider
being
> injected but obviously it isn't happening.
>
> Not sure how to diagnose this problem? Any Ideas?
>
>
> Lee
>
>
>
> Here is the SortableDataProvider Class:
>
> package org.seelink.web2.ui.user;
>
> import
>
org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
> import org.apache.wicket.model.IModel;
> import org.seelink.web2.model.role.Person;
> import org.seelink.web2.serv.GuiService;
> import org.seelink.web2.serv.PersonService;
> import org.seelink.web2.ui.appadm.DetachablePersonModel;
> import org.springframework.beans.factory.annotation.Autowired;
> import org.springframework.stereotype.Component;
>
> import java.io.Serializable;
> import java.util.Iterator;
>
>
> /**
> * Created by IntelliJ IDEA.
> * User: lchalupa
> * Date: 1/12/11
> * Time: 4:31 PM
> * To change this template use File | Settings | File Templates.
> */
> @Component("sortablePersonDataProvider")
> public class SortablePersonDataProvider extends
SortableDataProvider<Person>
> implements Serializable{
>
> @Autowired(required=true)
> private PersonService personService;
> @Autowired(required=true)
> private GuiService guiService;
>
>
> /**
> * constructor
> */
> public SortablePersonDataProvider() {
>
>
> // set default sort
> setSort("lastName", true);
> }
>
>
> /**
> * @see
> org.apache.wicket.markup.repeater.data.IDataProvider#iterator(int, int)
> */
> public Iterator<Person> iterator(int first, int count) {
> return getPersonService().findPersonSubset(first, count, getSort());
> }
>
> /**
> * @see org.apache.wicket.markup.repeater.data.IDataProvider#size()
> */
> public int size() {
> if (personService == null ) throw new
> RuntimeException("personService is null value");
> return getPersonService().personCount();
>
> }
>
> /**
> * @see
>
org.apache.wicket.markup.repeater.data.IDataProvider#model(java.lang.Object)
> */
> public IModel<Person> model(Person object) {
> return new DetachablePersonModel(object);
> }
>
>
> public PersonService getPersonService() {
> System.out.println("Person Service getter");
> return personService;
> }
>
> public void setPersonService(PersonService personService) {
> this.personService = personService;
> System.out.println("Person Service setter");
> }
>
>
> public GuiService getGuiService() {
> System.out.println("Gui Service getter");
> return guiService;
> }
>
> public void setGuiService(GuiService guiService) {
> this.guiService = guiService;
> System.out.println("Gui Service setter");
> }
> }
>
> Here is the stackTrace:
>
> Caused by: java.lang.NullPointerException
> at
>
org.seelink.web2.ui.user.SortablePersonDataProvider.iterator(SortablePersonDataProvider.java:47)
> at
>
org.apache.wicket.markup.repeater.data.DataViewBase$ModelIterator.<init>(DataViewBase.java:109)
> at
>
org.apache.wicket.markup.repeater.data.DataViewBase.getItemModels(DataViewBase.java:76)
> at
>
org.apache.wicket.markup.repeater.AbstractPageableView.getItemModels(AbstractPageableView.java:107)
> at
>
org.apache.wicket.markup.repeater.RefreshingView.onPopulate(RefreshingView.java:94)
> at
>
org.apache.wicket.markup.repeater.AbstractRepeater.onBeforeRender(AbstractRepeater.java:131)
> at
>
org.apache.wicket.markup.repeater.AbstractPageableView.onBeforeRender(AbstractPageableView.java:121)
> at
> org.apache.wicket.Component.internalBeforeRender(Component.java:1073)
> at org.apache.wicket.Component.beforeRender(Component.java:1107)
> at
>
org.apache.wicket.MarkupContainer.onBeforeRenderChildren(MarkupContainer.java:1753)
>
>
> Here is the log entries that show the Beans getting injected:
>
> DEBUG - DefaultListableBeanFactory - Creating shared instance of singleton
> bean 'sortablePersonDataProvider'
> DEBUG - DefaultListableBeanFactory - Creating instance of bean
> 'sortablePersonDataProvider'
> DEBUG - InjectionMetadata - Found injected element on class
> [org.seelink.web2.ui.user.SortablePersonDataProvider]:
AutowiredFieldElement
> for private org.seelink.web2.serv.PersonService
> org.seelink.web2.ui.user.SortablePersonDataProvider.personService
> DEBUG - InjectionMetadata - Found injected element on class
> [org.seelink.web2.ui.user.SortablePersonDataProvider]:
AutowiredFieldElement
> for private org.seelink.web2.serv.GuiService
> org.seelink.web2.ui.user.SortablePersonDataProvider.guiService
> DEBUG - DefaultListableBeanFactory - Eagerly caching bean
> 'sortablePersonDataProvider' to allow for resolving potential circular
> references
> DEBUG - InjectionMetadata - Processing injected method of bean
> 'sortablePersonDataProvider': AutowiredFieldElement for private
> org.seelink.web2.serv.PersonService
> org.seelink.web2.ui.user.SortablePersonDataProvider.personService
> DEBUG - DefaultListableBeanFactory - Returning cached instance of
singleton
> bean 'personService'
> DEBUG - nnotationBeanPostProcessor - Autowiring by type from bean name
> 'sortablePersonDataProvider' to bean named 'personService'
> DEBUG - InjectionMetadata - Processing injected method of bean
> 'sortablePersonDataProvider': AutowiredFieldElement for private
> org.seelink.web2.serv.GuiService
> org.seelink.web2.ui.user.SortablePersonDataProvider.guiService
> DEBUG - DefaultListableBeanFactory - Returning cached instance of
singleton
> bean 'guiServiceImpl'
> DEBUG - nnotationBeanPostProcessor - Autowiring by type from bean name
> 'sortablePersonDataProvider' to bean named 'guiServiceImpl'
> DEBUG - DefaultListableBeanFactory - Returning cached instance of
singleton
> bean 'org.springframework.transaction.config.internalTransactionAdvisor'
> DEBUG - DefaultListableBeanFactory - Finished creating instance of bean
> 'sortablePersonDataProvider'
> --
> View this message in context:
http://apache-wicket.1842946.n4.nabble.com/Can-t-get-a-SortableDataProvider-class-to-accept-DI-of-service-class-tp3218602p3218602.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>