I have AjaxLink which works good in Wicket 1.3.2 but doens't work whe i
change version to 1.3.3.

package pl.mainseek.car.wicket.components;

import java.util.Arrays;
import java.util.List;

import org.apache.wicket.PageParameters;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.markup.html.form.RequiredTextField;
import org.apache.wicket.markup.html.form.StatelessForm;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;

import pl.mainseek.car.dao.CarsDAO;
import pl.mainseek.car.entities.CarModel;
import pl.mainseek.car.entities.CarPart.Condition;
import pl.mainseek.car.wicket.CommonWebPage;
import pl.mainseek.car.wicket.models.SearchCarPartsModel;
import pl.mainseek.car.wicket.pages.AdvertismentsList;
import pl.mainseek.forum.wicket.pages.ForumList;

public class SearchPanel extends Panel {

    public static final String FORUM_OPTION = "forum";
    public static final String ADS_OPTION = "ads";

    @SpringBean
    private CarsDAO carsDAO;

    //keys
    private static final String ADVANCED_SEARCH_BUTTON_KEY =
"advanced.search.button";

    //wicket:ids
    public static final String SEARCH_FORM = "search_form";
    public static final String CONDITION = "condition";
    public static final String CAR_MODEL = "carModel";
    public static final String CAR_MARK = "carMark";
    public static final String QUERY = "query";
    public static final String ADVANCED_SEARCH = "advanced_search";
    public static final String SEARCH_BUTTON = "search_button";
    public static final String SEARCH_WHERE = "searchWhere";

    private final DropDownChoice searchWhereDDC, carMarkDDC, carModelDDC,
conditionDDC;
    private final RequiredTextField queryField;

    private final String[] searchWhereKeys = new String[] {ADS_OPTION,
FORUM_OPTION};

    //model
    private SearchCarPartsModel carPartsModel;

    public SearchPanel(String id, SearchCarPartsModel model) {
        super(id);
        this.carPartsModel = model;
        final Form searchForm = new StatelessForm(SEARCH_FORM, new
CompoundPropertyModel(carPartsModel)) {
            @Override
            protected void onSubmit() {
                super.onSubmit();
                setRedirect(true);
                PageParameters pageParameters = new PageParameters();
                pageParameters.add("query", carPartsModel.getQuery());
                if(carPartsModel.getCarModel() != null) {
                    pageParameters.add("carModel",
String.valueOf(carPartsModel.getCarModel().getId()));
                } else if(carPartsModel.getCarMark() != null) {
                    pageParameters.add("carMark",
String.valueOf(carPartsModel.getCarMark().getId()));
                }
                if(carPartsModel.getSearchWhere().equals(ADS_OPTION)) {
                    if(carPartsModel.getCondition() != null) {
                        pageParameters.add("condition",
carPartsModel.getCondition().toString().toLowerCase());
                    }
                    setResponsePage(AdvertismentsList.class,
pageParameters);
                } else
if(carPartsModel.getSearchWhere().equals(FORUM_OPTION)) {
                    setResponsePage(ForumList.class, pageParameters);
                }
            }
        };
        searchForm.setOutputMarkupId(true);
        queryField = new RequiredTextField(QUERY);
        searchWhereDDC = getSearchWhereDDC(searchForm);
        conditionDDC = getConditionDDC(searchForm);
        List<CarModel> carModels =
carsDAO.getCarModels(carPartsModel.getCarMark());
        carModelDDC = getCarModelDDC(carModels);
        carMarkDDC = getCarMarkDDC(carModels);
        carMarkDDC.setVisible(false);
        carModelDDC.setVisible(false);
        conditionDDC.setVisible(false);

        searchForm.add(queryField);
        searchForm.add(searchWhereDDC);
        searchForm.add(conditionDDC);
        searchForm.add(carMarkDDC);
        searchForm.add(carModelDDC);
        final AjaxLink advancedSearch = new AjaxLink(ADVANCED_SEARCH) {
            @Override public void onClick(AjaxRequestTarget target) {
                carMarkDDC.setVisible(!carMarkDDC.isVisible());
                carModelDDC.setVisible(!carModelDDC.isVisible());
                conditionDDC.setVisible(!carModelDDC.isVisible());
                if(carMarkDDC.isVisible()){
                    carMarkDDC.setChoices(carsDAO.getAllCarMarks());
                }
                target.addComponent(searchForm);
            }
        };
        searchForm.add(advancedSearch);
        searchForm.add(new Button(SEARCH_BUTTON, new
Model(getString(ADVANCED_SEARCH_BUTTON_KEY))));
        add(searchForm);
    }

