CC-GNU LGPL
This software is licensed under the CC-GNU LGPL.

GWT Widget Library

Sunday, June 04, 2006

 

FormPanel API Proposal

I am working on a file upload (like everyone else), and created a few widgets for it, including a FormPanel. This might make it into Monday's release of my distribution. I welcome comments on the API.

The FormPanel's constructor takes a Panel as an argument. This panel is used to organize the widgets inside of the form.

public FormPanel (Panel panel);
public Panel getPanel ();
public void setEncodingType (String type);
public void setMultipartEncoding ();
public void setMethodAsGet ();
public void setMethodAsPost ();
public void setTarget (String url);
public boolean add (Widget widget);
public void submit ();


I also created a FileUpload class, that currently only has a constructor and no methods, The constructor takes the field name as it's only argument.

public FileUploadField (String name);


Here is a code example of using both classes:

final FormPanel form = new FormPanel(new FlowPanel());
form.setMethodAsPost();
form.setMultipartEncoding();
form.setTarget("/uploadAction.do");

FileUploadField fUpload = new FileUploadField("file");
form.add(fUpload);

Hyperlink addLink = new Hyperlink();
addLink.setText("Add File");
addLink.setTargetHistoryToken("addfile");
addLink.addClickListener(new ClickListener()
{
public void onClick (Widget sender)
{
form.submit();
}
});
form.add(addLink);


Feedback welcome.

Comments:
Hi, even without File Upload, a FormPanel looks really necessary !
Is it implemented yet...?
 
There is bug in code sample.

Instead of:

form.setTarget("/uploadAction.do");

there should be

form.setAction("/uploadAction.do");

Mario
 
Post a Comment



<< Home

Archives

May 2006   June 2006  

This page is powered by Blogger. Isn't yours?