You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Ch...@t-systems.com on 2017/02/22 10:06:56 UTC

NullPointerException on submitting a form in a modal window

Hello,

I have a page which contains a table form. Inside this table there are some message objects and their data shown. Moreover the user can select some of the messages and trigger some action on them. Then there should be a modal window where the user have to set a remark for the selected messages.

The modal window:
public class RemarkModalWindow extends ModalWindow{

        /** serialVersionUID */
        private static final long serialVersionUID = 8798141972520682460L;

        /**
         * Constructor for the modal window.
         *
         * @param id the id of the modal window
         */
        public RemarkModalWindow(String id) {
                super(id);

                RemarkPanel remarkPanel = new RemarkPanel(this.getContentId(), this);
                this.setContent(remarkPanel);

                this.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() {
                        /** serialVersionUID */
                        private static final long serialVersionUID = 4018212161671004354L;

                        @Override
                        public boolean onCloseButtonClicked(AjaxRequestTarget target) {
                                DAPForm<FaultModel> remarkForm = remarkPanel.getRemarkForm();
                                remarkForm.error(getString("remarkModalClose.errorMessage"));
                                target.add(remarkForm);
                                return false;
                        }
                });
        }

    @Override
    public boolean isResizable(){
        return false;
    }

    @Override
    public int getInitialWidth(){
        return 500;
    }

    @Override
    public int getInitialHeight(){
        return 100;
    }

    @Override
    public IModel<String> getTitle(){
                return Model.of(getString("remarkModal.title"));
        }
}

So I created a modal window which contains a panel. Inside the panel there is a form with the textfield for the remark and an "add" button. If I click the "add" button the window should be closed and the message objects should get the remark.
The panel inside the modal window:
public class RemarkPanel extends Panel {

        /** serialVersionUID */
        private static final long serialVersionUID = -8422969117822175332L;

        RemarkForm remarkForm;

        /**
         * Constructor which creates the panel.
         *
         * @param id the id of the panel
         * @param remarkModalWindow
         */
        public RemarkPanel(String id, RemarkModalWindow remarkModalWindow) {
                super(id);

                remarkForm = (RemarkForm)FormFactory.getForm(DAPType.REMARK);
                remarkForm.setModalWindow(remarkModalWindow);
                add(remarkForm);
        }

        public DAPForm<FaultModel> getRemarkForm() {
                return (DAPForm<FaultModel>) this.remarkForm;
        }
}

The Form inside the panel:
public class RemarkForm extends DAPForm<FaultModel> {

        /** serialVersionUID */
        private static final long serialVersionUID = -3714702420141947828L;
        private ModalWindow modalWindow;

        /**
         * Constructor which creates a form to set the remark of a fault message.
         *
         * @param id the id of the form
         */
        public RemarkForm(String id) {
                super(id);

                setDefaultModel(new CompoundPropertyModel<FaultModel>(new FaultModel()));

                addTextfields();
                addButtons();
        }

        /**
         * Adds the additional textfields.
         */
        private void addTextfields() {
                TextField<String> faultRemark = new TextField<>("faultRemark");

                add(faultRemark);
        }

        /**
         * Adds the buttons to the form.
         */
        private void addButtons() {
                add(new AddRemarkButton("addRemarkButton", this, modalWindow));
        }


        public void setModalWindow(ModalWindow modalWindow) {
                this.modalWindow = modalWindow;
        }
}

This is my "add" button:
public class AddRemarkButton extends AjaxButton {

        /** serialVersionUID */
        private static final long serialVersionUID = -8702103017249783842L;


        private ModalWindow modalWindow;

        public AddRemarkButton(String id, Form<?> form, ModalWindow modalWindow) {
                super(id, form);
                this.modalWindow = modalWindow;
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                FaultModel faultModel = (FaultModel)form.getModelObject();
                String remark = faultModel.getFaultRemark();
                System.out.println("Remark: " + remark);

                modalWindow.close(target);
        }
}

If I click the "add" button in the modal window I get the following exception:

    java.lang.NullPointerException
         at com.tsystems.dap.console.components.button.AddRemarkButton.onSubmit(AddRemarkButton.java:32)
         at org.apache.wicket.ajax.markup.html.form.AjaxButton$1.onSubmit(AjaxButton.java:113)
         at org.apache.wicket.ajax.form.AjaxFormSubmitBehavior$AjaxFormSubmitter.onSubmit(AjaxFormSubmitBehavior.java:215)
         at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1309)
         at org.apache.wicket.markup.html.form.Form.process(Form.java:976)
         at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:797)
         at org.apache.wicket.ajax.form.AjaxFormSubmitBehavior.onEvent(AjaxFormSubmitBehavior.java:171)
         at org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:155)
         at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:601)
         at java.lang.reflect.Method.invoke(Method.java:498)
         at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:258)
         at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:241)
         at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:248)
         at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:234)
         at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:895)
         at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
         at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:265)
         at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:222)
         at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:293)
         at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:261)
         at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:203)
         at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:284)
         at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
         at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
         at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
         at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
         at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
         at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
         at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
         at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
         at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
         at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
         at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)
         at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)
         at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
         at org.eclipse.jetty.server.Server.handle(Server.java:497)
         at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
         at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
         at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
         at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
         at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
         at java.lang.Thread.run(Thread.java:745)
    Complete stack:
    org.apache.wicket.WicketRuntimeException: Method onRequest of interface org.apache.wicket.behavior.IBehaviorListener targeted at org.apache.wicket.ajax.markup.html.form.AjaxButton$1@15e7639 on component [AddRemarkButton [Component id = addRemarkButton]] threw an exception
         at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:268)
         at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:241)
         at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:248)
         at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:234)
         at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:895)
         at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
         at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:265)
         at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:222)
         at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:293)
         at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:261)
    java.lang.reflect.InvocationTargetException
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
         at java.lang.reflect.Method.invoke(Method.java:498)
         at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:258)
         at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:241)
         at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:248)
         at org.apache.wicket.core.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:234)
         at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:895)
         at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
         at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:265)
         at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:222)
         at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:293)
         at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:261)
