Re: Dynamic fields in form

2009-07-18 Thread Igor Vaynberg
create two different panels or fragments that contain form components
for cpu or motherboard, then simply add the correct one to the form.

-igor

On Sat, Jul 18, 2009 at 9:03 AM, Agus Purnomofurunom...@gmail.com wrote:
 Hello.

 I'm currently learning Wicket by converting my previous JSP site to Wicket.
 In my previous site, I have a product detail forms for the user to enter the
 detail of a specific product. This kind of detail differs for each category
 of products (e.g. a CPU has different detail with a motherboard). The code
 (in mixed JSP, crippled for simplicity sake) is like this :

 form action=edit_action.jsp?product_id=%= product.getId() %
 method=post
    table width=100% cellpadding=0 cellspacing=5
        tr valign=top
            td width=20%Name : /td
            td width=80%input type=text name=name size=50
 maxlength=100 value=%= product.getName() % //td
        /tr
 *%
 for (ProductDetail productDetail :
 EJBAgent.getProductService().getProductDetailsByProduct(product.getId())) {
 %
        tr valign=top
            td%=
 EJBAgent.**getProductService**().getField(productDetail.getFieldId()).getName()
 % : /td
            td
                input type=text name=%= productDetail.getFieldId() %
 id=%= productDetail.getFieldId() % size=50 maxlength=255 value=%=
 productDetail.getContent() % /
            /td
        /tr
 %
 }
 %*
        tr valign=top
            td/td
            tdinput type=submit value=Edit class=Button //td
        /tr
    /table
 /form

 The bold parts are the most important section, in that code, it generates
 the dynamic field for each product details associated with a product
 (according to their corresponding category).

 How can I do this with Wicket? I've been googling so far with no luck...

 Thanks before!


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Dynamic fields in form

2009-07-18 Thread Agus Purnomo
Well, the problem is, the category itself is dynamic, here's (a simplified
version) my database structure :

--- Table : Products ---
id / bigint / PK
name / varchar

--- Table : Categories ---
id / bigint / PK
name / varchar

--- Table : Fields ---
id / bigint / PK
name / varchar
category_id / bigint / FK from Categories.id

--- Table : Product Details ---
product_id / bigint / PK / FK from Products.id
field_id / bigint / PK / FK from Fields.id
content / varchar

And I'm just starting with Wicket for about 2 days or so...
But let me try that ,haven't learned about it yet... Thanks anyway!

More helps is much appreciated :)


Re: Dynamic fields in form

2009-07-18 Thread Agus Purnomo
oh I forgot to write this field in the products table :
category_id / bigint / FK from Categories.id


Re: Dynamic fields in form

2009-07-18 Thread Igor Vaynberg
then you can create a panel per field type and add all the right
fields using a repeater. so have a textpanel, selectpanel, etc.

add them into RepeatingView.

-igor

On Sat, Jul 18, 2009 at 9:26 AM, Agus Purnomofurunom...@gmail.com wrote:
 oh I forgot to write this field in the products table :
 category_id / bigint / FK from Categories.id


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Dynamic fields in form

2009-07-18 Thread Agus Purnomo
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
tdspan wicket:id=fieldNameFIELD_NAME/span/td
tdinput type=text size=50 maxlength=100
wicket:id=productDetailField//td
/tr
tr valign=top
td/td
tdinput 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
tdspanManufacturer :/span/td
tdinput type=text size=50 maxlength=100 value=Intel
name=productDetailList:0:productDetailField//td
/tr
tr valign=top
tdspanSeries :/span/td
tdinput type=text size=50 maxlength=100 value=Core i7
name=productDetailList:1:productDetailField//td
/tr
tr valign=top
tdspanCore Name :/span/td
tdinput 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?


Re: Dynamic fields in form

2009-07-18 Thread Daniel Toffetti
Agus Purnomo furunomail at gmail.com writes:
 
 ... etc etc etc ...
 
 Is this good enough? Well, at least this works and simple enough to me...
 Anyone has better solutions?
 

I don't know if it's a better solution, perhaps just an alternative, have
you taken a look at Wicket Web Beans ?

  http://code.google.com/p/wicket-web-beans/


Regards,

Daniel




-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Dynamic fields in form

2009-07-18 Thread Igor Vaynberg
i would use repeatingview rather then the listview, or at least call
listview.setreuseitems(true)

-igor

On Sat, Jul 18, 2009 at 10:31 AM, Agus Purnomofurunom...@gmail.com wrote:
 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
            tdspan wicket:id=fieldNameFIELD_NAME/span/td
            tdinput type=text size=50 maxlength=100
 wicket:id=productDetailField//td
        /tr
        tr valign=top
            td/td
            tdinput 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
    tdspanManufacturer :/span/td
    tdinput type=text size=50 maxlength=100 value=Intel
 name=productDetailList:0:productDetailField//td
 /tr
 tr valign=top
    tdspanSeries :/span/td
    tdinput type=text size=50 maxlength=100 value=Core i7
 name=productDetailList:1:productDetailField//td
 /tr
 tr valign=top
    tdspanCore Name :/span/td
    tdinput 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?


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org