Obligatory salve plug goes here :-)

It helps to understand what happens by stepping through some
construction logic of your components. If you follow that path you'll
venture along the registered IComponentInstantiationListener objects,
typically only your Spring component injector.

This doesn't work obviously for models and dataproviders because they
implement interfaces (IModel and IDataProvider respectively), and we
can't hook into their constructors the way we can with Component. The
same thing happens with your domain classes: they are outside Wicket's
reach.

Martijn

On Wed, Sep 9, 2009 at 10:26 AM, Matthias
Keller<matthias.kel...@ergon.ch> wrote:
> Hi Charles
>
> @SpringBean only seems to work in some wicket base classes. In your own
> separate classes, noone will actively inject your content.
> What I do (maybe there's a better possibility) is to add this line to that
> classes constructor to force injection:
>
> InjectorHolder.getInjector().inject(this);
>
> That way, all @SpringBean fields will be injected correctly.
>
> Matt
>
> Charles Moulliard wrote:
>>
>> Hi,
>>
>> I have a strange problem that I can't explain. I don't know if this is a
>> bug
>> or a limitation.
>>
>> When I inject Spring dependency of a service inside a Wicket web page,
>> everything works fine but when I inject this dependency in a separate
>> class
>> (in the following code example, the class RequestProvider is not longer
>> defined as internal class and moved to another package), I have a null
>> pointer exception at the following line :
>>
>>
>> 09:48:07,432 | ERROR | 3811...@qtp1-1   | RequestCycle
>> |
>> org.apache.wicket.RequestCycle   1521 | Error attaching this container for
>> rendering: [Page class = com.xpectis.x3s.fundbox.web.RequestPage, id = 0,
>> version = 0]
>> org.apache.wicket.WicketRuntimeException: Error attaching this container
>> for
>> rendering: [Page class = com.xpectis.x3s.fundbox.web.RequestPage, id = 0,
>> version = 0]
>>    at
>>
>> org.apache.wicket.MarkupContainer.onBeforeRenderChildren(MarkupContainer.java:1763)
>>    at org.apache.wicket.Component.onBeforeRender(Component.java:3863)
>>    at org.apache.wicket.Page.onBeforeRender(Page.java:1501)
>>    at
>> org.apache.wicket.Component.internalBeforeRender(Component.java:1061)
>>
>> ...
>> Caused by: java.lang.NullPointerException
>>    at
>>
>> com.xpectis.x3s.fundbox.web.data.RequestProvider.size(RequestProvider.java:63)
>>    at
>>
>> org.apache.wicket.markup.repeater.data.DataViewBase.internalGetItemCount(DataViewBase.java:140)
>>    at
>>
>> org.apache.wicket.markup.repeater.AbstractPageableView.getItemCount(AbstractPageableView.java:252)
>>
>> Line 63 corresponds to : size = requestService.findRequest().size();
>>
>> It seems that the requestService is not longer available when size method
>> is
>> called
>>
>>
>> Code which is working :
>>
>> public class RequestPage extends WebPage {
>>
>>   �...@springbean
>>    private RequestService requestService;
>>
>>    ....
>>
>>    private class RequestProvider implements IDataProvider {
>>
>>        private List<Request> result = new ArrayList<Request>();
>>        private RequestFormModel requestFormModel;
>>        private Request request;
>>
>>        public RequestProvider() {}
>>
>>        public RequestProvider(RequestFormModel requestFormModel) {
>>            this.requestFormModel = requestFormModel;
>>        }
>>
>>        public Iterator iterator(int first, int count) {
>>            if (requestFormModel != null) {
>>                if (requestFormModel.getRequestId() != null) {
>>                    request =
>> requestService.getRequest(requestFormModel.getRequestId());
>>                    result.add(request);
>>                } else if (requestFormModel.getFileName() != null) {
>>                    result =
>> requestService.findRequestByFileName(requestFormModel.getFileName());
>>                } else {
>>                    result = requestService.findRequest(first, count);
>>                }
>>            } else {
>>                result = requestService.findRequest(first, count);
>>            }
>>
>>            return result.iterator();
>>
>>        }
>>
>>        public int size() {
>>            int size = 0 ;
>>            if (requestFormModel != null) {
>>                if (requestFormModel.getRequestId() != null) {
>>                    request =
>> requestService.getRequest(requestFormModel.getRequestId());
>>                    result.add(request);
>>                    size = result.size();
>>                } else if (requestFormModel.getFileName() != null) {
>>                    size =
>>
>> requestService.findRequestByFileName(requestFormModel.getFileName()).size();
>>
>>                } else {
>>                    size = requestService.findRequest().size();
>>                }
>>            } else {
>>                size = requestService.findRequest().size();
>>            }
>>            return size;
>>        }
>>
>>        public IModel model(Object object) {
>>            return new Model((Request) object);
>>        }
>>
>>
>> Charles Moulliard
>> Senior Enterprise Architect
>> Apache Camel Committer
>>
>> *****************************
>> blog : http://cmoulliard.blogspot.com
>>
>>
>
>
>



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.4 increases type safety for web applications
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.4.0

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

Reply via email to