I don't know what I am doing wrong. Neither the AjaxRequestTarget nor the modalWindow is null. Can please somebody help me please?

Mit freundlichen Grüßen
Christoph Manig



AW: AW: NullPointerException on submitting a form in a modal window

Posted by Ch...@t-systems.com.
I found the line which set the modalWindow to null. Thanks for your help

Mit freundlichen Grüßen
Christoph Manig


-----Ursprüngliche Nachricht-----
Von: Manfred Bergmann [mailto:mb@software-by-mabe.com] 
Gesendet: Mittwoch, 22. Februar 2017 14:19
An: users@wicket.apache.org
Betreff: Re: AW: NullPointerException on submitting a form in a modal window

It it's that line, than only the modalWindow instance variable can be null.
Can you confirm that by either adding a log line or debug into there.

If it is indeed null something in the surrounding of the classes you show makes it null, or cleans it up. Some concurrency going on maybe?


Manfred

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/NullPointerException-on-submitting-a-form-in-a-modal-window-tp4677161p4677167.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


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


Re: NullPointerException on submitting a form in a modal window

Posted by Francois Meillet <fr...@gmail.com>.
When the RemarkForm is instancied, addButtons() is called. 
At this point the modalWindow is null.
So the modalWindow argument given to the AddRemarkButton constructor is null. 

You should modify the RemarkForm constructor to something like 
public RemarkForm(String id, ModalWindow modalWindow) {

François





> Le 22 févr. 2017 à 14:19, Manfred Bergmann <mb...@software-by-mabe.com> a écrit :
> 
> It it's that line, than only the modalWindow instance variable can be null.
> Can you confirm that by either adding a log line or debug into there.
> 
> If it is indeed null something in the surrounding of the classes you show
> makes it null, or cleans it up. Some concurrency going on maybe?
> 
> 
> Manfred
> 
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/NullPointerException-on-submitting-a-form-in-a-modal-window-tp4677161p4677167.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
> 


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


Re: AW: NullPointerException on submitting a form in a modal window

Posted by Manfred Bergmann <mb...@software-by-mabe.com>.
It it's that line, than only the modalWindow instance variable can be null.
Can you confirm that by either adding a log line or debug into there.

If it is indeed null something in the surrounding of the classes you show
makes it null, or cleans it up. Some concurrency going on maybe?


Manfred

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/NullPointerException-on-submitting-a-form-in-a-modal-window-tp4677161p4677167.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


AW: NullPointerException on submitting a form in a modal window

Posted by Ch...@t-systems.com.
The line which throws the exception is modalWindow.close(target); in AddRemarkButton. I do not copy the import statements so there are less lines in my copied code.


Mit freundlichen Grüßen
Christoph Manig

-----Ursprüngliche Nachricht-----
Von: Manfred Bergmann [mailto:mb@software-by-mabe.com] 
Gesendet: Mittwoch, 22. Februar 2017 11:41
An: users@wicket.apache.org
Betreff: Re: NullPointerException on submitting a form in a modal window

Maybe not all of those classes are in separate files.

Manfred

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/NullPointerException-on-submitting-a-form-in-a-modal-window-tp4677161p4677164.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


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


Re: NullPointerException on submitting a form in a modal window

Posted by Manfred Bergmann <mb...@software-by-mabe.com>.
Maybe not all of those classes are in separate files.

Manfred

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/NullPointerException-on-submitting-a-form-in-a-modal-window-tp4677161p4677164.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: NullPointerException on submitting a form in a modal window

Posted by christophManig <Ch...@t-systems.com>.
The line which throws the exception is modalWindow.close(target); in
AddRemarkButton. I do not copy the import statements so there are less lines
in my copied code.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/NullPointerException-on-submitting-a-form-in-a-modal-window-tp4677161p4677166.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: NullPointerException on submitting a form in a modal window

Posted by Francois Meillet <fr...@gmail.com>.
The AddRemarkButton source code you show is not the one who generated the exception.
The exception has been thrown line 32 in the submit method.
The source code you show has only 22 lines....

Put a breakpoint in the onSubmit method.

François




> Le 22 févr. 2017 à 11:16, Manfred Bergmann <mb...@software-by-mabe.com> a écrit :
> 
> Hi.
> 
> What's on line 32 of AddRemarkButton.java?
> 
> 
> Manfred
> 
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/NullPointerException-on-submitting-a-form-in-a-modal-window-tp4677161p4677162.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
> 


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


Re: NullPointerException on submitting a form in a modal window

Posted by Manfred Bergmann <mb...@software-by-mabe.com>.
Hi.

What's on line 32 of AddRemarkButton.java?


Manfred

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/NullPointerException-on-submitting-a-form-in-a-modal-window-tp4677161p4677162.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