You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by lang <de...@telfort.nl> on 2012/07/05 00:49:50 UTC
image from outside web application directory
I need to show images from c:/pictures on my website. I searched and searched
and there should be something on old.nabble but that link is giving null
pointer results. Who can help?
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/image-from-outside-web-application-directory-tp4650379.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: Unable to use wicket tester to simulate ajax behavior
Posted by Giovanni Cuccu <gi...@cup2000.it>.
Hi,
here it is
https://issues.apache.org/jira/browse/WICKET-4670
Thanks,
Giovanni
Il 24/07/12 09.22, Martin Grigorov ha scritto:
> Hi,
>
> File a ticket with a test case.
>
> On Tue, Jul 24, 2012 at 9:34 AM, Giovanni Cuccu
> <gi...@cup2000.it> wrote:
>> Hi,
>> sorry for the late response. Should I file a bug for this?
>> Thanks,
>> Giovanni
>> Il 11/07/12 15.13, Giovanni Cuccu ha scritto:
>>
>>> Hi Martin,
>>> I did the change you suggested but the test fails with esame error:
>>>
>>> junit.framework.AssertionFailedError: expect no error message, but
>>> contains
>>> Field 'combo1' is required.
>>>
>>> Thanks,
>>> Giovanni
>>> Il 11/07/12 09.23, Martin Grigorov ha scritto:
>>>> Hi,
>>>>
>>>> Try with:
>>>>
>>>> tester.getRequest().setParameter("form:combo1", "0");
>>>> tester.executeAjaxEvent("form:combo1", "onchange");
>>>>
>>>> On Tue, Jul 10, 2012 at 10:10 AM, Giovanni Cuccu
>>>> <gi...@cup2000.it> wrote:
>>>>> Hi,
>>>>> can someone give me an hint on this?
>>>>> I tried to explain my problem providing a complete example and
>>>>> explaining
>>>>> what I was trying to achieve.
>>>>> I'd like to know if there is a specific reason of getting no answer so I
>>>>> can
>>>>> change something on my side the next time I need to write to the list.
>>>>> Thanks,
>>>>> Giovanni
>>>>> Il 05/07/12 08.10, Giovanni Cuccu ha scritto:
>>>>>
>>>>>> Hi all,
>>>>>> I'm trying to test a wicket 1.5.7 application and I'm hitting a
>>>>>> strange (at least for me) issue.
>>>>>> I have two dropdowns (combo 1 and combo2) and when I select one value
>>>>>> from combo1 I fire an AjaxUpdateBehavior on onchange event which
>>>>>> selects
>>>>>> a value on combo2.
>>>>>> If I use the application everything is working as expected but If I try
>>>>>> to simulate the application with wicket tester I come into trouble.
>>>>>> Basically the test code is the following one:
>>>>>>
>>>>>> WicketTester tester= new WicketTester(new
>>>>>> WicketApplication());
>>>>>> tester.startPage(TestAjaxDropDown.class);
>>>>>> FormTester formTester=tester.newFormTester("form");
>>>>>> formTester.select("combo1", 0);
>>>>>> tester.executeAjaxEvent("form:combo1", "onchange");
>>>>>> formTester.submit();
>>>>>> tester.assertNoErrorMessage();
>>>>>>
>>>>>> what I got is that after firing the onchange event combo1 gets a null
>>>>>> value as object model and this does not happen when I use a browser. If
>>>>>> I do not fire the event the application reports that combo2 has no
>>>>>> element selected.
>>>>>> Am I missing something or is it a bug?
>>>>>>
>>>>>> Grazie,
>>>>>> Giovanni
>>>>>>
>>>>>> P.S. I built a simple test case that I insert here
>>>>>>
>>>>>> main page class
>>>>>>
>>>>>> package com.sg2net.test;
>>>>>>
>>>>>> import java.io.Serializable;
>>>>>> import java.util.ArrayList;
>>>>>> import java.util.List;
>>>>>>
>>>>>> import org.apache.wicket.ajax.AjaxRequestTarget;
>>>>>> import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
>>>>>> import org.apache.wicket.markup.html.WebPage;
>>>>>> import org.apache.wicket.markup.html.form.ChoiceRenderer;
>>>>>> import org.apache.wicket.markup.html.form.DropDownChoice;
>>>>>> import org.apache.wicket.markup.html.form.Form;
>>>>>> import org.apache.wicket.markup.html.panel.FeedbackPanel;
>>>>>> import org.apache.wicket.model.PropertyModel;
>>>>>> import org.slf4j.Logger;
>>>>>> import org.slf4j.LoggerFactory;
>>>>>>
>>>>>>
>>>>>> public class TestAjaxDropDown extends WebPage {
>>>>>>
>>>>>> private static final Logger
>>>>>> logger=LoggerFactory.getLogger(TestAjaxDropDown.class.getName());
>>>>>>
>>>>>> public TestAjaxDropDown() {
>>>>>> add(new FeedbackPanel("feedback"));
>>>>>> add(new TestAjaxDropDownFrom("form"));
>>>>>> }
>>>>>>
>>>>>> private class DomainObject1 implements Serializable {
>>>>>> public DomainObject1(long id, String description) {
>>>>>> super();
>>>>>> this.id = id;
>>>>>> this.description = description;
>>>>>> }
>>>>>> private static final long serialVersionUID = 1L;
>>>>>> private long id;
>>>>>> private String description;
>>>>>>
>>>>>> public long getId() {
>>>>>> return id;
>>>>>> }
>>>>>> public void setId(long id) {
>>>>>> this.id = id;
>>>>>> }
>>>>>> public String getDescription() {
>>>>>> return description;
>>>>>> }
>>>>>> public void setDescription(String description) {
>>>>>> this.description = description;
>>>>>> }
>>>>>> @Override
>>>>>> public int hashCode() {
>>>>>> final int prime = 31;
>>>>>> int result = 1;
>>>>>> result = prime * result + getOuterType().hashCode();
>>>>>> result = prime * result + (int) (id ^ (id >>> 32));
>>>>>> return result;
>>>>>> }
>>>>>> @Override
>>>>>> public boolean equals(Object obj) {
>>>>>> if (this == obj)
>>>>>> return true;
>>>>>> if (obj == null)
>>>>>> return false;
>>>>>> if (getClass() != obj.getClass())
>>>>>> return false;
>>>>>> DomainObject1 other = (DomainObject1) obj;
>>>>>> if (!getOuterType().equals(other.getOuterType()))
>>>>>> return false;
>>>>>> if (id != other.id)
>>>>>> return false;
>>>>>> return true;
>>>>>> }
>>>>>> private TestAjaxDropDown getOuterType() {
>>>>>> return TestAjaxDropDown.this;
>>>>>> }
>>>>>>
>>>>>> }
>>>>>>
>>>>>> private class DomainObject2 implements Serializable {
>>>>>> public DomainObject2(long id, String description) {
>>>>>> super();
>>>>>> this.id = id;
>>>>>> this.description = description;
>>>>>> }
>>>>>> private static final long serialVersionUID = 1L;
>>>>>> private long id;
>>>>>> private String description;
>>>>>>
>>>>>> public long getId() {
>>>>>> return id;
>>>>>> }
>>>>>> public void setId(long id) {
>>>>>> this.id = id;
>>>>>> }
>>>>>> public String getDescription() {
>>>>>> return description;
>>>>>> }
>>>>>> public void setDescription(String description) {
>>>>>> this.description = description;
>>>>>> }
>>>>>> @Override
>>>>>> public int hashCode() {
>>>>>> final int prime = 31;
>>>>>> int result = 1;
>>>>>> result = prime * result + getOuterType().hashCode();
>>>>>> result = prime * result + (int) (id ^ (id >>> 32));
>>>>>> return result;
>>>>>> }
>>>>>> @Override
>>>>>> public boolean equals(Object obj) {
>>>>>> if (this == obj)
>>>>>> return true;
>>>>>> if (obj == null)
>>>>>> return false;
>>>>>> if (getClass() != obj.getClass())
>>>>>> return false;
>>>>>> DomainObject2 other = (DomainObject2) obj;
>>>>>> if (!getOuterType().equals(other.getOuterType()))
>>>>>> return false;
>>>>>> if (id != other.id)
>>>>>> return false;
>>>>>> return true;
>>>>>> }
>>>>>> private TestAjaxDropDown getOuterType() {
>>>>>> return TestAjaxDropDown.this;
>>>>>> }
>>>>>>
>>>>>> }
>>>>>>
>>>>>> private static final long serialVersionUID = 1L;
>>>>>>
>>>>>> private class TestAjaxDropDownFrom extends Form<Void> {
>>>>>>
>>>>>> private static final long serialVersionUID = 1L;
>>>>>> private DomainObject1 domainObject1;
>>>>>> private DomainObject2 domainObject2;
>>>>>> private DropDownChoice<DomainObject2> secondCombo;
>>>>>>
>>>>>> public TestAjaxDropDownFrom(String id) {
>>>>>> super(id);
>>>>>> List<DomainObject1> choicesForCombo1= new
>>>>>> ArrayList<DomainObject1>();
>>>>>> choicesForCombo1.add(new DomainObject1(1L,"uno"));
>>>>>> choicesForCombo1.add(new DomainObject1(2L,"due"));
>>>>>> choicesForCombo1.add(new DomainObject1(3L,"tre"));
>>>>>> DropDownChoice<DomainObject1> firstCombo= new
>>>>>> DropDownChoice<DomainObject1>("combo1",
>>>>>> new
>>>>>> PropertyModel<DomainObject1>(this,"domainObject1"),choicesForCombo1,
>>>>>> new ChoiceRenderer<DomainObject1>("description",
>>>>>> "id"));
>>>>>> firstCombo.setRequired(true);
>>>>>> firstCombo.setNullValid(true);
>>>>>> firstCombo.add(new AjaxUpdateBehavior("onchange"));
>>>>>> add(firstCombo);
>>>>>>
>>>>>> List<DomainObject2> choicesForCombo2= new
>>>>>> ArrayList<DomainObject2>();
>>>>>> choicesForCombo2.add(new DomainObject2(10L,"unozero"));
>>>>>> choicesForCombo2.add(new DomainObject2(20L,"duezero"));
>>>>>> choicesForCombo2.add(new DomainObject2(30L,"trezero"));
>>>>>> secondCombo= new DropDownChoice<DomainObject2>("combo2",
>>>>>> new
>>>>>> PropertyModel<DomainObject2>(this,"domainObject2"),choicesForCombo2,
>>>>>> new ChoiceRenderer<DomainObject2>("description",
>>>>>> "id"));
>>>>>> secondCombo.setOutputMarkupId(true);
>>>>>> secondCombo.setNullValid(true);
>>>>>> add(secondCombo);
>>>>>>
>>>>>> }
>>>>>>
>>>>>> @Override
>>>>>> public void onSubmit() {
>>>>>> if (domainObject2==null) {
>>>>>> error("Domain object2 is null");
>>>>>> } else {
>>>>>> info("OK");
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> private class AjaxUpdateBehavior extends
>>>>>> AjaxFormComponentUpdatingBehavior {
>>>>>>
>>>>>>
>>>>>> private static final long serialVersionUID = 1L;
>>>>>>
>>>>>> public AjaxUpdateBehavior(String event) {
>>>>>> super(event);
>>>>>> }
>>>>>>
>>>>>> @Override
>>>>>> protected void onUpdate(AjaxRequestTarget target) {
>>>>>> if (domainObject1!=null) {
>>>>>> logger.warn("domainObject1.getId()=" +
>>>>>> domainObject1.getId());
>>>>>> if (domainObject1.getId()==1L) {
>>>>>> domainObject2=new
>>>>>> DomainObject2(10L,"unozero");
>>>>>> logger.warn("domainObject2.getId()=" +
>>>>>> domainObject2.getId());
>>>>>> }
>>>>>> if (domainObject1.getId()==2L) {
>>>>>> domainObject2=new
>>>>>> DomainObject2(20L,"duezero");
>>>>>> logger.warn("domainObject2.getId()=" +
>>>>>> domainObject2.getId());
>>>>>> }
>>>>>> if (domainObject1.getId()==3L) {
>>>>>> domainObject2=new
>>>>>> DomainObject2(30L,"trezero");
>>>>>> logger.warn("domainObject2.getId()=" +
>>>>>> domainObject2.getId());
>>>>>> }
>>>>>> secondCombo.modelChanged();
>>>>>> target.add(secondCombo);
>>>>>> } else {
>>>>>> logger.warn("domainObject1==null");
>>>>>> }
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> test class
>>>>>>
>>>>>> package com.sg2net.test;
>>>>>>
>>>>>> import org.apache.wicket.util.tester.FormTester;
>>>>>> import org.apache.wicket.util.tester.WicketTester;
>>>>>> import org.testng.annotations.Test;
>>>>>>
>>>>>> public class WicketTesterAjaxDropDown {
>>>>>> @Test
>>>>>> public void testAjaxDropDown() {
>>>>>> WicketTester tester= new WicketTester(new
>>>>>> WicketApplication());
>>>>>> tester.startPage(TestAjaxDropDown.class);
>>>>>> FormTester formTester=tester.newFormTester("form");
>>>>>> formTester.select("combo1", 0);
>>>>>> tester.executeAjaxEvent("form:combo1", "onchange");
>>>>>> //formTester.select("combo1", 0);
>>>>>> formTester.submit();
>>>>>> tester.assertNoErrorMessage();
>>>>>> }
>>>>>> }
>>>>>>
>>>>>> wicket application class
>>>>>>
>>>>>> package com.sg2net.test;
>>>>>> import org.apache.wicket.Page;
>>>>>> import org.apache.wicket.protocol.http.WebApplication;
>>>>>>
>>>>>> import com.sg2net.test.TestAjaxDropDown;
>>>>>>
>>>>>>
>>>>>> public class WicketApplication extends WebApplication {
>>>>>>
>>>>>> @Override
>>>>>> public Class<? extends Page> getHomePage() {
>>>>>>
>>>>>> return TestAjaxDropDown.class;
>>>>>> }
>>>>>>
>>>>>> protected void init() {
>>>>>> getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
>>>>>> }
>>>>>>
>>>>>> }
>>>>>>
>>>>>>
>>>>>>
>>>>> --
>>>>> Giovanni Cuccu
>>>>> Responsabile area sviluppo - CUP 2000 Spa
>>>>> Via del Borgo di S. Pietro, 90/c - 40126 Bologna
>>>>> e-mail: giovanni.cuccu _at_ cup2000.it
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>
>> --
>> Giovanni Cuccu
>> Responsabile area sviluppo - CUP 2000 Spa
>> Via del Borgo di S. Pietro, 90/c - 40126 Bologna
>> e-mail: giovanni.cuccu _at_ cup2000.it
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>
>
--
Giovanni Cuccu
Responsabile area sviluppo - CUP 2000 Spa
Via del Borgo di S. Pietro, 90/c - 40126 Bologna
e-mail: giovanni.cuccu _at_ cup2000.it
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Unable to use wicket tester to simulate ajax behavior
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
File a ticket with a test case.
On Tue, Jul 24, 2012 at 9:34 AM, Giovanni Cuccu
<gi...@cup2000.it> wrote:
> Hi,
> sorry for the late response. Should I file a bug for this?
> Thanks,
> Giovanni
> Il 11/07/12 15.13, Giovanni Cuccu ha scritto:
>
>> Hi Martin,
>> I did the change you suggested but the test fails with esame error:
>>
>> junit.framework.AssertionFailedError: expect no error message, but
>> contains
>> Field 'combo1' is required.
>>
>> Thanks,
>> Giovanni
>> Il 11/07/12 09.23, Martin Grigorov ha scritto:
>>>
>>> Hi,
>>>
>>> Try with:
>>>
>>> tester.getRequest().setParameter("form:combo1", "0");
>>> tester.executeAjaxEvent("form:combo1", "onchange");
>>>
>>> On Tue, Jul 10, 2012 at 10:10 AM, Giovanni Cuccu
>>> <gi...@cup2000.it> wrote:
>>>>
>>>> Hi,
>>>> can someone give me an hint on this?
>>>> I tried to explain my problem providing a complete example and
>>>> explaining
>>>> what I was trying to achieve.
>>>> I'd like to know if there is a specific reason of getting no answer so I
>>>> can
>>>> change something on my side the next time I need to write to the list.
>>>> Thanks,
>>>> Giovanni
>>>> Il 05/07/12 08.10, Giovanni Cuccu ha scritto:
>>>>
>>>>> Hi all,
>>>>> I'm trying to test a wicket 1.5.7 application and I'm hitting a
>>>>> strange (at least for me) issue.
>>>>> I have two dropdowns (combo 1 and combo2) and when I select one value
>>>>> from combo1 I fire an AjaxUpdateBehavior on onchange event which
>>>>> selects
>>>>> a value on combo2.
>>>>> If I use the application everything is working as expected but If I try
>>>>> to simulate the application with wicket tester I come into trouble.
>>>>> Basically the test code is the following one:
>>>>>
>>>>> WicketTester tester= new WicketTester(new
>>>>> WicketApplication());
>>>>> tester.startPage(TestAjaxDropDown.class);
>>>>> FormTester formTester=tester.newFormTester("form");
>>>>> formTester.select("combo1", 0);
>>>>> tester.executeAjaxEvent("form:combo1", "onchange");
>>>>> formTester.submit();
>>>>> tester.assertNoErrorMessage();
>>>>>
>>>>> what I got is that after firing the onchange event combo1 gets a null
>>>>> value as object model and this does not happen when I use a browser. If
>>>>> I do not fire the event the application reports that combo2 has no
>>>>> element selected.
>>>>> Am I missing something or is it a bug?
>>>>>
>>>>> Grazie,
>>>>> Giovanni
>>>>>
>>>>> P.S. I built a simple test case that I insert here
>>>>>
>>>>> main page class
>>>>>
>>>>> package com.sg2net.test;
>>>>>
>>>>> import java.io.Serializable;
>>>>> import java.util.ArrayList;
>>>>> import java.util.List;
>>>>>
>>>>> import org.apache.wicket.ajax.AjaxRequestTarget;
>>>>> import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
>>>>> import org.apache.wicket.markup.html.WebPage;
>>>>> import org.apache.wicket.markup.html.form.ChoiceRenderer;
>>>>> import org.apache.wicket.markup.html.form.DropDownChoice;
>>>>> import org.apache.wicket.markup.html.form.Form;
>>>>> import org.apache.wicket.markup.html.panel.FeedbackPanel;
>>>>> import org.apache.wicket.model.PropertyModel;
>>>>> import org.slf4j.Logger;
>>>>> import org.slf4j.LoggerFactory;
>>>>>
>>>>>
>>>>> public class TestAjaxDropDown extends WebPage {
>>>>>
>>>>> private static final Logger
>>>>> logger=LoggerFactory.getLogger(TestAjaxDropDown.class.getName());
>>>>>
>>>>> public TestAjaxDropDown() {
>>>>> add(new FeedbackPanel("feedback"));
>>>>> add(new TestAjaxDropDownFrom("form"));
>>>>> }
>>>>>
>>>>> private class DomainObject1 implements Serializable {
>>>>> public DomainObject1(long id, String description) {
>>>>> super();
>>>>> this.id = id;
>>>>> this.description = description;
>>>>> }
>>>>> private static final long serialVersionUID = 1L;
>>>>> private long id;
>>>>> private String description;
>>>>>
>>>>> public long getId() {
>>>>> return id;
>>>>> }
>>>>> public void setId(long id) {
>>>>> this.id = id;
>>>>> }
>>>>> public String getDescription() {
>>>>> return description;
>>>>> }
>>>>> public void setDescription(String description) {
>>>>> this.description = description;
>>>>> }
>>>>> @Override
>>>>> public int hashCode() {
>>>>> final int prime = 31;
>>>>> int result = 1;
>>>>> result = prime * result + getOuterType().hashCode();
>>>>> result = prime * result + (int) (id ^ (id >>> 32));
>>>>> return result;
>>>>> }
>>>>> @Override
>>>>> public boolean equals(Object obj) {
>>>>> if (this == obj)
>>>>> return true;
>>>>> if (obj == null)
>>>>> return false;
>>>>> if (getClass() != obj.getClass())
>>>>> return false;
>>>>> DomainObject1 other = (DomainObject1) obj;
>>>>> if (!getOuterType().equals(other.getOuterType()))
>>>>> return false;
>>>>> if (id != other.id)
>>>>> return false;
>>>>> return true;
>>>>> }
>>>>> private TestAjaxDropDown getOuterType() {
>>>>> return TestAjaxDropDown.this;
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>> private class DomainObject2 implements Serializable {
>>>>> public DomainObject2(long id, String description) {
>>>>> super();
>>>>> this.id = id;
>>>>> this.description = description;
>>>>> }
>>>>> private static final long serialVersionUID = 1L;
>>>>> private long id;
>>>>> private String description;
>>>>>
>>>>> public long getId() {
>>>>> return id;
>>>>> }
>>>>> public void setId(long id) {
>>>>> this.id = id;
>>>>> }
>>>>> public String getDescription() {
>>>>> return description;
>>>>> }
>>>>> public void setDescription(String description) {
>>>>> this.description = description;
>>>>> }
>>>>> @Override
>>>>> public int hashCode() {
>>>>> final int prime = 31;
>>>>> int result = 1;
>>>>> result = prime * result + getOuterType().hashCode();
>>>>> result = prime * result + (int) (id ^ (id >>> 32));
>>>>> return result;
>>>>> }
>>>>> @Override
>>>>> public boolean equals(Object obj) {
>>>>> if (this == obj)
>>>>> return true;
>>>>> if (obj == null)
>>>>> return false;
>>>>> if (getClass() != obj.getClass())
>>>>> return false;
>>>>> DomainObject2 other = (DomainObject2) obj;
>>>>> if (!getOuterType().equals(other.getOuterType()))
>>>>> return false;
>>>>> if (id != other.id)
>>>>> return false;
>>>>> return true;
>>>>> }
>>>>> private TestAjaxDropDown getOuterType() {
>>>>> return TestAjaxDropDown.this;
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>> private static final long serialVersionUID = 1L;
>>>>>
>>>>> private class TestAjaxDropDownFrom extends Form<Void> {
>>>>>
>>>>> private static final long serialVersionUID = 1L;
>>>>> private DomainObject1 domainObject1;
>>>>> private DomainObject2 domainObject2;
>>>>> private DropDownChoice<DomainObject2> secondCombo;
>>>>>
>>>>> public TestAjaxDropDownFrom(String id) {
>>>>> super(id);
>>>>> List<DomainObject1> choicesForCombo1= new
>>>>> ArrayList<DomainObject1>();
>>>>> choicesForCombo1.add(new DomainObject1(1L,"uno"));
>>>>> choicesForCombo1.add(new DomainObject1(2L,"due"));
>>>>> choicesForCombo1.add(new DomainObject1(3L,"tre"));
>>>>> DropDownChoice<DomainObject1> firstCombo= new
>>>>> DropDownChoice<DomainObject1>("combo1",
>>>>> new
>>>>> PropertyModel<DomainObject1>(this,"domainObject1"),choicesForCombo1,
>>>>> new ChoiceRenderer<DomainObject1>("description",
>>>>> "id"));
>>>>> firstCombo.setRequired(true);
>>>>> firstCombo.setNullValid(true);
>>>>> firstCombo.add(new AjaxUpdateBehavior("onchange"));
>>>>> add(firstCombo);
>>>>>
>>>>> List<DomainObject2> choicesForCombo2= new
>>>>> ArrayList<DomainObject2>();
>>>>> choicesForCombo2.add(new DomainObject2(10L,"unozero"));
>>>>> choicesForCombo2.add(new DomainObject2(20L,"duezero"));
>>>>> choicesForCombo2.add(new DomainObject2(30L,"trezero"));
>>>>> secondCombo= new DropDownChoice<DomainObject2>("combo2",
>>>>> new
>>>>> PropertyModel<DomainObject2>(this,"domainObject2"),choicesForCombo2,
>>>>> new ChoiceRenderer<DomainObject2>("description",
>>>>> "id"));
>>>>> secondCombo.setOutputMarkupId(true);
>>>>> secondCombo.setNullValid(true);
>>>>> add(secondCombo);
>>>>>
>>>>> }
>>>>>
>>>>> @Override
>>>>> public void onSubmit() {
>>>>> if (domainObject2==null) {
>>>>> error("Domain object2 is null");
>>>>> } else {
>>>>> info("OK");
>>>>> }
>>>>> }
>>>>>
>>>>> private class AjaxUpdateBehavior extends
>>>>> AjaxFormComponentUpdatingBehavior {
>>>>>
>>>>>
>>>>> private static final long serialVersionUID = 1L;
>>>>>
>>>>> public AjaxUpdateBehavior(String event) {
>>>>> super(event);
>>>>> }
>>>>>
>>>>> @Override
>>>>> protected void onUpdate(AjaxRequestTarget target) {
>>>>> if (domainObject1!=null) {
>>>>> logger.warn("domainObject1.getId()=" +
>>>>> domainObject1.getId());
>>>>> if (domainObject1.getId()==1L) {
>>>>> domainObject2=new
>>>>> DomainObject2(10L,"unozero");
>>>>> logger.warn("domainObject2.getId()=" +
>>>>> domainObject2.getId());
>>>>> }
>>>>> if (domainObject1.getId()==2L) {
>>>>> domainObject2=new
>>>>> DomainObject2(20L,"duezero");
>>>>> logger.warn("domainObject2.getId()=" +
>>>>> domainObject2.getId());
>>>>> }
>>>>> if (domainObject1.getId()==3L) {
>>>>> domainObject2=new
>>>>> DomainObject2(30L,"trezero");
>>>>> logger.warn("domainObject2.getId()=" +
>>>>> domainObject2.getId());
>>>>> }
>>>>> secondCombo.modelChanged();
>>>>> target.add(secondCombo);
>>>>> } else {
>>>>> logger.warn("domainObject1==null");
>>>>> }
>>>>> }
>>>>> }
>>>>>
>>>>> }
>>>>> }
>>>>>
>>>>> test class
>>>>>
>>>>> package com.sg2net.test;
>>>>>
>>>>> import org.apache.wicket.util.tester.FormTester;
>>>>> import org.apache.wicket.util.tester.WicketTester;
>>>>> import org.testng.annotations.Test;
>>>>>
>>>>> public class WicketTesterAjaxDropDown {
>>>>> @Test
>>>>> public void testAjaxDropDown() {
>>>>> WicketTester tester= new WicketTester(new
>>>>> WicketApplication());
>>>>> tester.startPage(TestAjaxDropDown.class);
>>>>> FormTester formTester=tester.newFormTester("form");
>>>>> formTester.select("combo1", 0);
>>>>> tester.executeAjaxEvent("form:combo1", "onchange");
>>>>> //formTester.select("combo1", 0);
>>>>> formTester.submit();
>>>>> tester.assertNoErrorMessage();
>>>>> }
>>>>> }
>>>>>
>>>>> wicket application class
>>>>>
>>>>> package com.sg2net.test;
>>>>> import org.apache.wicket.Page;
>>>>> import org.apache.wicket.protocol.http.WebApplication;
>>>>>
>>>>> import com.sg2net.test.TestAjaxDropDown;
>>>>>
>>>>>
>>>>> public class WicketApplication extends WebApplication {
>>>>>
>>>>> @Override
>>>>> public Class<? extends Page> getHomePage() {
>>>>>
>>>>> return TestAjaxDropDown.class;
>>>>> }
>>>>>
>>>>> protected void init() {
>>>>> getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>>
>>>>>
>>>> --
>>>> Giovanni Cuccu
>>>> Responsabile area sviluppo - CUP 2000 Spa
>>>> Via del Borgo di S. Pietro, 90/c - 40126 Bologna
>>>> e-mail: giovanni.cuccu _at_ cup2000.it
>>>>
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>
>>>
>>
>
> --
> Giovanni Cuccu
> Responsabile area sviluppo - CUP 2000 Spa
> Via del Borgo di S. Pietro, 90/c - 40126 Bologna
> e-mail: giovanni.cuccu _at_ cup2000.it
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Unable to use wicket tester to simulate ajax behavior
Posted by Giovanni Cuccu <gi...@cup2000.it>.
Hi,
sorry for the late response. Should I file a bug for this?
Thanks,
Giovanni
Il 11/07/12 15.13, Giovanni Cuccu ha scritto:
> Hi Martin,
> I did the change you suggested but the test fails with esame error:
>
> junit.framework.AssertionFailedError: expect no error message, but
> contains
> Field 'combo1' is required.
>
> Thanks,
> Giovanni
> Il 11/07/12 09.23, Martin Grigorov ha scritto:
>> Hi,
>>
>> Try with:
>>
>> tester.getRequest().setParameter("form:combo1", "0");
>> tester.executeAjaxEvent("form:combo1", "onchange");
>>
>> On Tue, Jul 10, 2012 at 10:10 AM, Giovanni Cuccu
>> <gi...@cup2000.it> wrote:
>>> Hi,
>>> can someone give me an hint on this?
>>> I tried to explain my problem providing a complete example and
>>> explaining
>>> what I was trying to achieve.
>>> I'd like to know if there is a specific reason of getting no answer
>>> so I can
>>> change something on my side the next time I need to write to the list.
>>> Thanks,
>>> Giovanni
>>> Il 05/07/12 08.10, Giovanni Cuccu ha scritto:
>>>
>>>> Hi all,
>>>> I'm trying to test a wicket 1.5.7 application and I'm hitting a
>>>> strange (at least for me) issue.
>>>> I have two dropdowns (combo 1 and combo2) and when I select one value
>>>> from combo1 I fire an AjaxUpdateBehavior on onchange event which
>>>> selects
>>>> a value on combo2.
>>>> If I use the application everything is working as expected but If I
>>>> try
>>>> to simulate the application with wicket tester I come into trouble.
>>>> Basically the test code is the following one:
>>>>
>>>> WicketTester tester= new WicketTester(new
>>>> WicketApplication());
>>>> tester.startPage(TestAjaxDropDown.class);
>>>> FormTester formTester=tester.newFormTester("form");
>>>> formTester.select("combo1", 0);
>>>> tester.executeAjaxEvent("form:combo1", "onchange");
>>>> formTester.submit();
>>>> tester.assertNoErrorMessage();
>>>>
>>>> what I got is that after firing the onchange event combo1 gets a null
>>>> value as object model and this does not happen when I use a
>>>> browser. If
>>>> I do not fire the event the application reports that combo2 has no
>>>> element selected.
>>>> Am I missing something or is it a bug?
>>>>
>>>> Grazie,
>>>> Giovanni
>>>>
>>>> P.S. I built a simple test case that I insert here
>>>>
>>>> main page class
>>>>
>>>> package com.sg2net.test;
>>>>
>>>> import java.io.Serializable;
>>>> import java.util.ArrayList;
>>>> import java.util.List;
>>>>
>>>> import org.apache.wicket.ajax.AjaxRequestTarget;
>>>> import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
>>>> import org.apache.wicket.markup.html.WebPage;
>>>> import org.apache.wicket.markup.html.form.ChoiceRenderer;
>>>> import org.apache.wicket.markup.html.form.DropDownChoice;
>>>> import org.apache.wicket.markup.html.form.Form;
>>>> import org.apache.wicket.markup.html.panel.FeedbackPanel;
>>>> import org.apache.wicket.model.PropertyModel;
>>>> import org.slf4j.Logger;
>>>> import org.slf4j.LoggerFactory;
>>>>
>>>>
>>>> public class TestAjaxDropDown extends WebPage {
>>>>
>>>> private static final Logger
>>>> logger=LoggerFactory.getLogger(TestAjaxDropDown.class.getName());
>>>>
>>>> public TestAjaxDropDown() {
>>>> add(new FeedbackPanel("feedback"));
>>>> add(new TestAjaxDropDownFrom("form"));
>>>> }
>>>>
>>>> private class DomainObject1 implements Serializable {
>>>> public DomainObject1(long id, String description) {
>>>> super();
>>>> this.id = id;
>>>> this.description = description;
>>>> }
>>>> private static final long serialVersionUID = 1L;
>>>> private long id;
>>>> private String description;
>>>>
>>>> public long getId() {
>>>> return id;
>>>> }
>>>> public void setId(long id) {
>>>> this.id = id;
>>>> }
>>>> public String getDescription() {
>>>> return description;
>>>> }
>>>> public void setDescription(String description) {
>>>> this.description = description;
>>>> }
>>>> @Override
>>>> public int hashCode() {
>>>> final int prime = 31;
>>>> int result = 1;
>>>> result = prime * result + getOuterType().hashCode();
>>>> result = prime * result + (int) (id ^ (id >>> 32));
>>>> return result;
>>>> }
>>>> @Override
>>>> public boolean equals(Object obj) {
>>>> if (this == obj)
>>>> return true;
>>>> if (obj == null)
>>>> return false;
>>>> if (getClass() != obj.getClass())
>>>> return false;
>>>> DomainObject1 other = (DomainObject1) obj;
>>>> if (!getOuterType().equals(other.getOuterType()))
>>>> return false;
>>>> if (id != other.id)
>>>> return false;
>>>> return true;
>>>> }
>>>> private TestAjaxDropDown getOuterType() {
>>>> return TestAjaxDropDown.this;
>>>> }
>>>>
>>>> }
>>>>
>>>> private class DomainObject2 implements Serializable {
>>>> public DomainObject2(long id, String description) {
>>>> super();
>>>> this.id = id;
>>>> this.description = description;
>>>> }
>>>> private static final long serialVersionUID = 1L;
>>>> private long id;
>>>> private String description;
>>>>
>>>> public long getId() {
>>>> return id;
>>>> }
>>>> public void setId(long id) {
>>>> this.id = id;
>>>> }
>>>> public String getDescription() {
>>>> return description;
>>>> }
>>>> public void setDescription(String description) {
>>>> this.description = description;
>>>> }
>>>> @Override
>>>> public int hashCode() {
>>>> final int prime = 31;
>>>> int result = 1;
>>>> result = prime * result + getOuterType().hashCode();
>>>> result = prime * result + (int) (id ^ (id >>> 32));
>>>> return result;
>>>> }
>>>> @Override
>>>> public boolean equals(Object obj) {
>>>> if (this == obj)
>>>> return true;
>>>> if (obj == null)
>>>> return false;
>>>> if (getClass() != obj.getClass())
>>>> return false;
>>>> DomainObject2 other = (DomainObject2) obj;
>>>> if (!getOuterType().equals(other.getOuterType()))
>>>> return false;
>>>> if (id != other.id)
>>>> return false;
>>>> return true;
>>>> }
>>>> private TestAjaxDropDown getOuterType() {
>>>> return TestAjaxDropDown.this;
>>>> }
>>>>
>>>> }
>>>>
>>>> private static final long serialVersionUID = 1L;
>>>>
>>>> private class TestAjaxDropDownFrom extends Form<Void> {
>>>>
>>>> private static final long serialVersionUID = 1L;
>>>> private DomainObject1 domainObject1;
>>>> private DomainObject2 domainObject2;
>>>> private DropDownChoice<DomainObject2> secondCombo;
>>>>
>>>> public TestAjaxDropDownFrom(String id) {
>>>> super(id);
>>>> List<DomainObject1> choicesForCombo1= new
>>>> ArrayList<DomainObject1>();
>>>> choicesForCombo1.add(new DomainObject1(1L,"uno"));
>>>> choicesForCombo1.add(new DomainObject1(2L,"due"));
>>>> choicesForCombo1.add(new DomainObject1(3L,"tre"));
>>>> DropDownChoice<DomainObject1> firstCombo= new
>>>> DropDownChoice<DomainObject1>("combo1",
>>>> new
>>>> PropertyModel<DomainObject1>(this,"domainObject1"),choicesForCombo1,
>>>> new ChoiceRenderer<DomainObject1>("description",
>>>> "id"));
>>>> firstCombo.setRequired(true);
>>>> firstCombo.setNullValid(true);
>>>> firstCombo.add(new AjaxUpdateBehavior("onchange"));
>>>> add(firstCombo);
>>>>
>>>> List<DomainObject2> choicesForCombo2= new
>>>> ArrayList<DomainObject2>();
>>>> choicesForCombo2.add(new DomainObject2(10L,"unozero"));
>>>> choicesForCombo2.add(new DomainObject2(20L,"duezero"));
>>>> choicesForCombo2.add(new DomainObject2(30L,"trezero"));
>>>> secondCombo= new DropDownChoice<DomainObject2>("combo2",
>>>> new
>>>> PropertyModel<DomainObject2>(this,"domainObject2"),choicesForCombo2,
>>>> new ChoiceRenderer<DomainObject2>("description",
>>>> "id"));
>>>> secondCombo.setOutputMarkupId(true);
>>>> secondCombo.setNullValid(true);
>>>> add(secondCombo);
>>>>
>>>> }
>>>>
>>>> @Override
>>>> public void onSubmit() {
>>>> if (domainObject2==null) {
>>>> error("Domain object2 is null");
>>>> } else {
>>>> info("OK");
>>>> }
>>>> }
>>>>
>>>> private class AjaxUpdateBehavior extends
>>>> AjaxFormComponentUpdatingBehavior {
>>>>
>>>>
>>>> private static final long serialVersionUID = 1L;
>>>>
>>>> public AjaxUpdateBehavior(String event) {
>>>> super(event);
>>>> }
>>>>
>>>> @Override
>>>> protected void onUpdate(AjaxRequestTarget target) {
>>>> if (domainObject1!=null) {
>>>> logger.warn("domainObject1.getId()=" +
>>>> domainObject1.getId());
>>>> if (domainObject1.getId()==1L) {
>>>> domainObject2=new
>>>> DomainObject2(10L,"unozero");
>>>> logger.warn("domainObject2.getId()=" +
>>>> domainObject2.getId());
>>>> }
>>>> if (domainObject1.getId()==2L) {
>>>> domainObject2=new
>>>> DomainObject2(20L,"duezero");
>>>> logger.warn("domainObject2.getId()=" +
>>>> domainObject2.getId());
>>>> }
>>>> if (domainObject1.getId()==3L) {
>>>> domainObject2=new
>>>> DomainObject2(30L,"trezero");
>>>> logger.warn("domainObject2.getId()=" +
>>>> domainObject2.getId());
>>>> }
>>>> secondCombo.modelChanged();
>>>> target.add(secondCombo);
>>>> } else {
>>>> logger.warn("domainObject1==null");
>>>> }
>>>> }
>>>> }
>>>>
>>>> }
>>>> }
>>>>
>>>> test class
>>>>
>>>> package com.sg2net.test;
>>>>
>>>> import org.apache.wicket.util.tester.FormTester;
>>>> import org.apache.wicket.util.tester.WicketTester;
>>>> import org.testng.annotations.Test;
>>>>
>>>> public class WicketTesterAjaxDropDown {
>>>> @Test
>>>> public void testAjaxDropDown() {
>>>> WicketTester tester= new WicketTester(new
>>>> WicketApplication());
>>>> tester.startPage(TestAjaxDropDown.class);
>>>> FormTester formTester=tester.newFormTester("form");
>>>> formTester.select("combo1", 0);
>>>> tester.executeAjaxEvent("form:combo1", "onchange");
>>>> //formTester.select("combo1", 0);
>>>> formTester.submit();
>>>> tester.assertNoErrorMessage();
>>>> }
>>>> }
>>>>
>>>> wicket application class
>>>>
>>>> package com.sg2net.test;
>>>> import org.apache.wicket.Page;
>>>> import org.apache.wicket.protocol.http.WebApplication;
>>>>
>>>> import com.sg2net.test.TestAjaxDropDown;
>>>>
>>>>
>>>> public class WicketApplication extends WebApplication {
>>>>
>>>> @Override
>>>> public Class<? extends Page> getHomePage() {
>>>>
>>>> return TestAjaxDropDown.class;
>>>> }
>>>>
>>>> protected void init() {
>>>> getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
>>>> }
>>>>
>>>> }
>>>>
>>>>
>>>>
>>> --
>>> Giovanni Cuccu
>>> Responsabile area sviluppo - CUP 2000 Spa
>>> Via del Borgo di S. Pietro, 90/c - 40126 Bologna
>>> e-mail: giovanni.cuccu _at_ cup2000.it
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>
>>
>
--
Giovanni Cuccu
Responsabile area sviluppo - CUP 2000 Spa
Via del Borgo di S. Pietro, 90/c - 40126 Bologna
e-mail: giovanni.cuccu _at_ cup2000.it
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Unable to use wicket tester to simulate ajax behavior
Posted by Giovanni Cuccu <gi...@cup2000.it>.
Hi Martin,
I did the change you suggested but the test fails with esame error:
junit.framework.AssertionFailedError: expect no error message, but contains
Field 'combo1' is required.
Thanks,
Giovanni
Il 11/07/12 09.23, Martin Grigorov ha scritto:
> Hi,
>
> Try with:
>
> tester.getRequest().setParameter("form:combo1", "0");
> tester.executeAjaxEvent("form:combo1", "onchange");
>
> On Tue, Jul 10, 2012 at 10:10 AM, Giovanni Cuccu
> <gi...@cup2000.it> wrote:
>> Hi,
>> can someone give me an hint on this?
>> I tried to explain my problem providing a complete example and explaining
>> what I was trying to achieve.
>> I'd like to know if there is a specific reason of getting no answer so I can
>> change something on my side the next time I need to write to the list.
>> Thanks,
>> Giovanni
>> Il 05/07/12 08.10, Giovanni Cuccu ha scritto:
>>
>>> Hi all,
>>> I'm trying to test a wicket 1.5.7 application and I'm hitting a
>>> strange (at least for me) issue.
>>> I have two dropdowns (combo 1 and combo2) and when I select one value
>>> from combo1 I fire an AjaxUpdateBehavior on onchange event which selects
>>> a value on combo2.
>>> If I use the application everything is working as expected but If I try
>>> to simulate the application with wicket tester I come into trouble.
>>> Basically the test code is the following one:
>>>
>>> WicketTester tester= new WicketTester(new WicketApplication());
>>> tester.startPage(TestAjaxDropDown.class);
>>> FormTester formTester=tester.newFormTester("form");
>>> formTester.select("combo1", 0);
>>> tester.executeAjaxEvent("form:combo1", "onchange");
>>> formTester.submit();
>>> tester.assertNoErrorMessage();
>>>
>>> what I got is that after firing the onchange event combo1 gets a null
>>> value as object model and this does not happen when I use a browser. If
>>> I do not fire the event the application reports that combo2 has no
>>> element selected.
>>> Am I missing something or is it a bug?
>>>
>>> Grazie,
>>> Giovanni
>>>
>>> P.S. I built a simple test case that I insert here
>>>
>>> main page class
>>>
>>> package com.sg2net.test;
>>>
>>> import java.io.Serializable;
>>> import java.util.ArrayList;
>>> import java.util.List;
>>>
>>> import org.apache.wicket.ajax.AjaxRequestTarget;
>>> import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
>>> import org.apache.wicket.markup.html.WebPage;
>>> import org.apache.wicket.markup.html.form.ChoiceRenderer;
>>> import org.apache.wicket.markup.html.form.DropDownChoice;
>>> import org.apache.wicket.markup.html.form.Form;
>>> import org.apache.wicket.markup.html.panel.FeedbackPanel;
>>> import org.apache.wicket.model.PropertyModel;
>>> import org.slf4j.Logger;
>>> import org.slf4j.LoggerFactory;
>>>
>>>
>>> public class TestAjaxDropDown extends WebPage {
>>>
>>> private static final Logger
>>> logger=LoggerFactory.getLogger(TestAjaxDropDown.class.getName());
>>>
>>> public TestAjaxDropDown() {
>>> add(new FeedbackPanel("feedback"));
>>> add(new TestAjaxDropDownFrom("form"));
>>> }
>>>
>>> private class DomainObject1 implements Serializable {
>>> public DomainObject1(long id, String description) {
>>> super();
>>> this.id = id;
>>> this.description = description;
>>> }
>>> private static final long serialVersionUID = 1L;
>>> private long id;
>>> private String description;
>>>
>>> public long getId() {
>>> return id;
>>> }
>>> public void setId(long id) {
>>> this.id = id;
>>> }
>>> public String getDescription() {
>>> return description;
>>> }
>>> public void setDescription(String description) {
>>> this.description = description;
>>> }
>>> @Override
>>> public int hashCode() {
>>> final int prime = 31;
>>> int result = 1;
>>> result = prime * result + getOuterType().hashCode();
>>> result = prime * result + (int) (id ^ (id >>> 32));
>>> return result;
>>> }
>>> @Override
>>> public boolean equals(Object obj) {
>>> if (this == obj)
>>> return true;
>>> if (obj == null)
>>> return false;
>>> if (getClass() != obj.getClass())
>>> return false;
>>> DomainObject1 other = (DomainObject1) obj;
>>> if (!getOuterType().equals(other.getOuterType()))
>>> return false;
>>> if (id != other.id)
>>> return false;
>>> return true;
>>> }
>>> private TestAjaxDropDown getOuterType() {
>>> return TestAjaxDropDown.this;
>>> }
>>>
>>> }
>>>
>>> private class DomainObject2 implements Serializable {
>>> public DomainObject2(long id, String description) {
>>> super();
>>> this.id = id;
>>> this.description = description;
>>> }
>>> private static final long serialVersionUID = 1L;
>>> private long id;
>>> private String description;
>>>
>>> public long getId() {
>>> return id;
>>> }
>>> public void setId(long id) {
>>> this.id = id;
>>> }
>>> public String getDescription() {
>>> return description;
>>> }
>>> public void setDescription(String description) {
>>> this.description = description;
>>> }
>>> @Override
>>> public int hashCode() {
>>> final int prime = 31;
>>> int result = 1;
>>> result = prime * result + getOuterType().hashCode();
>>> result = prime * result + (int) (id ^ (id >>> 32));
>>> return result;
>>> }
>>> @Override
>>> public boolean equals(Object obj) {
>>> if (this == obj)
>>> return true;
>>> if (obj == null)
>>> return false;
>>> if (getClass() != obj.getClass())
>>> return false;
>>> DomainObject2 other = (DomainObject2) obj;
>>> if (!getOuterType().equals(other.getOuterType()))
>>> return false;
>>> if (id != other.id)
>>> return false;
>>> return true;
>>> }
>>> private TestAjaxDropDown getOuterType() {
>>> return TestAjaxDropDown.this;
>>> }
>>>
>>> }
>>>
>>> private static final long serialVersionUID = 1L;
>>>
>>> private class TestAjaxDropDownFrom extends Form<Void> {
>>>
>>> private static final long serialVersionUID = 1L;
>>> private DomainObject1 domainObject1;
>>> private DomainObject2 domainObject2;
>>> private DropDownChoice<DomainObject2> secondCombo;
>>>
>>> public TestAjaxDropDownFrom(String id) {
>>> super(id);
>>> List<DomainObject1> choicesForCombo1= new
>>> ArrayList<DomainObject1>();
>>> choicesForCombo1.add(new DomainObject1(1L,"uno"));
>>> choicesForCombo1.add(new DomainObject1(2L,"due"));
>>> choicesForCombo1.add(new DomainObject1(3L,"tre"));
>>> DropDownChoice<DomainObject1> firstCombo= new
>>> DropDownChoice<DomainObject1>("combo1",
>>> new
>>> PropertyModel<DomainObject1>(this,"domainObject1"),choicesForCombo1,
>>> new ChoiceRenderer<DomainObject1>("description",
>>> "id"));
>>> firstCombo.setRequired(true);
>>> firstCombo.setNullValid(true);
>>> firstCombo.add(new AjaxUpdateBehavior("onchange"));
>>> add(firstCombo);
>>>
>>> List<DomainObject2> choicesForCombo2= new
>>> ArrayList<DomainObject2>();
>>> choicesForCombo2.add(new DomainObject2(10L,"unozero"));
>>> choicesForCombo2.add(new DomainObject2(20L,"duezero"));
>>> choicesForCombo2.add(new DomainObject2(30L,"trezero"));
>>> secondCombo= new DropDownChoice<DomainObject2>("combo2",
>>> new
>>> PropertyModel<DomainObject2>(this,"domainObject2"),choicesForCombo2,
>>> new ChoiceRenderer<DomainObject2>("description",
>>> "id"));
>>> secondCombo.setOutputMarkupId(true);
>>> secondCombo.setNullValid(true);
>>> add(secondCombo);
>>>
>>> }
>>>
>>> @Override
>>> public void onSubmit() {
>>> if (domainObject2==null) {
>>> error("Domain object2 is null");
>>> } else {
>>> info("OK");
>>> }
>>> }
>>>
>>> private class AjaxUpdateBehavior extends
>>> AjaxFormComponentUpdatingBehavior {
>>>
>>>
>>> private static final long serialVersionUID = 1L;
>>>
>>> public AjaxUpdateBehavior(String event) {
>>> super(event);
>>> }
>>>
>>> @Override
>>> protected void onUpdate(AjaxRequestTarget target) {
>>> if (domainObject1!=null) {
>>> logger.warn("domainObject1.getId()=" +
>>> domainObject1.getId());
>>> if (domainObject1.getId()==1L) {
>>> domainObject2=new DomainObject2(10L,"unozero");
>>> logger.warn("domainObject2.getId()=" +
>>> domainObject2.getId());
>>> }
>>> if (domainObject1.getId()==2L) {
>>> domainObject2=new DomainObject2(20L,"duezero");
>>> logger.warn("domainObject2.getId()=" +
>>> domainObject2.getId());
>>> }
>>> if (domainObject1.getId()==3L) {
>>> domainObject2=new DomainObject2(30L,"trezero");
>>> logger.warn("domainObject2.getId()=" +
>>> domainObject2.getId());
>>> }
>>> secondCombo.modelChanged();
>>> target.add(secondCombo);
>>> } else {
>>> logger.warn("domainObject1==null");
>>> }
>>> }
>>> }
>>>
>>> }
>>> }
>>>
>>> test class
>>>
>>> package com.sg2net.test;
>>>
>>> import org.apache.wicket.util.tester.FormTester;
>>> import org.apache.wicket.util.tester.WicketTester;
>>> import org.testng.annotations.Test;
>>>
>>> public class WicketTesterAjaxDropDown {
>>> @Test
>>> public void testAjaxDropDown() {
>>> WicketTester tester= new WicketTester(new WicketApplication());
>>> tester.startPage(TestAjaxDropDown.class);
>>> FormTester formTester=tester.newFormTester("form");
>>> formTester.select("combo1", 0);
>>> tester.executeAjaxEvent("form:combo1", "onchange");
>>> //formTester.select("combo1", 0);
>>> formTester.submit();
>>> tester.assertNoErrorMessage();
>>> }
>>> }
>>>
>>> wicket application class
>>>
>>> package com.sg2net.test;
>>> import org.apache.wicket.Page;
>>> import org.apache.wicket.protocol.http.WebApplication;
>>>
>>> import com.sg2net.test.TestAjaxDropDown;
>>>
>>>
>>> public class WicketApplication extends WebApplication {
>>>
>>> @Override
>>> public Class<? extends Page> getHomePage() {
>>>
>>> return TestAjaxDropDown.class;
>>> }
>>>
>>> protected void init() {
>>> getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
>>> }
>>>
>>> }
>>>
>>>
>>>
>> --
>> Giovanni Cuccu
>> Responsabile area sviluppo - CUP 2000 Spa
>> Via del Borgo di S. Pietro, 90/c - 40126 Bologna
>> e-mail: giovanni.cuccu _at_ cup2000.it
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>
>
--
Giovanni Cuccu
Responsabile area sviluppo - CUP 2000 Spa
Via del Borgo di S. Pietro, 90/c - 40126 Bologna
e-mail: giovanni.cuccu _at_ cup2000.it
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Unable to use wicket tester to simulate ajax behavior
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
Try with:
tester.getRequest().setParameter("form:combo1", "0");
tester.executeAjaxEvent("form:combo1", "onchange");
On Tue, Jul 10, 2012 at 10:10 AM, Giovanni Cuccu
<gi...@cup2000.it> wrote:
> Hi,
> can someone give me an hint on this?
> I tried to explain my problem providing a complete example and explaining
> what I was trying to achieve.
> I'd like to know if there is a specific reason of getting no answer so I can
> change something on my side the next time I need to write to the list.
> Thanks,
> Giovanni
> Il 05/07/12 08.10, Giovanni Cuccu ha scritto:
>
>>
>> Hi all,
>> I'm trying to test a wicket 1.5.7 application and I'm hitting a
>> strange (at least for me) issue.
>> I have two dropdowns (combo 1 and combo2) and when I select one value
>> from combo1 I fire an AjaxUpdateBehavior on onchange event which selects
>> a value on combo2.
>> If I use the application everything is working as expected but If I try
>> to simulate the application with wicket tester I come into trouble.
>> Basically the test code is the following one:
>>
>> WicketTester tester= new WicketTester(new WicketApplication());
>> tester.startPage(TestAjaxDropDown.class);
>> FormTester formTester=tester.newFormTester("form");
>> formTester.select("combo1", 0);
>> tester.executeAjaxEvent("form:combo1", "onchange");
>> formTester.submit();
>> tester.assertNoErrorMessage();
>>
>> what I got is that after firing the onchange event combo1 gets a null
>> value as object model and this does not happen when I use a browser. If
>> I do not fire the event the application reports that combo2 has no
>> element selected.
>> Am I missing something or is it a bug?
>>
>> Grazie,
>> Giovanni
>>
>> P.S. I built a simple test case that I insert here
>>
>> main page class
>>
>> package com.sg2net.test;
>>
>> import java.io.Serializable;
>> import java.util.ArrayList;
>> import java.util.List;
>>
>> import org.apache.wicket.ajax.AjaxRequestTarget;
>> import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
>> import org.apache.wicket.markup.html.WebPage;
>> import org.apache.wicket.markup.html.form.ChoiceRenderer;
>> import org.apache.wicket.markup.html.form.DropDownChoice;
>> import org.apache.wicket.markup.html.form.Form;
>> import org.apache.wicket.markup.html.panel.FeedbackPanel;
>> import org.apache.wicket.model.PropertyModel;
>> import org.slf4j.Logger;
>> import org.slf4j.LoggerFactory;
>>
>>
>> public class TestAjaxDropDown extends WebPage {
>>
>> private static final Logger
>> logger=LoggerFactory.getLogger(TestAjaxDropDown.class.getName());
>>
>> public TestAjaxDropDown() {
>> add(new FeedbackPanel("feedback"));
>> add(new TestAjaxDropDownFrom("form"));
>> }
>>
>> private class DomainObject1 implements Serializable {
>> public DomainObject1(long id, String description) {
>> super();
>> this.id = id;
>> this.description = description;
>> }
>> private static final long serialVersionUID = 1L;
>> private long id;
>> private String description;
>>
>> public long getId() {
>> return id;
>> }
>> public void setId(long id) {
>> this.id = id;
>> }
>> public String getDescription() {
>> return description;
>> }
>> public void setDescription(String description) {
>> this.description = description;
>> }
>> @Override
>> public int hashCode() {
>> final int prime = 31;
>> int result = 1;
>> result = prime * result + getOuterType().hashCode();
>> result = prime * result + (int) (id ^ (id >>> 32));
>> return result;
>> }
>> @Override
>> public boolean equals(Object obj) {
>> if (this == obj)
>> return true;
>> if (obj == null)
>> return false;
>> if (getClass() != obj.getClass())
>> return false;
>> DomainObject1 other = (DomainObject1) obj;
>> if (!getOuterType().equals(other.getOuterType()))
>> return false;
>> if (id != other.id)
>> return false;
>> return true;
>> }
>> private TestAjaxDropDown getOuterType() {
>> return TestAjaxDropDown.this;
>> }
>>
>> }
>>
>> private class DomainObject2 implements Serializable {
>> public DomainObject2(long id, String description) {
>> super();
>> this.id = id;
>> this.description = description;
>> }
>> private static final long serialVersionUID = 1L;
>> private long id;
>> private String description;
>>
>> public long getId() {
>> return id;
>> }
>> public void setId(long id) {
>> this.id = id;
>> }
>> public String getDescription() {
>> return description;
>> }
>> public void setDescription(String description) {
>> this.description = description;
>> }
>> @Override
>> public int hashCode() {
>> final int prime = 31;
>> int result = 1;
>> result = prime * result + getOuterType().hashCode();
>> result = prime * result + (int) (id ^ (id >>> 32));
>> return result;
>> }
>> @Override
>> public boolean equals(Object obj) {
>> if (this == obj)
>> return true;
>> if (obj == null)
>> return false;
>> if (getClass() != obj.getClass())
>> return false;
>> DomainObject2 other = (DomainObject2) obj;
>> if (!getOuterType().equals(other.getOuterType()))
>> return false;
>> if (id != other.id)
>> return false;
>> return true;
>> }
>> private TestAjaxDropDown getOuterType() {
>> return TestAjaxDropDown.this;
>> }
>>
>> }
>>
>> private static final long serialVersionUID = 1L;
>>
>> private class TestAjaxDropDownFrom extends Form<Void> {
>>
>> private static final long serialVersionUID = 1L;
>> private DomainObject1 domainObject1;
>> private DomainObject2 domainObject2;
>> private DropDownChoice<DomainObject2> secondCombo;
>>
>> public TestAjaxDropDownFrom(String id) {
>> super(id);
>> List<DomainObject1> choicesForCombo1= new
>> ArrayList<DomainObject1>();
>> choicesForCombo1.add(new DomainObject1(1L,"uno"));
>> choicesForCombo1.add(new DomainObject1(2L,"due"));
>> choicesForCombo1.add(new DomainObject1(3L,"tre"));
>> DropDownChoice<DomainObject1> firstCombo= new
>> DropDownChoice<DomainObject1>("combo1",
>> new
>> PropertyModel<DomainObject1>(this,"domainObject1"),choicesForCombo1,
>> new ChoiceRenderer<DomainObject1>("description",
>> "id"));
>> firstCombo.setRequired(true);
>> firstCombo.setNullValid(true);
>> firstCombo.add(new AjaxUpdateBehavior("onchange"));
>> add(firstCombo);
>>
>> List<DomainObject2> choicesForCombo2= new
>> ArrayList<DomainObject2>();
>> choicesForCombo2.add(new DomainObject2(10L,"unozero"));
>> choicesForCombo2.add(new DomainObject2(20L,"duezero"));
>> choicesForCombo2.add(new DomainObject2(30L,"trezero"));
>> secondCombo= new DropDownChoice<DomainObject2>("combo2",
>> new
>> PropertyModel<DomainObject2>(this,"domainObject2"),choicesForCombo2,
>> new ChoiceRenderer<DomainObject2>("description",
>> "id"));
>> secondCombo.setOutputMarkupId(true);
>> secondCombo.setNullValid(true);
>> add(secondCombo);
>>
>> }
>>
>> @Override
>> public void onSubmit() {
>> if (domainObject2==null) {
>> error("Domain object2 is null");
>> } else {
>> info("OK");
>> }
>> }
>>
>> private class AjaxUpdateBehavior extends
>> AjaxFormComponentUpdatingBehavior {
>>
>>
>> private static final long serialVersionUID = 1L;
>>
>> public AjaxUpdateBehavior(String event) {
>> super(event);
>> }
>>
>> @Override
>> protected void onUpdate(AjaxRequestTarget target) {
>> if (domainObject1!=null) {
>> logger.warn("domainObject1.getId()=" +
>> domainObject1.getId());
>> if (domainObject1.getId()==1L) {
>> domainObject2=new DomainObject2(10L,"unozero");
>> logger.warn("domainObject2.getId()=" +
>> domainObject2.getId());
>> }
>> if (domainObject1.getId()==2L) {
>> domainObject2=new DomainObject2(20L,"duezero");
>> logger.warn("domainObject2.getId()=" +
>> domainObject2.getId());
>> }
>> if (domainObject1.getId()==3L) {
>> domainObject2=new DomainObject2(30L,"trezero");
>> logger.warn("domainObject2.getId()=" +
>> domainObject2.getId());
>> }
>> secondCombo.modelChanged();
>> target.add(secondCombo);
>> } else {
>> logger.warn("domainObject1==null");
>> }
>> }
>> }
>>
>> }
>> }
>>
>> test class
>>
>> package com.sg2net.test;
>>
>> import org.apache.wicket.util.tester.FormTester;
>> import org.apache.wicket.util.tester.WicketTester;
>> import org.testng.annotations.Test;
>>
>> public class WicketTesterAjaxDropDown {
>> @Test
>> public void testAjaxDropDown() {
>> WicketTester tester= new WicketTester(new WicketApplication());
>> tester.startPage(TestAjaxDropDown.class);
>> FormTester formTester=tester.newFormTester("form");
>> formTester.select("combo1", 0);
>> tester.executeAjaxEvent("form:combo1", "onchange");
>> //formTester.select("combo1", 0);
>> formTester.submit();
>> tester.assertNoErrorMessage();
>> }
>> }
>>
>> wicket application class
>>
>> package com.sg2net.test;
>> import org.apache.wicket.Page;
>> import org.apache.wicket.protocol.http.WebApplication;
>>
>> import com.sg2net.test.TestAjaxDropDown;
>>
>>
>> public class WicketApplication extends WebApplication {
>>
>> @Override
>> public Class<? extends Page> getHomePage() {
>>
>> return TestAjaxDropDown.class;
>> }
>>
>> protected void init() {
>> getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
>> }
>>
>> }
>>
>>
>>
>
> --
> Giovanni Cuccu
> Responsabile area sviluppo - CUP 2000 Spa
> Via del Borgo di S. Pietro, 90/c - 40126 Bologna
> e-mail: giovanni.cuccu _at_ cup2000.it
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Unable to use wicket tester to simulate ajax behavior
Posted by Giovanni Cuccu <gi...@cup2000.it>.
Hi,
can someone give me an hint on this?
I tried to explain my problem providing a complete example and
explaining what I was trying to achieve.
I'd like to know if there is a specific reason of getting no answer so I
can change something on my side the next time I need to write to the list.
Thanks,
Giovanni
Il 05/07/12 08.10, Giovanni Cuccu ha scritto:
>
> Hi all,
> I'm trying to test a wicket 1.5.7 application and I'm hitting a
> strange (at least for me) issue.
> I have two dropdowns (combo 1 and combo2) and when I select one value
> from combo1 I fire an AjaxUpdateBehavior on onchange event which selects
> a value on combo2.
> If I use the application everything is working as expected but If I try
> to simulate the application with wicket tester I come into trouble.
> Basically the test code is the following one:
>
> WicketTester tester= new WicketTester(new WicketApplication());
> tester.startPage(TestAjaxDropDown.class);
> FormTester formTester=tester.newFormTester("form");
> formTester.select("combo1", 0);
> tester.executeAjaxEvent("form:combo1", "onchange");
> formTester.submit();
> tester.assertNoErrorMessage();
>
> what I got is that after firing the onchange event combo1 gets a null
> value as object model and this does not happen when I use a browser. If
> I do not fire the event the application reports that combo2 has no
> element selected.
> Am I missing something or is it a bug?
>
> Grazie,
> Giovanni
>
> P.S. I built a simple test case that I insert here
>
> main page class
>
> package com.sg2net.test;
>
> import java.io.Serializable;
> import java.util.ArrayList;
> import java.util.List;
>
> import org.apache.wicket.ajax.AjaxRequestTarget;
> import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
> import org.apache.wicket.markup.html.WebPage;
> import org.apache.wicket.markup.html.form.ChoiceRenderer;
> import org.apache.wicket.markup.html.form.DropDownChoice;
> import org.apache.wicket.markup.html.form.Form;
> import org.apache.wicket.markup.html.panel.FeedbackPanel;
> import org.apache.wicket.model.PropertyModel;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
>
> public class TestAjaxDropDown extends WebPage {
>
> private static final Logger
> logger=LoggerFactory.getLogger(TestAjaxDropDown.class.getName());
>
> public TestAjaxDropDown() {
> add(new FeedbackPanel("feedback"));
> add(new TestAjaxDropDownFrom("form"));
> }
>
> private class DomainObject1 implements Serializable {
> public DomainObject1(long id, String description) {
> super();
> this.id = id;
> this.description = description;
> }
> private static final long serialVersionUID = 1L;
> private long id;
> private String description;
>
> public long getId() {
> return id;
> }
> public void setId(long id) {
> this.id = id;
> }
> public String getDescription() {
> return description;
> }
> public void setDescription(String description) {
> this.description = description;
> }
> @Override
> public int hashCode() {
> final int prime = 31;
> int result = 1;
> result = prime * result + getOuterType().hashCode();
> result = prime * result + (int) (id ^ (id >>> 32));
> return result;
> }
> @Override
> public boolean equals(Object obj) {
> if (this == obj)
> return true;
> if (obj == null)
> return false;
> if (getClass() != obj.getClass())
> return false;
> DomainObject1 other = (DomainObject1) obj;
> if (!getOuterType().equals(other.getOuterType()))
> return false;
> if (id != other.id)
> return false;
> return true;
> }
> private TestAjaxDropDown getOuterType() {
> return TestAjaxDropDown.this;
> }
>
> }
>
> private class DomainObject2 implements Serializable {
> public DomainObject2(long id, String description) {
> super();
> this.id = id;
> this.description = description;
> }
> private static final long serialVersionUID = 1L;
> private long id;
> private String description;
>
> public long getId() {
> return id;
> }
> public void setId(long id) {
> this.id = id;
> }
> public String getDescription() {
> return description;
> }
> public void setDescription(String description) {
> this.description = description;
> }
> @Override
> public int hashCode() {
> final int prime = 31;
> int result = 1;
> result = prime * result + getOuterType().hashCode();
> result = prime * result + (int) (id ^ (id >>> 32));
> return result;
> }
> @Override
> public boolean equals(Object obj) {
> if (this == obj)
> return true;
> if (obj == null)
> return false;
> if (getClass() != obj.getClass())
> return false;
> DomainObject2 other = (DomainObject2) obj;
> if (!getOuterType().equals(other.getOuterType()))
> return false;
> if (id != other.id)
> return false;
> return true;
> }
> private TestAjaxDropDown getOuterType() {
> return TestAjaxDropDown.this;
> }
>
> }
>
> private static final long serialVersionUID = 1L;
>
> private class TestAjaxDropDownFrom extends Form<Void> {
>
> private static final long serialVersionUID = 1L;
> private DomainObject1 domainObject1;
> private DomainObject2 domainObject2;
> private DropDownChoice<DomainObject2> secondCombo;
>
> public TestAjaxDropDownFrom(String id) {
> super(id);
> List<DomainObject1> choicesForCombo1= new
> ArrayList<DomainObject1>();
> choicesForCombo1.add(new DomainObject1(1L,"uno"));
> choicesForCombo1.add(new DomainObject1(2L,"due"));
> choicesForCombo1.add(new DomainObject1(3L,"tre"));
> DropDownChoice<DomainObject1> firstCombo= new
> DropDownChoice<DomainObject1>("combo1",
> new
> PropertyModel<DomainObject1>(this,"domainObject1"),choicesForCombo1,
> new ChoiceRenderer<DomainObject1>("description",
> "id"));
> firstCombo.setRequired(true);
> firstCombo.setNullValid(true);
> firstCombo.add(new AjaxUpdateBehavior("onchange"));
> add(firstCombo);
>
> List<DomainObject2> choicesForCombo2= new
> ArrayList<DomainObject2>();
> choicesForCombo2.add(new DomainObject2(10L,"unozero"));
> choicesForCombo2.add(new DomainObject2(20L,"duezero"));
> choicesForCombo2.add(new DomainObject2(30L,"trezero"));
> secondCombo= new DropDownChoice<DomainObject2>("combo2",
> new
> PropertyModel<DomainObject2>(this,"domainObject2"),choicesForCombo2,
> new ChoiceRenderer<DomainObject2>("description",
> "id"));
> secondCombo.setOutputMarkupId(true);
> secondCombo.setNullValid(true);
> add(secondCombo);
>
> }
>
> @Override
> public void onSubmit() {
> if (domainObject2==null) {
> error("Domain object2 is null");
> } else {
> info("OK");
> }
> }
>
> private class AjaxUpdateBehavior extends
> AjaxFormComponentUpdatingBehavior {
>
>
> private static final long serialVersionUID = 1L;
>
> public AjaxUpdateBehavior(String event) {
> super(event);
> }
>
> @Override
> protected void onUpdate(AjaxRequestTarget target) {
> if (domainObject1!=null) {
> logger.warn("domainObject1.getId()=" +
> domainObject1.getId());
> if (domainObject1.getId()==1L) {
> domainObject2=new DomainObject2(10L,"unozero");
> logger.warn("domainObject2.getId()=" +
> domainObject2.getId());
> }
> if (domainObject1.getId()==2L) {
> domainObject2=new DomainObject2(20L,"duezero");
> logger.warn("domainObject2.getId()=" +
> domainObject2.getId());
> }
> if (domainObject1.getId()==3L) {
> domainObject2=new DomainObject2(30L,"trezero");
> logger.warn("domainObject2.getId()=" +
> domainObject2.getId());
> }
> secondCombo.modelChanged();
> target.add(secondCombo);
> } else {
> logger.warn("domainObject1==null");
> }
> }
> }
>
> }
> }
>
> test class
>
> package com.sg2net.test;
>
> import org.apache.wicket.util.tester.FormTester;
> import org.apache.wicket.util.tester.WicketTester;
> import org.testng.annotations.Test;
>
> public class WicketTesterAjaxDropDown {
> @Test
> public void testAjaxDropDown() {
> WicketTester tester= new WicketTester(new WicketApplication());
> tester.startPage(TestAjaxDropDown.class);
> FormTester formTester=tester.newFormTester("form");
> formTester.select("combo1", 0);
> tester.executeAjaxEvent("form:combo1", "onchange");
> //formTester.select("combo1", 0);
> formTester.submit();
> tester.assertNoErrorMessage();
> }
> }
>
> wicket application class
>
> package com.sg2net.test;
> import org.apache.wicket.Page;
> import org.apache.wicket.protocol.http.WebApplication;
>
> import com.sg2net.test.TestAjaxDropDown;
>
>
> public class WicketApplication extends WebApplication {
>
> @Override
> public Class<? extends Page> getHomePage() {
>
> return TestAjaxDropDown.class;
> }
>
> protected void init() {
> getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
> }
>
> }
>
>
>
--
Giovanni Cuccu
Responsabile area sviluppo - CUP 2000 Spa
Via del Borgo di S. Pietro, 90/c - 40126 Bologna
e-mail: giovanni.cuccu _at_ cup2000.it
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Unable to use wicket tester to simulate ajax behavior
Posted by Giovanni Cuccu <gi...@cup2000.it>.
Hi all,
I'm trying to test a wicket 1.5.7 application and I'm hitting a
strange (at least for me) issue.
I have two dropdowns (combo 1 and combo2) and when I select one value
from combo1 I fire an AjaxUpdateBehavior on onchange event which selects
a value on combo2.
If I use the application everything is working as expected but If I try
to simulate the application with wicket tester I come into trouble.
Basically the test code is the following one:
WicketTester tester= new WicketTester(new WicketApplication());
tester.startPage(TestAjaxDropDown.class);
FormTester formTester=tester.newFormTester("form");
formTester.select("combo1", 0);
tester.executeAjaxEvent("form:combo1", "onchange");
formTester.submit();
tester.assertNoErrorMessage();
what I got is that after firing the onchange event combo1 gets a null
value as object model and this does not happen when I use a browser. If
I do not fire the event the application reports that combo2 has no
element selected.
Am I missing something or is it a bug?
Grazie,
Giovanni
P.S. I built a simple test case that I insert here
main page class
package com.sg2net.test;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.PropertyModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestAjaxDropDown extends WebPage {
private static final Logger
logger=LoggerFactory.getLogger(TestAjaxDropDown.class.getName());
public TestAjaxDropDown() {
add(new FeedbackPanel("feedback"));
add(new TestAjaxDropDownFrom("form"));
}
private class DomainObject1 implements Serializable {
public DomainObject1(long id, String description) {
super();
this.id = id;
this.description = description;
}
private static final long serialVersionUID = 1L;
private long id;
private String description;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + getOuterType().hashCode();
result = prime * result + (int) (id ^ (id >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
DomainObject1 other = (DomainObject1) obj;
if (!getOuterType().equals(other.getOuterType()))
return false;
if (id != other.id)
return false;
return true;
}
private TestAjaxDropDown getOuterType() {
return TestAjaxDropDown.this;
}
}
private class DomainObject2 implements Serializable {
public DomainObject2(long id, String description) {
super();
this.id = id;
this.description = description;
}
private static final long serialVersionUID = 1L;
private long id;
private String description;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + getOuterType().hashCode();
result = prime * result + (int) (id ^ (id >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
DomainObject2 other = (DomainObject2) obj;
if (!getOuterType().equals(other.getOuterType()))
return false;
if (id != other.id)
return false;
return true;
}
private TestAjaxDropDown getOuterType() {
return TestAjaxDropDown.this;
}
}
private static final long serialVersionUID = 1L;
private class TestAjaxDropDownFrom extends Form<Void> {
private static final long serialVersionUID = 1L;
private DomainObject1 domainObject1;
private DomainObject2 domainObject2;
private DropDownChoice<DomainObject2> secondCombo;
public TestAjaxDropDownFrom(String id) {
super(id);
List<DomainObject1> choicesForCombo1= new
ArrayList<DomainObject1>();
choicesForCombo1.add(new DomainObject1(1L,"uno"));
choicesForCombo1.add(new DomainObject1(2L,"due"));
choicesForCombo1.add(new DomainObject1(3L,"tre"));
DropDownChoice<DomainObject1> firstCombo= new
DropDownChoice<DomainObject1>("combo1",
new
PropertyModel<DomainObject1>(this,"domainObject1"),choicesForCombo1,
new ChoiceRenderer<DomainObject1>("description",
"id"));
firstCombo.setRequired(true);
firstCombo.setNullValid(true);
firstCombo.add(new AjaxUpdateBehavior("onchange"));
add(firstCombo);
List<DomainObject2> choicesForCombo2= new
ArrayList<DomainObject2>();
choicesForCombo2.add(new DomainObject2(10L,"unozero"));
choicesForCombo2.add(new DomainObject2(20L,"duezero"));
choicesForCombo2.add(new DomainObject2(30L,"trezero"));
secondCombo= new DropDownChoice<DomainObject2>("combo2",
new
PropertyModel<DomainObject2>(this,"domainObject2"),choicesForCombo2,
new ChoiceRenderer<DomainObject2>("description",
"id"));
secondCombo.setOutputMarkupId(true);
secondCombo.setNullValid(true);
add(secondCombo);
}
@Override
public void onSubmit() {
if (domainObject2==null) {
error("Domain object2 is null");
} else {
info("OK");
}
}
private class AjaxUpdateBehavior extends
AjaxFormComponentUpdatingBehavior {
private static final long serialVersionUID = 1L;
public AjaxUpdateBehavior(String event) {
super(event);
}
@Override
protected void onUpdate(AjaxRequestTarget target) {
if (domainObject1!=null) {
logger.warn("domainObject1.getId()=" +
domainObject1.getId());
if (domainObject1.getId()==1L) {
domainObject2=new DomainObject2(10L,"unozero");
logger.warn("domainObject2.getId()=" +
domainObject2.getId());
}
if (domainObject1.getId()==2L) {
domainObject2=new DomainObject2(20L,"duezero");
logger.warn("domainObject2.getId()=" +
domainObject2.getId());
}
if (domainObject1.getId()==3L) {
domainObject2=new DomainObject2(30L,"trezero");
logger.warn("domainObject2.getId()=" +
domainObject2.getId());
}
secondCombo.modelChanged();
target.add(secondCombo);
} else {
logger.warn("domainObject1==null");
}
}
}
}
}
test class
package com.sg2net.test;
import org.apache.wicket.util.tester.FormTester;
import org.apache.wicket.util.tester.WicketTester;
import org.testng.annotations.Test;
public class WicketTesterAjaxDropDown {
@Test
public void testAjaxDropDown() {
WicketTester tester= new WicketTester(new WicketApplication());
tester.startPage(TestAjaxDropDown.class);
FormTester formTester=tester.newFormTester("form");
formTester.select("combo1", 0);
tester.executeAjaxEvent("form:combo1", "onchange");
//formTester.select("combo1", 0);
formTester.submit();
tester.assertNoErrorMessage();
}
}
wicket application class
package com.sg2net.test;
import org.apache.wicket.Page;
import org.apache.wicket.protocol.http.WebApplication;
import com.sg2net.test.TestAjaxDropDown;
public class WicketApplication extends WebApplication {
@Override
public Class<? extends Page> getHomePage() {
return TestAjaxDropDown.class;
}
protected void init() {
getMarkupSettings().setDefaultMarkupEncoding("UTF-8");
}
}
--
Giovanni Cuccu
Responsabile area sviluppo - CUP 2000 Spa
Via del Borgo di S. Pietro, 90/c - 40126 Bologna
e-mail: giovanni.cuccu _at_ cup2000.it
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: image from outside web application directory
Posted by Martin Grigorov <mg...@apache.org>.
The blog article I gave you url to explains exactly this use case.
Mount a resource that reads the image name from the request's
path/parameters, loads it from external store and delivers it back to
the client.
On Thu, Jul 5, 2012 at 3:15 PM, lang <de...@telfort.nl> wrote:
> Martin could you give me an example of this?
> I my website i want to upload jpgt pictures from clients. I already store
> them on another location but i can't show the pictures on my website
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/image-from-outside-web-application-directory-tp4650379p4650392.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
>
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: image from outside web application directory
Posted by lang <de...@telfort.nl>.
Martin could you give me an example of this?
I my website i want to upload jpgt pictures from clients. I already store
them on another location but i can't show the pictures on my website
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/image-from-outside-web-application-directory-tp4650379p4650392.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: image from outside web application directory
Posted by Scott Swank <sc...@gmail.com>.
This is what I've done.
https://cwiki.apache.org/WICKET/how-to-load-an-external-image.html
Scott
On Thu, Jul 5, 2012 at 6:18 AM, lang <de...@telfort.nl> wrote:
> Martin could you give me an example of this?
> I my website i want to upload jpgt pictures from clients. I already store
> them on another location but i can't show the pictures on my website
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/image-from-outside-web-application-directory-tp4650379p4650393.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: image from outside web application directory
Posted by lang <de...@telfort.nl>.
Martin could you give me an example of this?
I my website i want to upload jpgt pictures from clients. I already store
them on another location but i can't show the pictures on my website
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/image-from-outside-web-application-directory-tp4650379p4650393.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: image from outside web application directory
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
Read this: http://wicketinaction.com/2011/07/wicket-1-5-mounting-resources/
On Thu, Jul 5, 2012 at 12:49 AM, lang <de...@telfort.nl> wrote:
> I need to show images from c:/pictures on my website. I searched and searched
> and there should be something on old.nabble but that link is giving null
> pointer results. Who can help?
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/image-from-outside-web-application-directory-tp4650379.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
>
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: image from outside web application directory
Posted by Giovanni Cuccu <gi...@cup2000.it>.
Hi,
it's not wicket related but if you are using tomcat as application
server you can use the aliases attribute of the context (
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html) which
allows you to map an external (to your web app) dir to an url (es
c:/images on filesystem as /images in the url)
ciao,
Giovanni
Il 05/07/12 00.49, lang ha scritto:
> I need to show images from c:/pictures on my website. I searched and searched
> and there should be something on old.nabble but that link is giving null
> pointer results. Who can help?
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/image-from-outside-web-application-directory-tp4650379.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
>
>
>
--
Giovanni Cuccu
Responsabile area sviluppo - CUP 2000 Spa
Via del Borgo di S. Pietro, 90/c - 40126 Bologna
e-mail: giovanni.cuccu _at_ cup2000.it