Wicket AJAX表行添加不起作用

时间:2013-05-06 07:26:56

标签: java ajax wicket

我有一些代码,由其他人编写。情况是页面上有一个表,最初有一行。有一个添加行按钮,可以向表中添加一行。到目前为止它正在重新绘制整个页面,现在我已经将任务分配给Ajax-ify添加了行。但是,当我按下添加行按钮时,会收到一条消息,例如
Ajax POST stopped because of precondition check, url ....

以下是代码:

HTML:

<div id="tablebg">
                <table class="borderbg"  wicket:id="table"> //this will be the web markup container
                    <tr class="thead">
                        <th class="stylethLeft"></th>
                        <th class="styleth">Foo</th>
                        <th class="styleth">Bar</th>
                        <th class="styleth">Baz</th>

                    </tr>

                    <tr wicket:id="gpOffRow">
                        <td class="tdstyle_serial_number" wicket:id="sno">1</td>
                        <td class="td_address" id="alpha"><input type="text"
                            wicket:id="address" class="styledinput" /></td>
                        <td class="td_twochars" id="alpha"><select wicket:id="country"
                            class="styledSelect">
                                <option>NL</option>
                                <option>UK</option>
                        </select></td>
                        <td class="td_phone" id="number"><input type="text"
                            wicket:id="telephone" class="styledinput" /></td>

                    </tr>



                </table>
            </div>


Java代码:

public class GpOfficePage extends WebPage {
private static final long serialVersionUID = 1L;

protected Form<Void> form;

private GeneralPartner generalPartner;
private List<GpOffice> gpOfficeRows;
private WebMarkupContainer wmc=null;

private String editOrNew;

public GpOfficePage(GeneralPartner gp, String editOrNew) {

    this.generalPartner = gp;
    this.editOrNew = editOrNew;

    add(new TopPanel("topPanel", "General Partner Offices details"));

    add(new FeedbackPanel("gpOffFeedback"));

    form = new Form<Void>("gpOffForm");
    add(form);
    wmc=new WebMarkupContainer("table");
    form.add(Commons.createCancelButton("cancelButton"));
    form.add(createSaveNextButton("saveNextButton"));
    form.add(createAjaxButton("addRowButton",form,wmc));
    form.add(wmc);


列表视图:

ListView<GpOffice> gpo = new ListView<GpOffice>("blah",
            blah) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<GpOffice> item) {

            item.setModel(new CompoundPropertyModel<blahblah>(item
                    .getModel()));

            item.add(new Label("sno", new Integer(item.getIndex())
                    .toString()));

            TextField<String> addressTf = new TextField<String>("address");
            addressTf.setRequired(true);
            item.add(addressTf);

            DropDownChoice<Country> countryList = new DropDownChoice<Country>(
                    "country",
                    new LoadableDetachableModel<List<Country>>() {
                        private static final long serialVersionUID = 1L;

                        @Override
                        protected List<Country> load() {
                            ArrayList<Country> countries = new ArrayList<Country>(); 
                            Country c1 = new Country(); 
                            c1.setName("INR"); 
                            c1.setIsoCode("INR");
                            countries.add(c1); 

                            Country c2 = new Country(); 
                            c2.setName("INR2"); 
                            c2.setIsoCode("INR2");
                            countries.add(c2);
                            return countries;
                        }
                    });
            item.add(countryList);

            TextField<String> telephoneTf = new TextField<String>(
                    "telephone");
            item.add(telephoneTf);
        }
    };
    wmc.add(gpo);//add to the WebMarkupContainer

createAjaxButton()方法

private AjaxButton createAjaxButton(final String id, Form<?> form, final WebMarkupContainer wmc){
System.out.println("LOOK HERE"+" "+ wmc.size()+" "+wmc.getMarkupId());
    AjaxButton ajaxButton=new AjaxButton(id){

        private static final long serialVersionUID = 1L;
        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form){    

            target.add(wmc);


        }
        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form){}

    };

    return ajaxButton;
}

这里可能有什么问题?感谢

0 个答案:

没有答案