-
1. Re: Binding of ListBoxes with Errai
edewit Apr 11, 2013 5:42 AM (in response to martin.haft)Hi Martin,
You can bind widgets that do not implement HasValue, but then they are readonly. If you want to create a <select/> why not use a ValueListBox.
Hope that helps,
Erik Jan
-
2. Re: Binding of ListBoxes with Errai
martin.haft Apr 11, 2013 7:19 AM (in response to edewit)Hi Erik,
ValueListBox implements HasValue and would be bound by Errai but it is not instantiated by Errai due to a non-trivial constructor. I.e. ValueListBox needs a Renderer<T> with T of type of the value. (Actually we tried an own extention of ValueListBox with trivial constructor that had its own generic Renderer. But than we ran into ClassCastExceptions.)
Martin
-
3. Re: Binding of ListBoxes with Errai
edewit Apr 11, 2013 7:25 AM (in response to martin.haft)1 of 1 people found this helpfulHi Martin,
Right, you can't let Errai @Inject the because of the constructor, but you can still bind it. I don't know why you get a class cast exception maybe because a ValueListBox is not a ListBox? Maybe you can post the full stack trace?
Here is an example of how I use ValueListBox:
@Bound @DataField("project") private ValueListBox projectListBox = new ValueListBox(new Renderer() { @Override public String render(Project project) { return project.getTitle(); } @Override public void render(Project project, Appendable appendable) throws IOException { appendable.append(render(project)); } });
Hope this helps
Erik Jan
-
4. Re: Binding of ListBoxes with Errai
martin.haft Apr 11, 2013 12:14 PM (in response to edewit)Thanks, without Errai injection this works quite well .
Martin
-
5. Re: Binding of ListBoxes with Errai
jmbarone Apr 14, 2013 8:32 AM (in response to martin.haft)Hi ... i'm trying to do a <select/> binding to a ValueListBox.
I follow Erik's advice but i have a ClassCastException when Errai set the value in the ValueListBox.
java.lang.ClassCastException: java.lang.String cannot be cast to xxxxxx
It seems that internally the binder try to do a setValue on the ValueListBox with a String type, but i correctly configured the generics part. :-(
All the other fields are correctly binded.
Thanks for any guide about how to resolve this issue.
-
6. Re: Binding of ListBoxes with Errai
jfuerth Apr 22, 2013 10:59 AM (in response to jmbarone)[Edit: I had responded, but I see Jose started a new thread to deal with this new question. Response has been moved there]
-
7. Re: Binding of ListBoxes with Errai
chaluwa Apr 30, 2013 9:22 AM (in response to edewit)My errai project is modelled after the errai MVP demo which uses presenters and views. In such an approach, the ValueListBox will be defined in the view and probably accessed from the presenter, so can one do data-binding by annotating it like you just did? I usually do my binding within a @PostConstructed annotated method containing code such as:
programme = dataBinder.bind(widget, "field").getModel() so my question is, how can ValueListBox be data-bound in such scenarios.
-
8. Re: Binding of ListBoxes with Errai
jfuerth Apr 30, 2013 10:13 AM (in response to chaluwa)Hi Charles,
I'm not an MVP expert, but by my understanding, in the MVP pattern, the view must not refer to any model classes. That would mean you're limited to simple types in your view: ValueListBox<String> and maybe ValueListBox<Integer>... but never ValueListBox<YourModelClass>.
Because of this, if you choose to follow the MVP pattern, you'll need to create a Converter<YourModelClass, String> and use it when you bind your model property to the ValueListBox<String> widget.
Hope that helps,
Jonathan
-
9. Re: Binding of ListBoxes with Errai
chaluwa Apr 30, 2013 11:24 AM (in response to jfuerth)Well, I wonder how practical it will be to follow such a pattern to the letter. I actually have code like ValueListBox<MyModelClass> in my views, but that's all because I do not perform anything apart from rendering logic within the views. All logic for event handling, RPC e.t.c are done in the presenter. Ok, If I have to go with say ValueListBox<String> instead of ValueListBox<MyModelClass>, how can one guarantee that I can always convert/re-construct/represent MyModelClass from some string representation. Whats the community's experience with doing so.