Thursday, November 16, 2017

Re: Editors

Thanks both of you.

Managing Errors will be the next goal. Colin's info will be useful.
For now, I will call it warning. 

To explain what I dit with the simplest example, let's say I have a Person with a field firstname. 
The simple rule in this case is to get a red dot if firstname is empty.

So I added a field boolean firstnameRP in Person
in ui :
<g:TextBox ui:field="firstname" /> <u:RedPointEditor ui:field="firstnameRP" />
where RedPointEditor is an Editor for a boolean showing or not an image.

In the root editor, when some data are changed in ui :
Person person =  driver.flush();
// compute boolean for firstname
if (person.firstname.size() >  0)
 person.setFirstnameRP(false);
else
 person.setFirstnameRP(true); // show red dot
 
 driver.edit(person); the red dot is hided/showed
 
 EditorVisitor seems promising but I dont have any clue how to get it and use it.
Could you, please, tell me more ?

Pierre

Le jeudi 16 novembre 2017 16:57:00 UTC+1, Thomas Broyer a écrit :
And in case you think "errors" are not a good fit, I think you can do it all by yourself using EditorVisitor⋅s (this is how errors actually work IIRC), and probably custom interfaces for your editors (fwiw, to determine the isDirty flag, the EditorDriver does a first visit using an EditorVisitor to get the initial values just after an edit(), and whenever you call isDirty, it visits again and compares to the initial values).
You'd probably have to tell us more about your use case (e.g. what does "computing the boolean" means?)

On Thursday, November 16, 2017 at 2:13:27 PM UTC+1, Colin Alworth wrote:
It turns out this is already supported in the editor framework, though perhaps not in your editors themselves - the framework even supports a collection being passed from the client code (perhaps from the server) to the driver to indicate that there are problems, and which fields to highlight. The call on the driver is
driver.setConstraintViolations(...)

That takes an Iterable (a List or a Set will work) of javax.validation.ConstraintViolation instances. If you create these objects on the server (using Java's own validation wiring), you can pass them along, else just use com.google.gwt.validation.client.impl.ConstraintViolationImpl's builder() method, and create the instances.

You'll need to at least pass the propertyPath (to each bean property that is wrong), the message (to show the user), and the rootBean (which I believe represents the base object passed to the driver, but it has been a while).

Then, the driver will inform all of your editors which implement HasEditorErrors<T>, by calling their showErrors(...) method with a List of com.google.gwt.editor.client.EditorError instances. With this, you can display that red dot, and give the message about why it is wrong. In GWT itself, only ValueBoxEditorDecorator implements this (and you would wrap a ValueBoxBase subtype with it), but toolkits like GXT show that it is also possible to make each of your individual editors implement it as well.

You can also implement it at the panel level, where you might also say Editor<Person>, add HasEditorErrors<Person>, and then that will get all of the errors within that person instance, so you can render them.

On Thursday, November 16, 2017 at 2:06:49 AM UTC-6, 129pierre wrote:
Hi,

I have a tree structure of data with a lot of fields and relations. I used Editors to avoid too much code.
I have an additionnal feature implemented with Editors but not satisfiying.
For almost all fields in the structure a RedPoint is diplayed next to the field if it is still with the init value (ie: Not answered for RadioButton or empty for textfield...).
To implement that RedPoint feature, I added for each field a boolean fieldRP in the bean so that they are part of the editors.

In case of change, the bean is flush, each boolean are computed and the bean is edited again for display modification of redpoints.

I am looking for a simpler way of doing that. For example, use 2 beans so only flush of data and edit of boolean RP will be necessary.
But for my understanding of Editors, only one bean can be used...


Any help will be apprecied.
Thanks in advance
Pierre

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment