Hi,
There seem to be similar issues posted previously but none of them explains
this seem to be very trivial scenario. I have the typical Person/Address
relationship in my entities. The person's address can be null but if there
is an address, the city and zip can not be null (please take a look at the
entities below). I utilize RequestFactoryEditorDriver to display/edit the
person and address utilizing PersonEditor and AddressEditor respectively.
I have to mention editing an existing Person with an Address works just
fine so the editors are working and implemented somewhat properly.
Creating a person get done by: request.persist().using(person). If I don't
provide an address before starting the driver(setValue is called with
null), the PersonEditor does its job but AddressEditor's value gets ignored
which is expected but not desired. If I create an address (via the same
requestContext) and assign it to the person (as commented out) before
creating my persist context and starting the driver, then I "have to" have
an address. If I leave the city/zip empty, the editors validation detects
the error and demands the fields to be set. But what if I just want to
ignore the address for some persons and provide one for others.
Basically I want to choose creating an addressProxy and attaching it to the
context. If the AddressEditor is empty then there is no need to create an
AddressProxy, but if there is a value in the AddressEditor then the
validation and flush need to work as expected.
/*
AddressProxy address = request.create(AddressProxy.class);
proxy.setAddress(address);
*/
request.persist().using(person);
here's the jest of AddressEditor
public class AddressEditor extends Composite implements
HasRequestContext<AddressProxy>,
ValueAwareEditor<AddressProxy>, LeafValueEditor<AddressProxy>,
HasEditorErrors<AddressProxy> {
....
}
I tried the OptionalFieldEditor in AddressEditor as follow but I wasn't
sure if I should utilize it in PersonEditor or AddressEditor
interface Driver
extends
RequestFactoryEditorDriver<AddressProxy,
OptionalFieldEditor<AddressProxy, AddressEditor>> {
}
public class Person{
@NotNull
@Size(min = 3, max = 30)
@Column(name = "first_name")
private String firstName;
@NotNull
@Size(min = 3, max = 30)
@Column(name = "last_name")
private String lastName;
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "address_id", unique = true)
private Address address;
}
public class Address{
@Size(min = 3, max = 64, message = "Street lenght needs to be between 3
to 64 chars")
@Column(name = "street")
private String street;
@NotNull
@Size(min = 3, max = 30)
@Column(name = "city")
private String city;
@NotNull
@Size(min = 5, max = 10)
@Column(name = "zip")
private String zip;
}
As you can tell, I have exhausted my options by implementing every possible
editor interfaces and testing different scenarios.
Any help would be greatly appreciated.
Arash
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-web-toolkit/-/dj-VjiWc9RcJ.
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.