Ah, I figured out what I was doing wrong. I am using GXT, and my
pojo/bean was being used as a runtime generated class that implemented
gxt's BeanModel. My ignorance on exactly how this worked prevented me
from refactoring correctly. I had been trying to make a genericized
form component, extending a FieldSet, and now it works like this:
public class SelectorFieldSet<T extends BeanModel, B extends Serializable>
extends FieldSet {
private Grid<T> grid;
private CheckBoxSelectionModel<T> cbsm;
public SelectorFieldSet(String heading, List<ColumnConfig>
columnConfigs,
ListStore<T> storeIn) {..make a grid, add buttons,
etc..}
...bunch of stuff...
public ArrayList<B> getSelectionList() {
final ArrayList<B> a = new ArrayList<B>();
for (T model : grid.getSelectionModel().getSelectedItems()) {
if (model != null) {
a.add((B) model.getBean());
}
}
return a;
}
}
So now I have a builder like this:
public static SelectorFieldSet<BeanModel, MyBean> buildMyBeanSelector() {
...do the Rpc Proxy / list loader stuff
...set up the columns
return new SelectorFieldSet<BeanModel, MyBean>("Pick My Beans!",
configs, store);
}
Then in my onSubmit() method, I can do something like this:
ReportPojo report = new ReportPojo("TheNameOfTheReport");
report.set("selectedMyBeans", myBeanSelector.getSelectionList());
ReportServiceAsync.RPC.runReport(report, callback);
On Thu, Jun 11, 2009 at 2:15 PM, Daniel Jue<[email protected]> wrote:
> Hi, I've read some past emails on this subject, but I want to know if
> anyone has a best practice for this.
>
> Lets say I have MyService(HashMap<String,Serializable> reportBag) .
> I've read it's advisable to narrow down the "Serializable" to a type
> that has a smaller set of implementations, such as using GXT2's
> serializable BeanModel or making up a marker like SerializaleDTO (or
> for that matter, the old IsSerializable) I'd be willing to do this,
> except I'd like to put ArrayList<BeanModel> in my
> HashMap<String,Serializable> reportBag
>
> When I start stuffing things in my bag from widgets like selections
> from grids, etc, these my come back as ArrayList<BeanModel>.
>
> This means if I want to do
>
> reportBag.put("StuffFromWidget1",myGrid.getSelection());
> it won't work unless myGrid.getSelection() is null.
>
> I tried wrapping ArrayList<BeanModel> in a new implementation of
> BeanModel, but it still did not work (same error, even after
> cleaning).
>
> I guess what I'm looking for is a way to sent an object with an
> arbitrary number and combination of beans and lists of beans, where a
> bean is a Serializable object. I'd prefer to use some sort of map, so
> I can look up the objects in my service impl.
>
> i.e.
> reportBag = new HashMap<String, Serializable>();
> reportBag.put("SomeText","JustText");
> reportBag.put("SomeBean",imaSerializableBean);
> reportBag.put("ListOBeans",thatListOBeansFromAWidget);
> reportBag.put("OneMoreBean",forGoodMeasureBean);
> etc etc
>
> then
>
> MyServiceAsync.RPC.runReport(reportBag, callback);
>
> Is this possible?
>
>
> I know topics on serialization get hashed and rehashed here and I sure
> don't want to bother people with noob questions. I must have read 40
> threads on it today! Now I'm off to google code search to try and
> find something in the wild...
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---