Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DataSource / selected record for Component in *.ui.xml

    Hello,

    I tried the component xml feature and defined a small test form like this:

    Code:
    <DynamicForm ID="inhaltForm" dataSource="contact" autoDraw="false" width="400" numCols="4" colWidths="100,100,100,100" errorOrientation="bottom">
                      <fields>
                          <TextItem name="kennung" type="text" title="Kurzname" />
                     </fields>
    </DynamicForm>
    I could load it with RPCManager.loadScreen(...) but how the fields can have the value of a record in datasource? Coding in Java its easy, just add datasource to form and fetch the record, maybe with a valuesmanager. But how can I do this if the form is a *.ui.xml component? My form is always empty o_o

    If the field "kennung" is defined in a *.ds.xml file I only need to define a TextItem kennung = new TextItem("kennung") to get an object specified in the ds.xml with type and title, Does this work also in *.ui.xml file?


    Thx
    Hans

    #2
    Yes, forms defined in Component XML can specify a DataSource. They also, once loaded, support the full Java API, so you can still call fetchData(), editRecord() and other APIs as usual.

    Comment


      #3
      Yeah but how does this work? As you see in my form I set dataSource="contact"because I have a contact.ds.xml file. In my case I have a selected record from a grid and I call the contact form to show details. However the contact form is always empty, the record is not given to the form. I tried
      Code:
      DynamicForm contactForm = (DynamicForm) this.getScreen().getByLocalId("inhaltForm");
      contactForm.setValuesManager(vm);
      to set the existing valuesmanager but it didnt work.

      Any suggestions?

      ​thx

      Comment


        #4
        We're not sure what you mean by "but how does this work", since these APIs work as they are documented, and you already seem familiar with their usage in Java, so there is nothing new here..

        In particular, just setting a valuesManager would not populate a form whether the form was loaded from Component XML or not. Once a form has been added to a ValuesManager, calling APIs such as setValues() or editRecord() will populate it, again regardless of whether Component XML is used or not.

        Comment


          #5
          Thats why i wonder this doesnt work, I used editRecord() and with my java code it works perfectly, just switching to ui.xml part it stopped working. Did I miss something in my ui.xml file,
          Code:
          <TextItem name="kennung" type="text" title="Kurzname" />
          Is that the right way to specify a field from a datasource? In my case "kennung" would be a field in my *.ds.xml file. I suppose here is the mistake.

          Thx

          Comment


            #6
            There's nothing wrong with that tiny fragment, but of course it is impossible to identify the problem if you only post tiny fragments of code. See the FAQ for the information you should post to enable others to help you.

            Comment


              #7
              Well, the problem is the way how databinding works with component xml.

              Here is the datasource
              Code:
              <DataSource
                  ID="contact"
                  serverType="sql"
                  tableName="contact"
                  beanClassName="de.esc.shared.BO.Contact"
              >
                  <fields>
                      <field name="contactid" type="sequence" primaryKey="true"/>
                      <field name="kennung"   type="text"       title="Kurzname"  />
                      <field name="password"   type="password"   title="Kennwort"             />
                      <field name="email"      type="text"       title="EMail"            />
                      <field name="vorname"  type="text"       title="Vorname"          />
                      <field name="nachname"   type="text"       title="Nachname"         />
                      <field name="contacttyp"  type="text" multiple="true" title="Kontakt Typ" defaultValue="Keine Zuordnung" >
                          <valueMap>
                              <value>Firma</value>
                              <value>Externer Mitarbeiter</value>
                              <value>Interner Mitarbeiter</value>
                          </valueMap>
                      </field>
                  </fields>
              </DataSource>
              and here is the component xml (contact.ui.xml)


              Code:
                      <DynamicForm ID="inhaltForm" dataSource="contact" autoDraw="false" width="400" numCols="4" colWidths="100,100,100,100" errorOrientation="bottom">  
                          <fields>
                              <TextItem name="kennung" type="text" title="Kurzname" endRow="true" />
                              <TextItem name="email" type="text"   />
                          </fields>
                      </DynamicForm>
              And here is the way I am loading this component xml widget:

              Code:
                      RPCManager.loadScreen("contact", new LoadScreenCallback() {
                          @Override
                          public void execute() {
                              DynamicForm contactForm = (DynamicForm) this.getScreen().getByLocalId("inhaltForm");
                              
                              contactForm.setValuesManager(vm);
                              contactForm.setAutoFetchData(true);
                              workspaceLayout.addMember(contactForm);
                          }
              
                      });
              The vm (valuesmanager) is set via code with a selected record from a grid. The grid has the datasource "contact". If I set the form manually (create dynmicform ) and set the fields manually via TextItem test = new Textitem("kennung") all the fields have the values from the selected record (done via vm), as soon as I use the component xml its empty, so the databinding doesnt work. It seems for me that the TextItem "kennung" from the ui.xml is not bound with a datasource. If i had to set each single field from the component xml separately via setValue there is no advantage for me using the component xml.

              thx again

              Comment


                #8
                after I add autoFetch attribute to the ui.xml like
                Code:
                  <DynamicForm ID="inhaltForm"  [B]autoFetchData="true" [/B]dataSource="contact" autoDraw="false" width="400" numCols="4" colWidths="100,100,100,100"   errorOrientation="bottom">  
                            <fields>
                                <TextItem name="kennung" type="text" title="Kurzname" endRow="true" ID="kennung" />
                                <TextItem name="firma1" type="text"   />
                            </fields>
                        </DynamicForm>
                it rerieved always the first record from the datasource. How can I tell the component to retrieve a certain record?

                thx.

                Comment


                  #9
                  Again, the components work the same whether defined in Component XML or not, what you have is a basic usage error: autoFetchData causes a fetch at draw, and you are enabling autoFetchData on a component that is already drawn, so of course that does nothing.

                  To fetch a specific record, call fetchData() passing criteria. Since this form is part of a ValuesManager, you want to call fetchData() on the ValuesManager, not any individual form.

                  And, should go without saying, but of course your Component XML form should be loaded and added to the ValuesManager before you call fetchData().

                  Comment

                  Working...
                  X