    private DropDownChoice getSearchWhereDDC(final Form form) {
        DropDownChoice _searchWhereDDC = new DropDownChoice(SEARCH_WHERE,
Arrays.asList(searchWhereKeys));
        _searchWhereDDC.setNullValid(false);
        _searchWhereDDC.setChoiceRenderer(new IChoiceRenderer() {
            public Object getDisplayValue(Object o) {
                String searchOpt = (String) o;
                return getString("searchWhere." + searchOpt);
            }

            public String getIdValue(Object o, int i) {
                String searchOpt = (String) o;
                return searchOpt;
            }
        });
        _searchWhereDDC.add(new
AjaxFormComponentUpdatingBehavior(CommonWebPage.ONCHANGE_BEHAVIOR) {
            protected void onUpdate(AjaxRequestTarget target) {
                if(carPartsModel.getSearchWhere().equals(ADS_OPTION)) {
                    conditionDDC.setVisible(true);
                } else {
                    conditionDDC.setVisible(false);
                }
                if(carMarkDDC.isVisible()) {
                    target.addComponent(form);
                }
            }
        });
        return _searchWhereDDC;
    }

    private DropDownChoice getConditionDDC(Form form) {
        DropDownChoice _conditionDDC = new DropDownChoice(CONDITION,
Arrays.asList(Condition.values())) {
            @Override
            public boolean isVisible() {
                return carMarkDDC.isVisible() &&
carPartsModel.getSearchWhere().equals(ADS_OPTION);
            }
        };
        _conditionDDC.setChoiceRenderer(new IChoiceRenderer() {
            public Object getDisplayValue(Object o) {
                Condition condition = (Condition) o;
                return getString(Condition.getKey(condition));
            }

            public String getIdValue(Object o, int i) {
                Condition condition = (Condition) o;
                return condition.toString();
            }
        });
        return _conditionDDC;
    }

    private DropDownChoice getCarMarkDDC(final List<CarModel> carModels) {
        return new CarMarkDDC(CAR_MARK, carPartsModel, carsDAO, carModels,
carModelDDC);
    }

    @SuppressWarnings("unchecked")
    private DropDownChoice getCarModelDDC(final List<CarModel> carModels) {
        return new CarModelDDC(CAR_MODEL, carPartsModel.getCarMark(),
carModels);
    }
}




<html>
    <wicket:head>
          <link rel="stylesheet" type="text/css" href="/css/search.css">
    </wicket:head>
    <body>
        <wicket:panel>
            <form wicket:id="search_form">
                <div class="headerNav">
                    <div class="lft">
                        <div class="rgt">
                            <img src="/img/logo.gif" class="floatL"
alt="kfz.pl" />
                            <div class="posSearch">
                                <div class="floatL">
                                    <input type="text" wicket:id="query" />
                                    <select wicket:id="searchWhere">[search
where]</select>
                                </div>
                                <button class="btn btn_b" type="submit"
wicket:id="search_button" ><font><span><wicket:message
key="search_form.button"/></span></font></button>
                                <a class="advanced"
wicket:id="advanced_search"><wicket:message key="advanced.search.link"/></a>
                            </div>
                        </div>
                    </div>
                </div>
                <wicket:enclosure child="carMark">
                    <div class="hoverSearch">
                        <div class="boxSearch oo">
                            <div class="txtSel mt10">
                                <div><wicket:message
