Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » Reusing the same formData member on more than one field(Filling two fields (e.g. on different tabs) with the same formData member value)
Reusing the same formData member on more than one field [message #975956] Thu, 08 November 2012 02:51 Go to next message
Urs Beeli is currently offline Urs Beeli
Messages: 325
Registered: October 2012
Location: Bern, Switzerland
Senior Member
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 #980578 is a reply to message #975956] Sun, 11 November 2012 15:19 Go to previous messageGo to next message
Bertin Kiekebosch is currently offline Bertin Kiekebosch
Messages: 300
Registered: August 2011
Senior Member
You could place the commen fields directly in the main box, and then the tabs with the other fields below it.
Re: Reusing the same formData member on more than one field [message #980824 is a reply to message #980578] Sun, 11 November 2012 20:12 Go to previous messageGo to next message
Stathis Alexopoulos is currently offline Stathis Alexopoulos
Messages: 42
Registered: September 2010
Member
Hello Bertin,

I am not quite sure that i understand how to do it.

Till now i am using the following quidelines in order to include a field in an IForm or IFormField.

  • For every field i have to create an inner class implementing the IFormField.
  • The order of appearance can be controlled by @Order annotation.

Is there another way to include a field?
Re: Reusing the same formData member on more than one field [message #981192 is a reply to message #980578] Mon, 12 November 2012 03:20 Go to previous messageGo to next message
Urs Beeli is currently offline Urs Beeli
Messages: 325
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Bertin Kiekebosch wrote on Sun, 11 November 2012 15:19
You could place the commen fields directly in the main box, and then the tabs with the other fields below it.


I could do that, but then I would be designing the UI based on what is technically possible, not what we think the UI should look like.

I was hoping there would be an elegant way to use the same formData field for several fields on the same form. I'd be happy to copy these values from the formData into the UI fields myself, if anyone can tell me how to "be informed" when the formData is updated.
Re: Reusing the same formData member on more than one field [message #981753 is a reply to message #975956] Mon, 12 November 2012 12:13 Go to previous messageGo to next message
Stephan Leicht Vogt is currently offline Stephan Leicht Vogt
Messages: 102
Registered: February 2010
Location: Baden Switzerland
Senior Member

Hallo Urs

You can "be informed" when a field is changed:
  yearField.addPropertyChangeListener(IValueField.PROP_VALUE, new PropertyChangeListener() {
    
    @Override
    public void propertyChange(PropertyChangeEvent e) {
      Date year = (Date) e.getNewValue();
      year2Field.setValue(year);
    }
  }

With this the year2Field gets changed, as soon as the yearField is changed. There is a drawback with this: Normally the form gets loaded with
  MyFormData formData = new MyFormData();
  exportFormData(formData);
  formData = SERVICES.getService(IMyFormProcessService.class).load(formData);
  importFormData(formData);

The importFormData call doesn't trigger the property change triggers by default (IMHO: which is totally OK for 99.8% of all cases). So your changeListener on the yearField won't get triggered when you load the form. So we have following second option. We overwrite the importFormFieldData call on our yearField:
  public class YearField extends AbstractDateField {
    {...} //your code

    @Override
    public void importFormFieldData(AbstractFormFieldData source, boolean valueChangeTriggersEnabled) {
      super.importFormFieldData(source, valueChangeTriggersEnabled);
      try {
        if (!valueChangeTriggersEnabled) {
          year2Field.setValueChangeTriggerEnabled(false);
        }
        year2Field.setValue(YearField.this.getValue());
      }
      finally {
        if (!valueChangeTriggersEnabled) {
          year2Field.setValueChangeTriggerEnabled(true);
        }
      }
    }
  }

With these two codesnippets your fields will get updated in both cases: if the form is loaded from "importFormData" and if the YearField gets changed in the client.

Please ask if you have any further questions.

Sincerely
Stephan
Re: Reusing the same formData member on more than one field [message #983831 is a reply to message #981753] Wed, 14 November 2012 02:16 Go to previous messageGo to next message
Urs Beeli is currently offline Urs Beeli
Messages: 325
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Hi Stephan

Thanks a lot for your answer. This works like a charm.

Cheers
/urs
Re: Reusing the same formData member on more than one field [message #986083 is a reply to message #983831] Sun, 18 November 2012 10:21 Go to previous messageGo to next message
Lukas Huser is currently offline Lukas Huser
Messages: 41
Registered: March 2010
Member
Hi Urs

Just a short additional comment:
If your year fields are read-only, you get away with somewhat shorter code, if you simply copy your fields after importing the form data in the client:
MyFormData formData = new MyFormData();
exportFormData(formData);
formData = SERVICES.getService(IMyFormProcessService.class).load(formData);
importFormData(formData);
getYear2Field().setValue(getYearField().getValue());
// more fields to copy...
Re: Reusing the same formData member on more than one field [message #987873 is a reply to message #986083] Wed, 28 November 2012 08:19 Go to previous messageGo to next message
Urs Beeli is currently offline Urs Beeli
Messages: 325
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Ah, that will be useful for read-only field, thanks.
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 Go to previous messageGo to next message
Urs Beeli is currently offline Urs Beeli
Messages: 325
Registered: October 2012
Location: Bern, Switzerland
Senior Member
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 Sad

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 #990067 is a reply to message #990022] Mon, 10 December 2012 12:42 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie Bresson
Messages: 675
Registered: October 2011
Senior Member
On the FormData each value-holder (for value fields or form variables) contains a valueSet boolean flag. I think that if your ValueFieldData for total2 have a "valueSet == false", it will not be imported by importFieldData(..).

Can you check:
formData.getTotal1().isValueSet()
formData.getTotal2().isValueSet()

and verify my theory.

To test: Before importFieldData(..) you can call "formData.getTotal2().setValueSet(false)" on the client.

If everything works well, ensuring formData.getTotal2().isValueSet() == false should be accomplished in the server.
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 Go to previous message
Urs Beeli is currently offline Urs Beeli
Messages: 325
Registered: October 2012
Location: Bern, Switzerland
Senior Member
@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?
Previous Topic:Corrupted file using IRemoteFileService ...
Next Topic:Unable to locate secure storage module
Goto Forum:
  


Current Time: Thu Aug 28 23:42:31 EDT 2014

Powered by FUDForum. Page generated in 0.01944 seconds