Reusing the same formData member on more than one field [message #975956] |
Thu, 08 November 2012 02:51  |
Eclipse User |
|
|
|
I have a form containing two tabs. One tab shows a rough overview over the data returned (company name, the year for which the data is shown, a total over the data) while the second tab shows the detail data but it also includes some "header" data (the year for which the data is shown, the total).
When I try to create two fields with the same name on the different tabs (i.e. in their group boxes) Scout complains, telling me the name already exists. If I rename the field, an additional member with the new name is added to the formData.
I currently solve this, by returning the data twice in my process service, i.e.
SQL.selectInto("select name, year, year, total, total, n1, n2, ... nN" +
"from company where company_nr = :companyNr" +
"into :companyName, :year, :year2, :total, :total2, :n1, ... :nN",
formData);
This works, but seems to me to be a clumsy way of solving this issue. Is there a workaround for this?
|
|
|
|
|
|
|
|
|
|
Re: Reusing the same formData member on more than one field [message #990022 is a reply to message #987873] |
Mon, 10 December 2012 09:24   |
Eclipse User |
|
|
|
Actually, having played around with this some more, it seems that the solution suggested by Stephan doesn't work after all (or at least not for all situations).
It does work for the "year1" and "year2" cases. However, when I tried to copy it for another field "total1" and "total2" it fails to work. I debugged it, and what happens is the following:
- total1 is set as part of the importFormData() call
- this triggers both the propertyChange() call and the importFormFieldData() call which copies the total1Field value to total2Field
However, now importFormData() continues, and as my processService did not fill total2 on the form field, importFormData() now overwrites my (propagated and correct) total2Field value with the total2 member of the formData (which is null), so once my form is shown, the corresponding field is empty again 
I guess it makes more sense to use the method proposed by Lukas for the inital population of the form and use the propertyChange listener to propagate changing values during the life time of the form. As it looks now, I can probably forgo overwrite importFieldData().
I'm not quite sure why the same thing works with year1 and year2 (though things are slightly different as there is also a variable year which comes into this, so that might explain it).
Any comments on this?
|
|
|
|
Re: Reusing the same formData member on more than one field [message #990380 is a reply to message #990067] |
Wed, 12 December 2012 04:02  |
Eclipse User |
|
|
|
@Jeremie:
Thanks you were spot on! I added the following code to my ModifyHandler.execLoad() method:
formData = service.load(formData);
System.out.println("total1.isValueSet: " + formData.getTotal1().isValueSet());
System.out.println("total2.isValueSet: " + formData.getTotal2().isValueSet());
formData.getTotal2().setValueSet(false);
importFormData(formData);
And it returns true for both fields. Setting valueSet to false for total2 makes the solution using importFormFieldData works again.
Thanks for helping me out with this!
If I understand your last line correctly, best practice would be to do a setValueSet(false) for any formData member which is not set as part of the SQL.selectInto() in the XxxxProcessService.load() method?
|
|
|
Powered by
FUDForum. Page generated in 0.05749 seconds