key="advanced.search.condition"/></div>
                                <div><wicket:message
key="advanced.search.mark"/></div>
                                <div><wicket:message
key="advanced.search.model"/></div>
                            </div>
                            <div class="selct mt10">
                                <select
wicket:id="condition">[condition]</select>
                                <select
wicket:id="carMark">[carMark]</select>
                                <select
wicket:id="carModel">[carModel]</select>
                            </div>
                        </div>
                        <div class="shadow"><div class="lft"><div
class="rgt"></div></div></div>
                    </div>
                </wicket:enclosure>
            </form>
        </wicket:panel>
    </body>
</html>

Wicket Ajax Debug:
*INFO: *focus removed from
*INFO: *focus set on advanced__search4
*INFO: *
*INFO: *
Initiating Ajax GET request on
../../?wicket:interface=:0:2:::0:2&random=0.3031798307043151
*INFO: *Invoking pre-call handler(s)...
*INFO: *Received ajax response (2159 characters)
*INFO: *
<?xml version="1.0"
encoding="UTF-8"?><ajax-response><header-contribution
encoding="wicket1" ><![CDATA[<head xmlns:wicket="
http://wicket.apache.org";><script type="text/javascript"
src="../../resources/org.apache.wicket.markup.html.WicketEventReference/wicket-event.js"></script>

<script type="text/javascript"
src="../../resources/org.apache.wicket.ajax.WicketAjaxReference/wicket-ajax.js"></script>

<script type="text/javascript"
src="../../resources/org.apache.wicket.ajax.AbstractDefaultAjaxBehavior/wicket-ajax-debug.js"></script>

<script type="text/javascript"
id="wicket-ajax-debug-enable"><!--/*--><![CDATA[/*><!--*/
wicketAjaxDebugEnable=true;
/*-->]^]^>*/</script>

</head>]]></header-contribution><component id="search__form1"
><![CDATA[<form id="search__form1"
action="../../page/HomePage/wicket:interface/%3A0%3Asearch_panel%3Asearch_form%3A%3AIFormSubmitListener%3A%3A/"
method="post"><div style="display:none"><input type="hidden"
name="search__form1_hf_0" id="search__form1_hf_0" /></div>

                <div class="headerNav">
                    <div class="lft">
                        <div class="rgt">
                            <img src="/img/logo.gif" class="floatL"
alt="kfz.pl" />

                            <div class="posSearch">
                                <div class="floatL">
                                    <input name="query" value="" type="text"/>

                                    <select id="searchWhere2"
name="searchWhere" onchange="var
wcall=wicketAjaxPost('../../?wicket:interface=:0:1:::0:2',
wicketSerialize(Wicket.$('searchWhere2')),null,null, function()
{return Wicket.$('searchWhere2') != null;}.bind(this));">
<option selected="selected" value="ads">w ogłoszeniach</option>
<option value="forum">w forum</option>
</select>
                                </div>
                                <button id="search__button3"
name="search_button" value="Szukaj" class="btn btn_b"
type="submit"><font><span>Szukaj</span></font></button>

                                <a id="advanced__search4" onclick="var
wcall=wicketAjaxGet('../../?wicket:interface=:0:2:::0:2',null,null,
function() {return Wicket.$('advanced__search4') !=
null;}.bind(this));return !wcall;" class="advanced" href="#">Szukanie
zaawansowane</a>

                            </div>
                        </div>
                    </div>
                </div>

            </form>]]></component></ajax-response>
*INFO: *Response parsed. Now invoking steps...
*INFO: *Response processed successfully.
*INFO: *Invoking post-call handler(s)...
*INFO: *Calling focus on advanced__search4
*INFO: *focus set on advanced__search4
*INFO: *focus removed from advanced__search4
*INFO: *focus set on advanced__search4
*INFO: *focus removed from advanced__search4

Reply via email to