Ow yeah... Looks like I can get away with this :

=== ProductEdit.html ===

<form wicket:id="productEditForm">
    <table width="100%" cellpadding="0" cellspacing="5">
        <tr valign="top" wicket:id="productDetailList">
            <td><span wicket:id="fieldName">FIELD_NAME</span></td>
            <td><input type="text" size="50" maxlength="100"
wicket:id="productDetailField"/></td>
        </tr>
        <tr valign="top">
            <td></td>
            <td><input type="submit" value="Edit" class="Button" /></td>
        </tr>
    </table>
</form>

=== ProductEditForm.java ===

public class ProductEditForm extends Form {

    @EJB(name = "LearnWicketEJB/ProductService")
    private ProductService productService;

    private ListView productDetailList;

    public ProductEditForm(String componentName, final Product product) {

        super(componentName);
        this.product = product;

        this.add(productDetailList = new ListView("productDetailList",
this.productService.getProductDetailsByProductId(product.getId())) {
            @Override
            protected void populateItem(final ListItem item) {
                final ProductDetail productDetail = (ProductDetail)
item.getModelObject();
                item.add(new Label("fieldName",
productService.getField(productDetail.getFieldId()).getName() + " :"));
                item.add(new TextField("productDetailField", new
PropertyModel(productDetail, "content")));
            }
        });

    }

    @Override
    public void onSubmit() {

        for (Object object : this.productDetailList.getModelObject()) {
            ProductDetail productDetail = (ProductDetail) object;

this.productService.updateProductDetail(productDetail.getProductId(),
productDetail.getFieldId(), productDetail.getContent(),
productDetail.getNotApplicable());
        }

        this.setResponsePage(new
ProductConfirmation(ProductConfirmation.CONFIRMATION_TYPE_EDIT));

    }

}

=== End of Code ===

I've realized that the ListView in the form generate unique field name
(which is exactly what I need) :

<tr valign="top">
    <td><span>Manufacturer :</span></td>
    <td><input type="text" size="50" maxlength="100" value="Intel"
name="productDetailList:0:productDetailField"/></td>
</tr>
<tr valign="top">
    <td><span>Series :</span></td>
    <td><input type="text" size="50" maxlength="100" value="Core i7"
name="productDetailList:1:productDetailField"/></td>
</tr>
<tr valign="top">
    <td><span>Core Name :</span></td>
    <td><input type="text" size="50" maxlength="100" value="Bloomfield"
name="productDetailList:2:productDetailField"/></td>
</tr>
... etc etc etc ...

Is this good enough? Well, at least this works and simple enough to me...
Anyone has better solutions?

Reply via email to