Announcement

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

    How to make data source fields from multiple different types appears as static text?

    Hi folks, how are you feeling today?

    I have a clientonly datasource that I am using to receive data from another view in the application, this guy has 11 fields, some has date value, others holds text, and so forth.

    This datasource is bound to a dynamic form. The question is, I need to display the data source data as text (like StaticTextItem), not as controls, I mean DataSourceDateField, DataSourceTextField, and the like. How can I do that?

    Every suggestion will be very appreciated.

    I have tried use DataSourceField instead any specific type, but unsuccessful. By the way, I am using a ListGridRecord (a selected record in a grid from another view) to feed the data source.

    Best regards,

    Vitor Eduardo

    P.S. Have a nice weeked.

    #2
    Hi Vitor. I'm going to take a stab a it and say that you could just override all your DataSourceFields with StaticTextItem fields, and use those to populate the form. By overriding I mean creating (manually in your DynamicForm) new StaticTextItem fields with the exact same name of your DataSource fields. This way, you will get the fields displayed this way and not as DataSourceDateField, DataSourceTextField, etc.

    Hope this helps...

    ps. have a nice weekend too..

    Comment


      #3
      Hi Carlos unfortunately seems not works. Please, if you can, take a closer look the code below:

      Code:
      public StaticTextItem getSendungsnummerField() {
              if(sendungsnummerField == null){
                  sendungsnummerField = new StaticTextItem("sendungsnummer");
                  sendungsnummerField.setTitle(scatext.fields_sendnummer());
      //            sendungsnummerField.setCellStyle("formTitleBig ");
                  sendungsnummerField.setAlign(Alignment.CENTER);
              }
              return sendungsnummerField;
          }
                  
          public StaticTextItem getArtField() {
              if(artField == null){
                  artField = new StaticTextItem("art");
                  artField.setTitle(scatext.fields_art());
          //        artField.setCellStyle("formCellCenterAlignment ");
                  artField.setAlign(Alignment.CENTER);
              }
              return artField;
          }
                  
          public StaticTextItem getLuField() {
              if(luField == null){
                  luField = new StaticTextItem("lu");
                  luField.setTitle(scatext.fields_lu());
              //    luField.setCellStyle("formCellCenterAlignment ");
                  luField.setCanEdit(false);
                  luField.setAlign(Alignment.CENTER);
              }
              return luField;
          }
          
          public StaticTextItem getPackField() {
              if(packField == null){
                  packField = new StaticTextItem("packlisten");
                  packField.setTitle(scatext.fields_pack());
          //        packField.setCellStyle("formCellCenterAlignment ");
                  packField.setAlign(Alignment.CENTER);
              }
              return packField;
          }
          
          public StaticTextItem getSaSollPatField() {
              if(saSollPatField == null){
                  saSollPatField = new StaticTextItem("saSoll");
                  saSollPatField.setTitle(scatext.fields_sasollpat());
              //    saSollPatField.setCellStyle("formCellCenterAlignment ");
                  saSollPatField.setAlign(Alignment.CENTER);
              }
              return saSollPatField;
          }
          
          public StaticTextItem getAwField() {
              if(awField == null){
                  awField = new StaticTextItem("auswahl");
                  awField.setTitle(scatext.fields_aw());
          //        awField.setCellStyle("formCellCenterAlignment ");
                  awField.setAlign(Alignment.CENTER);
              }
              return awField;
          }
      
          public StaticTextItem getSaistField() {
              if(saistField == null){
                  saistField = new StaticTextItem("saIst");
                  saistField.setTitle(scatext.fields_saist());
          //        saistField.setCellStyle("formCellCenterAlignment ");
                  saistField.setAlign(Alignment.CENTER);
              }
              return saistField;
          }
          
          public StaticTextItem getCuField() {
              if(cueField == null){
                  cueField = new StaticTextItem("cue");
                  cueField.setTitle(scatext.fields_cue());
          //        cueField.setCellStyle("formCellCenterAlignment ");
                  cueField.setAlign(Alignment.CENTER);
              }
              return cueField;
          }
          
          public StaticTextItem getVersandSollField() {
              if(versandSollField == null){
                  versandSollField = new StaticTextItem("versandSoll");
                  versandSollField.setTitle(scatext.fields_versandsoll());
              //    versandSollField.setCellStyle("formCellCenterAlignment ");
                  versandSollField.setAlign(Alignment.CENTER);
              }
              return versandSollField;
          }
          
          public StaticTextItem getVersandAbWerkField() {
              if(versandAbWerkField == null){
                  versandAbWerkField = new StaticTextItem("versandwerk");
                  versandAbWerkField.setTitle(scatext.fields_versandabwerk());
              //    versandAbWerkField.setCellStyle("formCellCenterAlignment ");
                  versandAbWerkField.setAlign(Alignment.CENTER);
              }
              return versandAbWerkField;
          }
          
          public StaticTextItem getFinanzfreigabeField() {
              if(finanzfreigabeField == null){
                  finanzfreigabeField = new StaticTextItem("finanzfreigabe");
                  finanzfreigabeField.setTitle(scatext.fields_finanzfreigabe());
              //    finanzfreigabeField.setCellStyle("formCellCenterAlignment ");
                  finanzfreigabeField.setCanEdit(false);
                  finanzfreigabeField.setAlign(Alignment.CENTER);
              }
              return finanzfreigabeField;
          }
      The code above is from view. The following is from presenter where I create the datasource:

      Code:
      public DataSource getDsSendung() {
              
              if (dsSendung == null) {
                  
                  dsSendung = new DataSource();
                  dsSendung.setID("FahrzeugsendungDS");
                  dsSendung.setClientOnly(true);
                  
                  DataSourceField textSendungsNr = new DataSourceTextField("sendungsnummer");
                  textSendungsNr.setTitle(scatext.fields_sendnummer());
                  textSendungsNr.setCanEdit(false);
                  
                  DataSourceField textArt = new DataSourceTextField("art");
                  textArt.setTitle(scatext.fields_art());
                  textArt.setCanEdit(false);
                  
                  DataSourceField textLU = new DataSourceTextField("lu");
                  textLU.setTitle(scatext.fields_lu());
                  textLU.setCanEdit(false);
                  
                  DataSourceField intPack = new DataSourceIntegerField("packlisten");
                  intPack.setTitle(scatext.fields_pack());
                  intPack.setCanEdit(false);
                  
                  DataSourceField dateSASoll = new DataSourceDateField("saSoll");
                  dateSASoll.setTitle(scatext.fields_sasollpat());
                  dateSASoll.setCanEdit(false);
                  
                  DataSourceField dateAW = new DataSourceDateField("auswahl");
                  dateAW.setTitle(scatext.fields_aw());
                  dateAW.setCanEdit(false);
                  
                  DataSourceField dateSAIst = new DataSourceDateField("saIst");
                  dateSAIst.setTitle(scatext.fields_saist());
                  //dateSAIst.setFormat(format);
                  dateSAIst.setCanEdit(false);
                  
                  DataSourceField textCU = new DataSourceTextField("cue");
                  textCU.setTitle(scatext.fields_cue());
                  textCU.setCanEdit(false);
                  
                  DataSourceField dateVersandSoll = new DataSourceDateField("versandSoll");
                  dateVersandSoll.setTitle(scatext.fields_versandsoll());
                  dateVersandSoll.setCanEdit(false);
                  
                  DataSourceField floatRebateMax = new DataSourceFloatField("rebatemax");
                  floatRebateMax.setCanEdit(false);
                  floatRebateMax.setHidden(true);
                  
                  DataSourceField floatBaseRebate = new DataSourceFloatField("baserebate");
                  floatBaseRebate.setCanEdit(false);
                  floatBaseRebate.setHidden(true);
                  
                  DataSourceField dateVersandWerk = new DataSourceDateField("versandwerk");
                  dateVersandWerk.setTitle(scatext.fields_versandabwerk());
                  dateVersandWerk.setCanEdit(false);
                  
                  DataSourceField textFinanzfreigabe = new DataSourceTextField("finanzfreigabe");
                  textFinanzfreigabe.setTitle(scatext.fields_finanzfreigabe());
                  textFinanzfreigabe.setCanEdit(false);
                  
                  DataSourceField textJahr = new DataSourceTextField("jahr");
                  textJahr.setHidden(true);
                  
                  dsSendung.setFields(
                      textSendungsNr,
                      textArt,
                      textLU,
                      intPack,
                      dateSASoll,
                      dateAW,
                      dateSAIst,
                      textCU,
                      dateVersandSoll,
                      floatRebateMax,
                      floatBaseRebate,
                      dateVersandWerk,
                      textFinanzfreigabe,
                      textJahr
                  );
                  
              }
              
              return dsSendung;
          }

      Comment


        #4
        Hi Vitor. Sorry for the late reply, but I had a very busy start of the week. Anyway, here is some ample code where I get the effect described in my post above.

        TestCases.java (for brevitty I excluded my imports, but if you need them, feel free to ask and I will update the post).
        Code:
        public class TestCases implements EntryPoint {  
             
            public void onModuleLoad() {         
                DynamicForm form = new DynamicForm();
                form.setDataSource(DataSource.get("log"));
                form.setUseAllDataSourceFields(true);
                form.setAutoFetchData(true);
            
        //        StaticTextItem idField = new StaticTextItem("id");
        //        StaticTextItem timeStampField = new StaticTextItem("time_stamp");
        //        StaticTextItem levelField = new StaticTextItem("level");
        //        StaticTextItem categoryField = new StaticTextItem("category");
        //        StaticTextItem messageField = new StaticTextItem("message");
        //        StaticTextItem userNameField = new StaticTextItem("username");
                
        //        form.setFields(idField, timeStampField, levelField, categoryField, messageField, userNameField);
                
                HLayout layout = new HLayout();
                layout.setWidth100();
                layout.setHeight100();
                layout.addMember(form);
                layout.show();
            }
        }
        log.ds.xml (besides the i18n elements, nothing out of the ordinary here)
        Code:
        <DataSource 
            ID="log" 
            serverType="sql" 
            tableName="log" 
            xmlns:fmt="WEB-INF/"
            autoDeriveSchema="true"
        >
            <fmt:bundle basename="com.myApp.testcases.shared.i18n.MyResources" encoding="utf-8"/>
            <fields>
            
                <field name="id" type="sequence" primaryKey="true" hidden="true">
                </field>
                
                <field name="time_stamp" type="datetime">
                    <title><fmt:message key="log_timeStamp"/></title>
                </field>        
        
                <field name="level">
                    <title><fmt:message key="log_level"/></title>
                    <valueMap>
                        <value id="E"><fmt:message key="log_levelError"/></value>
                        <value id="W"><fmt:message key="log_levelWarning"/></value>
                        <value id="I"><fmt:message key="log_levelInfo"/></value>
                    </valueMap>
                </field>
                
                <field name="category">
                    <title><fmt:message key="log_category"/></title>
                    <valueMap>
                        <value id="FL"><fmt:message key="log_categoryFileLoad"/></value>
                        <value id="PER"><fmt:message key="log_categoryPerformance"/></value>
                    </valueMap>
                </field>
                
                <field name="message">
                    <title><fmt:message key="log_message"/></title>
                </field>
                
                <field name="username">
                    <title><fmt:message key="log_userName"/></title>
                </field>
                
            </fields>
        </DataSource>
        This is the result I get when I use the code just as it's posted:
        Click image for larger version

