从ListView中检索TextField值

时间:2015-01-07 07:30:41

标签: java list listview wicket

我有ListView.Where我显示了一些记录.ListView包含Lable和TextField.I在textField中输入了一些数据(在ListView中)。在Submit()方法中,我试图检索输入的textfield值。但我没有得到我在文本框中输入的值。请让我知道如何从文本字段输入值?下面是我的代码。

public List<StockCountDetail> getItemEntryDetails() {

        List<StockCountDetail> myStockCountDetailList = new ArrayList<StockCountDetail>();
        List<StockKeepingUnit> mySkuList = MpoBeanFactory.getBean(StockKeepingUnitDAO.class).getByStockLocation(stockLocationModel.getObject());
        myStockCountDetailList.clear();
        for (StockKeepingUnit mySku : mySkuList) {
            StockCountDetail stockCountDetail = new StockCountDetail();
            stockCountDetail.setProduct(mySku.getProduct());
            myStockCountDetailList.add(stockCountDetail);
        }
        return myStockCountDetailList;
    }
myStockCountDetailList = new ListView<StockCountDetail>("itemList", new PropertyModel<List<StockCountDetail>>(
                        StockCountEditPage.this, "itemEntryDetails")) {

            @Override
            protected void populateItem(ListItem<StockCountDetail> aItem) {
                aItem.add(new AttributeAppender("class", true, new Model<String>(aItem.getIndex() % 2 == 0 ? "even" : "odd"), " "));
                aItem.add(new Label("product", aItem.getModelObject().getProduct().getCode()));
                aItem.add(new Label("description", aItem.getModelObject().getProduct().getDescription()));
                aItem.add(new CheckBox("skipFlag", new PropertyModel<Boolean>(aItem.getModel(), "skipFlag")));
                aItem.add(new TextField<Integer>("count", new PropertyModel<Integer>(aItem.getModel(), "count")));
            }
        };
        myStockCountDetailList.setReuseItems(true);
        form.add(myStockCountDetailList);
        setOutputMarkupId(true);
AjaxFallbackButton mySave = new AjaxFallbackButton("save", form) {

            @Override
            protected void onSubmit(AjaxRequestTarget aTarget, Form<?> aForm) {
                saveStockCount();
                aTarget.addComponent(feedbackPanel);
            }

        };
        form.add(mySave);
private void saveStockCount() {
        boolean recordAdded = false;
        for (StockCountDetail myStockCount : myStockCountDetailList.getModelObject()) {
            if (!myStockCount.isSkipFlag()) {
myStockTransaction.setQuantity(new BigDecimal(myStockCount.getCount()));

}

这里我没有使用myStockCount.getCount()获取值,这是listview.let中输入的textbox值我知道如何获取文本框的值?

1 个答案:

答案 0 :(得分:0)

您的ListView使用的PropertyModel通过调用getItemEntryDetails()获取其值。

您致电myStockCountDetailList.getModelObject(),然后生成的对象将来自this.getItemEntryDetails(),这将返回带有List s的新StockCountDetail

为了保留该值,您可以将列表存储在字段中。