Name:	FormWithoutOverrides.png
Views:	101
Size:	8.6 KB
ID:	238886

        And this is the result I get when I uncomment the code above and use the field overrides:
        Click image for larger version

Name:	FormWithOverrides.png
Views:	96
Size:	6.0 KB
ID:	238887

        Off course you can set additional properties for the overridden fields to get a better look than this, but I hope it is clear enough to illustrate the point.

        Hopefully this is what you were asking for!

        Comment


          #5
          Hi Carlos,

          Thank you for your reply, was not late. That issue I solved by setting the editor type property for data source fields, passing the form items instances as reference.

          However, essentially the problem remains, then your reply not came late. Now, I have a grid that shows the data for a table. I have a modal (window) used to add new records. So, I have a form inside, with only three fields. THe form is bound in the same datasource from the grid.

          I have done the same way you described above, but unsuccessfully. The datasource still overrides the form items. Please, look at the code below:

          DataSource descriptor
          [HTML]
          <DataSource ID="CountryDS" serverType="generic"
          mappedBeanClassName="com.sca.server.transfer.CountryTransferData"
          serverConstructor="com.sca.core.client.datasource.CountryDS">
          <fields>
          <field
          name="iso"
          primaryKey="true"
          type="text"
          candEdit="false"
          escapeHTML="true"
          required="true"
          length="3"/>
          <field
          name="description"
          type="text"
          candEdit="true"
          escapeHTML="true"
          required="true"
          length="512"/>
          <field
          name="countryCode"
          type="text"
          candEdit="true"
          escapeHTML="true"
          required="true"
          length="6"/>
          </fields>
          </DataSource>
          [/HTML]

          The form items implementation:
          Code:
              public DynamicForm getForm() {
                  
                  if (form == null) {
                      
                      form = new DynamicForm();
                      form.setWidth100();
                      form.setAutoHeight();
                      form.setFields(
                          getTextCountry(),
                          getTextISO(),
                          getTextCode()
                      );
                      
                  }
                  
                  layout.addMember(form, 0);
                  
                  return form;
              }
          
              public TextItem getTextCountry() {
                  
                  if (textCountry == null) {
                      
                      textCountry = new TextItem();
                      textCountry.setTitle(scatext.screen_landertabelle_field_country());
                      
                  }
                  
                  return textCountry;
              }
          
              public TextItem getTextISO() {
                  
                  if (textISO == null) {
                      
                      textISO = new TextItem();
                      textISO.setTitle(scatext.screen_landertabelle_field_iso());
                      
                  }
                  
                  return textISO;
              }
          
              public TextItem getTextCode() {
                  
                  if (textCode == null) {
                      
                      textCode = new TextItem();
                      textCode.setTitle(scatext.screen_landertabelle_field_code());
                      
                  }
                  
                  return textCode;
              }
          Then, before bind the datasource to the form, in the presenter I set field names:
          Code:
          display.getWindowAdd().getTextISO().setName(FIELD_ISO);
          display.getWindowAdd().getTextCountry().setName(FIELD_DESCRIPTION);
          display.getWindowAdd().getTextCode().setName(FIELD_COUNTRY_CODE);
          Any idea?

          Comment


            #6
            Hi Vitor. Is this code supposed to override the field definitions? If so, please take into consideration that for correctly overriding a field, you need to set its ID to the same ID used in the DataSource descriptor (ds.xml) and not its title. Maybe this is the problem?

            Comment


              #7
              Yes, I know. I am using the same name in ds.xml and in form items, please take a look again at the last code snippet. I am using constants but I already verified if their values are equal to ds.xml.

              Comment


                #8
                But setting the title of an item is not the same as setting its ID. You are setting the title...

                Comment


                  #9
                  I got! yuhuuu! Always you need set the data source first, next the form items. it is working.

                  Comment


                    #10
                    Good... glad I could help!

                    Comment

                    Working...
                    X