Announcement

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

  • A small problem with the CustomCalidator connection of the ServerCustom type under Listgrid in ClientOnly mode

    SmartGwt 6.1p

    Hi

    I have a completely dynamically created ListGrid and Datasource based on csv string, but without connecting the datasource component to the .ds.xml file.
    ListGrid presents the user with data that will be imported into the database into various tables depending on the definition of columns in csv. One of the columns is the username that I want to verify with the database using the validator. Here my problem arises because if the definition of using the validator in the .ds.xml file is not a problem then my form design does not provide such a file (due to the dynamic structure of the csv file) and I create everything by hand.
    I am asking for advice on how to connect a CustomServer validator running on ListGrid and DataSource in the ClientOnly (true) and SaveLocaly (true) mode from the java code level. I am currently trying to do something like this but it does not work:

    listGrid_Wyniki.setID("ListGrid_Wyniki");
    listGrid_Wyniki.setAutoFetchData(false);
    listGrid_Wyniki.setSaveLocally(true);
    listGrid_Wyniki.setAutoSaveEdits(false);
    listGrid_Wyniki.setSaveByCell(false);
    listGrid_Wyniki.setWidth100();
    listGrid_Wyniki.setHeight100();
    listGrid_Wyniki.setCanEdit(true);
    listGrid_Wyniki.setCanSort(false);
    listGrid_Wyniki.setAutoFitFieldWidths(true);
    listGrid_Wyniki.setAutoFitWidthApproach(AutoFitWidthApproach.BOTH);
    listGrid_Wyniki.setCanRemoveRecords(false);
    listGrid_Wyniki.setLayoutAlign(Alignment.CENTER);
    listGrid_Wyniki.setValidateByCell(true);
    listGrid_Wyniki.setValidateOnChange(true);
    listGrid_Wyniki.setShowRowNumbers(true);
    listGrid_Wyniki.setCanSelectCells(true);
    listGrid_Wyniki.setFilterLocalData(true);
    listGrid_Wyniki.setUseRemoteValidators(true);

    dataSource_rsTempImpCSV = new DataSource();
    dataSource_rsTempImpCSV.setClientOnly(true);

    Record[] recordsCSV = dataSource_rsTempImpCSV.recordsFromText(str_csv, settings);
    RecordList recordList = new RecordList(recordsCSV);

    listGrid_Wyniki.setDataSource(dataSource_rsTempImpCSV);
    listGrid_Wyniki.setData(recordList);
    Próbuję podłączyć validację jednej kolumny z bazą danych:
    CustomValidator impWynBad_Validator = new CustomValidator() {

    @Override
    protected boolean condition(Object value) {
    setType(ValidatorType.SERVERCUSTOM);
    setAttribute("serverObject", "lookupStyle="new" className="pl.ciop.pbf.server.validators.rs.ValidatorDMI" methodName="isKodBadanego"");
    setAttribute("errorMessage", "$errorMessage");
    return false; //I now this is bad but :/
    }
    };

    impWynBad_Validator.setClientOnly(false);
    impWynBad_Validator.setErrorMessage("no rec value in db!");
    impWynBad_Validator.setValidateOnChange(true); listGrid_Wyniki.getField("OS_KOD_BADANY").setValidators(impWynBad_Validator);


    Thank you for any help and I apologize for my poor English.
    Last edited by rs@ciop.pl; 21st May 2019, 04:36.

  • #2
    You're not going to be able to access .ds.xml-based features such as a server custom validator without a .ds.xml file, however, you can generate the DataSource definition dynamically - see the discussion of Dynamic DataSource Generators starting in the QuickStart Guide. So with this approach you would generate the .ds.xml file dynamically from the CSV data.

    Another approach would be a .ds.xml file that doesn't declare the full fields of the CSV data, just declaring one field with the validator you want. This would require the field that you want to validate to have a fixed name, or require you to rename the CSV data to whatever name you use in the .ds.xml file.

    Comment


    • #3
      Thanks for the response, very nice suggestion with the use of Dynamic DataSource Generators. I implemented the second solution in accordance with the guidelines by creating the file.ds.xml with one column and connecting it to the hibernate entity. However, the remote procedure does not start despite the appropriate settings. I do not have any error messages, etc. in the server logs and the web browser console. I include parts of the code with settings, maybe something skipped??

      _rs__TempImp_OsobaGrid.ds.xml:
      <DataSource ID="_rs__TempImp_OsobaGrid" serverType="hibernate" autoDeriveSchema="false" schemaBean="pl.ciop.pbf.server.entities.Osoba" allowAdvancedCriteria="false" generatedBy="rs">
      <fields>
      <field name="osKodBadany" type="text" required="true" length="16" title="Kod osoby badanej" canEdit="false">
      <validators>
      <Validator>
      <type>isString</type>
      <stopIfFalse>true</stopIfFalse>
      <typeCastValidator>true</typeCastValidator>
      <defaultErrorMessage></defaultErrorMessage>
      </Validator>
      <Validator>
      <type>serverCustom</type>
      <errorMessage>$errorMessage</errorMessage>
      <serverObject>
      <className>pl.ciop.pbf.server.validators.rs.ValidatorDMI</className>
      <methodName>isKodBadanego</methodName>
      <lookupStyle>new</lookupStyle>
      </serverObject>
      <serverOnly>true</serverOnly>
      </Validator>

      </validators>
      </field>
      </fields>
      <dropExtraFields>true</dropExtraFields>
      </DataSource>


      ListGrid & DataSource settings:
      listGrid_Wyniki = new ListGrid();
      listGrid_Wyniki.setID("ListGrid_Wyniki");
      listGrid_Wyniki.setAutoFetchData(false);

      listGrid_Wyniki.setSaveLocally(true);
      listGrid_Wyniki.setAutoSaveEdits(false);
      listGrid_Wyniki.setSaveByCell(false);
      listGrid_Wyniki.setWidth100();
      listGrid_Wyniki.setHeight100();
      listGrid_Wyniki.setCanEdit(true);
      listGrid_Wyniki.setCanSort(false);
      listGrid_Wyniki.setAutoFitFieldWidths(true);
      listGrid_Wyniki.setAutoFitWidthApproach(AutoFitWidthApproach.BOTH);
      listGrid_Wyniki.setCanRemoveRecords(false);
      listGrid_Wyniki.setLayoutAlign(Alignment.CENTER);
      listGrid_Wyniki.setValidateByCell(true);
      listGrid_Wyniki.setValidateOnChange(true);

      listGrid_Wyniki.setShowRowNumbers(true);
      listGrid_Wyniki.setCanSelectCells(true);
      listGrid_Wyniki.setFilterLocalData(true);

      listGrid_Wyniki.setUseRemoteValidators(true);

      dataSource_rsTempImpCSV = new DataSource(); //dataSource_rsTempImpCSV.get("_rs__TempImp_OsobaGrid");
      dataSource_rsTempImpCSV.get("_rs__TempImp_OsobaGrid");
      dataSource_rsTempImpCSV.setID("_rs__TempImp_OsobaGrid");
      dataSource_rsTempImpCSV.setFields(fieldsList.toArray(new DataSourceField[fieldsList.size()]));
      dataSource_rsTempImpCSV.setClientOnly(true);

      Record[] recordsCSV = dataSource_rsTempImpCSV.recordsFromText(str_csv, settings);
      RecordList recordList = new RecordList(recordsCSV);

      listGrid_Wyniki.setDataSource(dataSource_rsTempImpCSV);
      listGrid_Wyniki.setData(recordList);



      A code snippet that runs all validators in ListGrid (however, only validators on the client side work)
      listGrid_Wyniki.saveAllEdits();
      listGrid_Wyniki.saveEdits();
      for (int row_num = 0; row_num < listGrid_Wyniki.getTotalRows(); row_num++) {
      ListGridRecord rec = (ListGridRecord) listGrid_Wyniki.getEditedRecord(row_num);
      Map<String, Object> lgWyn_map = new HashMap<String, Object>(); // 1.07
      for (int i = 0; i < fieldsList.length; i++) {
      String colName = fieldsList[i].getName();
      String colVal = rec.getAttribute(colName);
      lgWyn_map.put(colName, colVal);
      }
      listGrid_Wyniki.setEditValues(row_num, lgWyn_map);
      if (!listGrid_Wyniki.validateRow(row_num)) {
      komunikat += "Błąd walidacji wczytywanych danych!!!, wiersz: " + Integer.valueOf(row_num + 1) + "<BR>";
      setCzyWystapilJakisBladDanych(true);
      }
      }
      listGrid_Wyniki.saveAllEdits();
      listGrid_Wyniki.saveEdits();



      The server-side class is responsible for the validation. The same class is used in another part of the code with a different method and works without a problem. The difference is that in this other part there is normal communication with the database and when data is saved, a validation call is made, which is visible in the Developer console.

      package pl.ciop.pbf.server.validators.rs;
      import java.util.Map;
      import javax.servlet.http.HttpServletRequest;
      import org.eclipse.jetty.util.log.Log;
      import com.isomorphic.datasource.DSRequest;
      import com.isomorphic.datasource.DataSource;
      import com.isomorphic.datasource.Validator;
      import com.isomorphic.log.Logger;
      import com.isomorphic.util.DataTools;
      import com.isomorphic.util.ErrorMessage;

      public class ValidatorDMI {

      private final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(this.getClass().getName());

      public boolean isUnique(Object value, Validator validator, String fieldName, Map record, DataSource ds, HttpServletRequest httpServletRequest) throws Exception {
      logger.info("[RS] - isUnique - validating value: '" + value + "' for fieldName: '" + fieldName + "' in DataSource: '" + ds.getID() + "'\nin record: " + DataTools.prettyPrint(record) + "\nvalidator definition: "
      + DataTools.prettyPrint(validator));

      if (value == null)
      return false;

      DSRequest dsRequest = new DSRequest(ds, "fetch");
      dsRequest.setCriteria(DataTools.buildMap(fieldName, record.get(fieldName)));
      if ((dsRequest.execute()).getDataList().size() > 0) {
      validator.addErrorMessageVariable("errorMessage", "Wartość ma być unikalna!");
      return false;
      }
      return true;
      }

      public boolean isKodBadanego(Object value, Validator validator, String fieldName, Map record, DataSource ds, HttpServletRequest httpServletRequest) throws Exception {
      logger.info("[RS] - isKodBadanego - validating value: '" + value + "' for fieldName: '" + fieldName + "' in DataSource: '" + ds.getID() + "'\nin record: " + DataTools.prettyPrint(record) + "\nvalidator definition: "
      + DataTools.prettyPrint(validator));

      if (value == null)
      return false;

      DSRequest dsRequest = new DSRequest("_rs__Osoba", "fetch");
      dsRequest.setCriteria(DataTools.buildMap("osKodBadany", record.get(fieldName)));
      if ((dsRequest.execute()).getDataList().size() <= 0) {
      validator.addErrorMessageVariable("errorMessage", "No user in database!");
      return false;
      }
      return true;
      }

      }


      I do not know what else I can set ?, what's worse, I do not have any error messages, and the developer console shows that there is no traffic when modifying the data and saving it on the server side.
      As part of the tests, I also changed the setClientOnly property (false) in the DataSource, but that has not changed anything.

      Only where there was some effect was the setSaveLocally (false) change in Listgrid. When I did not have a .ds.xml file, I received a message that the system could not locate it. With the current implementation of the ds.xml file I got a message about the lack of the primary key in it, but I did it only as part of the test to see how the application will behave, so setClientOnly (true) suits me the most.

      I was pleased to find information on the forum in the thread from 2016 about adding to the ListGrid a UseRemoteValidators property that would allow calling the remote validation procedures without the need to write data directly to the database.

      I will be grateful for the hint of what I can check or set.

      Sorry for the long post, I hope it is understandable :) :)


      Last edited by rs@ciop.pl; 22nd May 2019, 00:19. Reason: removed native chars ;)

      Comment


      • #4
        You need to setClientOnly(false) and setSaveLocally(false). Nothing is going to the server because that's exactly what you said to do. And yes, you'll need to have a primaryKey field. As with the single field you wanted validated, you can name it whatever you want and you can fill it in however you like, it need not be in the CSV data.

        Comment


        • #5
          OK, great thanks for the answer, but it does not work.

          I added a key key definition to the ds.xml file and a column that reflects the table in the database. I checked the file itself in Visual Developer if it correctly displays the data from the table and is ok.

          As suggested, I set Listgrid.setSaveLocally (false); and DataSource.setClientOnly (false); and Listgrid has setUseRemoteValidators (true);

          Code:
          <DataSource ID="_rs__TempImp_OsobaGrid" serverType="hibernate" autoDeriveSchema="false" schemaBean="pl.ciop.pbf.server.entities.Osoba" allowAdvancedCriteria="true" generatedBy="rs">
            <fields>
              <field name="id" type="sequence" required="false" length="255" title="Id" canEdit="false" hidden="true" primaryKey="true">
                <validators>
                  <Validator>
                    <type>isInteger</type>
                    <stopIfFalse>true</stopIfFalse>
                    <typeCastValidator>true</typeCastValidator>
                    <defaultErrorMessage></defaultErrorMessage>
                  </Validator>
                </validators>
              </field>  
              <field name="osKodBadany" type="text" required="true" length="16" title="Kod osoby badanej" canEdit="false">
                <validators>
                  <Validator>
                    <type>isString</type>
                    <stopIfFalse>true</stopIfFalse>
                    <typeCastValidator>true</typeCastValidator>
                    <defaultErrorMessage></defaultErrorMessage>
                  </Validator>
                  <Validator>
                    <type>serverCustom</type>
                    <errorMessage>$errorMessage</errorMessage>
                    <serverObject>
                      <className>pl.ciop.pbf.server.validators.rs.ValidatorDMI</className>
                      <methodName>isKodBadanego</methodName>
                      <lookupStyle>new</lookupStyle>
                    </serverObject>
                    <serverOnly>true</serverOnly>
                  </Validator>
                </validators>
              </field>
            </fields>
            <dropExtraFields>true</dropExtraFields>
          </DataSource>
          With this configuration, the developer console shows the launch of the update operation, but I get a message about the lack of the primary key:

          Code:
          === 2019-05-22 10:34:41,277 [5-90] INFO  RequestContext - URL: '/pbf__hs/sc/IDACall', User-Agent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0': Moz (Gecko) with Accept-Encoding header
          === 2019-05-22 10:34:41,281 [5-90] DEBUG XML - Parsed XML from (in memory stream): 4ms
          === 2019-05-22 10:34:41,283 [5-90] DEBUG RPCManager - Processing 1 requests.
          === 2019-05-22 10:34:41,284 [5-90] DEBUG HibernateDSGenerator - Generating data source '_rs__TempImp_OsobaGrid' for entity pl.ciop.pbf.server.entities.Osoba
          === 2019-05-22 10:34:41,284 [5-90] DEBUG HibernateDSGenerator - Generated data source configuration: {beanClassName=pl.ciop.pbf.server.entities.Osoba, entityName=pl.ciop.pbf.server.entities.Osoba, serverType=hibernate, allowAdvancedCriteria=true, ID=_rs__TempImp_OsobaGrid, dropExtraFields=true, generatedBy=v11.1p_2019-05-13/Pro Deployment 2019-05-13, fields=[{extPrecision=19, hidden=true, extIsLazy=false, canEdit=false, name=id, length=255, extIsUnique=true, type=sequence, extScale=2, required=false, primaryKey=true}, {extPrecision=19, extIsLazy=false, canEdit=true, name=osKodBadany, length=16, extIsUnique=true, type=text, extScale=2, required=false}, {extPrecision=19, extIsLazy=false, canEdit=true, name=version, length=255, extIsUnique=false, type=integer, extScale=2, required=true}]}
          === 2019-05-22 10:34:41,284 [5-90] DEBUG RPCManager - Request #1 (DSRequest) payload: {
              criteria:{
              },
              values:{
                  osKodBadany:"KOD_3",
                  NR_BAD:"1",
                  OLBI_1:"2",
                  OLBI_2:"2",
                  OLBI_3:"3",
                  OLBI_4:"2",
                  OLBI_5:"2",
                  OLBI_6:"3",
                  OLBI_7:"2",
                  OLBI_8:"2",
                  OLBI_9:"2",
                  OLBI_10:"2",
                  OLBI_11:"3",
                  OLBI_12:"3",
                  OLBI_13:"3",
                  OLBI_14:"2",
                  OLBI_15:"2",
                  OLBI_16:"2"
              },
              operationConfig:{
                  dataSource:"_rs__TempImp_OsobaGrid",
                  repo:null,
                  operationType:"update",
                  textMatchStyle:"exact"
              },
              componentId:"ListGrid_Wyniki",
              appID:"builtinApplication",
              operation:"_rs__TempImp_OsobaGrid_update",
              oldValues:{
                  osKodBadany:"KOD_3",
                  NR_BAD:"1",
                  OLBI_1:"2",
                  OLBI_2:"3",
                  OLBI_3:"3",
                  OLBI_4:"2",
                  OLBI_5:"2",
                  OLBI_6:"3",
                  OLBI_7:"2",
                  OLBI_8:"2",
                  OLBI_9:"2",
                  OLBI_10:"2",
                  OLBI_11:"3",
                  OLBI_12:"3",
                  OLBI_13:"3",
                  OLBI_14:"2",
                  OLBI_15:"2",
                  OLBI_16:"2"
              }
          }
          === 2019-05-22 10:34:41,284 [5-90] INFO  IDACall - Performing 1 operation(s)
          === 2019-05-22 10:34:41,284 [5-90] DEBUG DeclarativeSecurity - Processing security checks for DataSource null, field null
          === 2019-05-22 10:34:41,284 [5-90] DEBUG DeclarativeSecurity - DataSource _rs__TempImp_OsobaGrid is not in the pre-checked list, processing...
          === 2019-05-22 10:34:41,284 [5-90] DEBUG AppBase - [builtinApplication._rs__TempImp_OsobaGrid_update] No userTypes defined, allowing anyone access to all operations for this application
          === 2019-05-22 10:34:41,284 [5-90] DEBUG AppBase - [builtinApplication._rs__TempImp_OsobaGrid_update] No public zero-argument method named '__rs__TempImp_OsobaGrid_update' found, performing generic datasource operation
          === 2019-05-22 10:34:41,284 [5-90] WARN  RequestContext - dsRequest.execute() failed:
          com.isomorphic.base.UpdateWithoutPKException: Criteria received from the client for update operation is missing the following required unique and/or primary fields: [id, id]. Either provide all primary key fields or set allowMultiUpdate or providesMissingKeys on the OperationBinding (see the client-side docs for details of those flags)
              at com.isomorphic.application.AppBase.executeDefaultDSOperation(AppBase.java:621)
              at com.isomorphic.application.AppBase.executeAppOperation(AppBase.java:548)
              at com.isomorphic.application.AppBase.execute(AppBase.java:491)
              at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:2815)
              at com.isomorphic.servlet.IDACall.handleDSRequest(IDACall.java:230)
              at com.isomorphic.servlet.IDACall.processRPCTransaction(IDACall.java:187)
              at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:152)
              at com.isomorphic.servlet.IDACall._processRequest(IDACall.java:119)
              at com.isomorphic.servlet.IDACall.doPost(IDACall.java:79)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
              at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:176)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
              at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)
              at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)
              at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:224)
              at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
              at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
              at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
              at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
              at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
              at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
              at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
              at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
              at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
              at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
              at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
              at org.eclipse.jetty.server.handler.RequestLogHandler.handle(RequestLogHandler.java:95)
              at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
              at org.eclipse.jetty.server.Server.handle(Server.java:499)
              at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
              at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
              at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
              at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
              at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
              at java.lang.Thread.run(Thread.java:748)
          === 2019-05-22 10:34:41,285 [5-90] DEBUG RPCManager - Content type for RPC transaction: text/plain; charset=UTF-8
          === 2019-05-22 10:34:41,285 [5-90] DEBUG RPCManager - non-DMI response, dropExtraFields: true
          === 2019-05-22 10:34:41,285 [5-90] INFO  Compression - /pbf__hs/sc/IDACall: 412 -> 284 bytes
          200 - POST /pbf__hs/sc/IDACall?isc_rpc=1&isc_v=v11.1p_2019-05-13&isc_xhr=1 (127.0.0.1) 284 bytes

          From what I read in the documentation and what I'm interested in is just launching data validation and setting properties:
          Listgrid.setSaveLocally (true);
          DataSource.setClientOnly (true);
          Listgrid.setUseRemoteValidators (true); - it was to ensure that.

          I do not want to write to the table in the database.

          The documentation says:

          void com.smartgwt.client.widgets.grid.ListGrid.setUseRemoteValidators (Boolean useRemoteValidators)

          If saveLocally is specified, this is a grid is bound to a DataSource which includes a remote field validators, by default edits will be saved synchronously and these are validatorswill not be executed.
          Set this property to true to ensure the remote validators are called whensaving edits in saveLocally mode. Note that since this is the most important issue, it is still being processed.

          Note: This is an advanced setting
          Parameters: useRemoteValidators New useRemoteValidators value. Default value is null



          Maybe I am still doing something wrong, or maybe it is some error in the operation of the component ??

          Comment


          • #6
            I found a solution that validation works in both case settings (true / folse) for ListGrid and DataSource.

            The problem was performing Listgrid.sedID ("rs__TempImp_OsobaGrid"), which cleaned columns in the datasource, and thus did not see declarations of master keys and defined validators. I detected this when I wanted to look at the column from the table directly in the listgrid to check if everything works ok at this stage.

            Now I have a different problem for it:
            dataSource_rsTempImpCSV = DataSource.get ("_ rs__TempImp_OsobaGrid");

            completely creates the DataSource object and then I can not add another column to it dynamically. I get a message in the browser console:

            Fields cannot be added to a DataSource after the underlying component has been created.


            Thus, I am unable to add another columns from the CSV file that I am interested in, and I have to add them to read the data from the CSV. How to do it ??

            Comment


            • #7
              Hi, it's me again, but now I can add additional columns to ListGrid :).

              Instead of adding columns from the data in the form of a csv file to DataSource (which I did now), it adds them directly to Listgrid.
              Thanks to this, I have one column in the .ds.xml file that correctly starts remote data validation and additional columns added to ListGrid.

              Everything would be fine, but two problems arose:

              - added validators in ClientOnly mode which I added from the level of java to DataSource and worked, are now added to ListGrid and do not start - and there is also no error message
              .
              - in the amount of 600 remote validation launches (one for each row, and there can be many more) the web browser hangs for a few moments and after a few next moments displays a window with the following message:

              Validator DMI invocation threw exception: org.hibernate.exception.GenericJDBCException with error: Can not open connection

              As a result, the last pair of records are not validated

              Hence two questions:
              1. Can I add a validator in clientOnly mode to Listgrid, to a column that is not reflected in the .ds.xml file?
              2. Where in the configuration can I increase the connection pains for hibernate and whether this is possible assuming that it can be run from 100 to 5000 validations.?

              Comment


              • #8
                1. you can't, we covered this. You should not be in clientOnly mode if you intend to contact the server. Note how we named it "client only". As in no server.

                2. this is a Hibernate question - wrong forum

                Comment


                • #9
                  Thanks for the answer.
                  In the meantime, I've come to the fact that the number of connections from the database is dependent on the database server itself. Although I noticed on the database server itself that you are creating a series of connections to the server, which then are not released and go into a sleep state. It is possible that I set up something wrong in the project itself, but it is a problem for another time.

                  I have the impression that we do not quite understand the validation and configuration of components in relation to what I need and what I found in the documentation that it is possible to do.
                  I will pass another question that may help.

                  Can I dynamically create a Listgrid object from Java and add, for example, two fields to it and set IntegerRange validation in the range 1-5 between them without having a DataSource connected to it ??

                  My tests have shown that such a validator, which is supposed to function only on the client's side and verify, for example, ranges of entered data does not work, and no communication with servers is needed here.

                  However, if I dynamically create a DataSource in ClientOnly mode and add to it the example of the above mentioned validator, in addition to the remote validator that requires the ds.xml file, everything works fine.

                  I wanted to dynamically add a field to DataSource from Java, which was previously initialized from the ds.xml file (as suggested), but this is not possible because I receive a message: Fields can not be added to a DataSource after the underlying component has been created.
                  I thought about giving the fields instead of the DataSource to ListGrid.
                  As my tests showed, when the new field added is not reflected in the DataSource, the validators do not work. And this is exactly the case with me.

                  Hence my question how to solve this problem?

                  To sum up:
                  - I want to display in the ListGrid for example 5 columns with data that can be modified. I have to add some validators to each column. The first column must validate its values ​​based on the database, and the remaining ones based on validators, for example IntegerRange type, from the range 1-5 (depending on the data provided in csv file, the number of such columns may be different). In addition to the validation of only the first column, there is no other communication with the server and there is no question of any attempt to save data to the database. Only verification, nothing more.
                  From what I found in the documentation and here on the forum (https://forums.smartclient.com/forum...lidation-issue) it is possible when the properties are set:
                  • ListGrid.setSaveLocally(true);
                  • ListGrid.setUseRemoteValidators (true);
                  • DataSource.setClientOnly (true);
                  In this forum thread, it was about blocking all communication with the server responsible for writing data from ListGrid to the database, and only allowing validation. For me, the case is similar with the difference that only one column reflects the table in the database, and the other columns are dynamic virtual columns, which must verify their values ​​based on the validated validators. In addition to remote validation, everything is supposed to work on the client's side.
                  My problem is that depending on how I implement the support for loading and hooking fields, only the remote validation works, but the validation of the other dynamics, no or vice versa, validation of dynamic fields works, but the remote validation does not work.

                  Perhaps I can add a field to the DataSource ds.xml file that was just initialized a moment ago? - it would solve all problems :)

                  I apologize for the lengthy post and my English (google translator is my friend ;)), but I try to explain as accurately as possible what I mean and what I can manage to achieve and with what effect and conclusions created along the way.

                  I will be grateful for your help, best regards

                  Comment


                  • #10
                    As we previously covered, you can dynamically create a .ds.xml DataSource with Dynamic DataSource Generators. That would solve all of your problems, so that's why we mentioned it first.. we're not sure why you're still ignoring that path.

                    As far as the current approach you're taking, yes you can add validators at the ListGrid level that are not present in the DataSource. However, validators in general are only run for data that is edited. When you load data from a DataSource or supply it via setData(), it's assumed valid. If you want it to be treated as edited data, you need to supply it as editValues, via setEditValues() or via startEditingNew(values) if you want the whole thing treated as an unsaved record for validation purposes. This may clear up questions as to why validation isn't happening.

                    Comment


                    • #11
                      Thanks for answering and it's so fast.

                      Everything works!!!.
                      I had an error in the code incorrectly counting indexes, on ListGrid, on which I turned on the option of showing line numbers. In addition, the validators are added based on the column names and here an error in the application logic has crept in and the validators have not added to the corresponding columns.

                      I've detected this by accident adding another functionality. When I worked on columns based on DataSource, I did not have to omit the column numbering the lines in ListGrid, and I did not pay attention to my own message which I am displaying to the user about incorrect data (initial validation of data in the csv file). In addition, I cleared every cache I found.

                      I chose the second proposed solution because it seemed easier and faster to impelment :)

                      It also applies the aforementioned method of data input via editValues, which is called when the user clicks the button.

                      Many thanks for the time spent and the desire to read my long posts.


                      ps.
                      A quick additional question in this thread from another category:
                      Does SmartGwt 6.1p or GWT CORE have a built-in JSON parser on the client side or maybe there is some other free library to use ??

                      Comment


                      • #12
                        HTML5 itself provides a built-in parsing engine. If you need to support older browsers, there are multiple free libraries, or just use eval().

                        Comment


                        • #13
                          I think I lied a little.
                          It turned out that I still have one more problem.
                          Visual validation itself works. On the listgrid after clicking on the button, the fields in which errors occur nicely mark, but from the level of Java for the column having remote validation is not visible problem, that there was an error. Thus, I am not able to block the further activity of the user because the system can not see the error even though ListGrid displays it.

                          Is this the result of the async operation of the component in remote validation or maybe something wrong?

                          I enclose a piece of code executed during validation on button click:.

                          Code:
                                      listGrid_Wyniki.saveAllEdits ();
                                      SC.logWarn ("number of rows:" + listGrid_Results.getTotalRows ());
                                      for (int row_num = 0; row_num <listGrid_Results.getTotalRows (); row_num ++) {
                                        SC.logWarn ("row_num:" + row_num);
                                        // ListGridRecord rec = listGrid_Results.getRecord (row_num);
                                        ListGridRecord rec = (ListGridRecord) listGrid_Results.getEditedRecord (row_num);
                          
                                        Map <String, String> lgWyn_map = new HashMap <String, String> (); // 1.07
                                        for (int i = 0; i <fieldsList.length; i ++) {
                                          String colName = fieldsList [i] .getName ();
                                          String colVal = rec.getAttribute (colName);
                                          lgWyn_map.put (colName, colVal);
                                        }
                          
                                        if (lgWyn_map.size ()> 0)
                                          listGrid_Wyniki.setEditValues ​​(row_num, lgWyn_map);
                          
                                        if (! listGrid_Results.validateRow (row_num)) {
                                          err_message += "Error validating read data !!!, line:" + Integer.valueOf (row_num + 1) + "<BR>";
                                           SC.logWarn ("Error in line ::" + Integer.valueOf (row_num + 1));
                                          setCzyWystapilJakisBladDanych (true); // Mark the boolean variable that an error has occurred
                                        }
                                      }
                          
                                      listGrid_Wyniki.saveAllEdits ();

                          Comment


                          • #14
                            You only said that the system doesn’t seem to recognize the error, but what specifically is happening that you do not want?

                            Comment


                            • #15

                              Hmm, I would like to know that there was an error in the remote validation and be able to properly handle it. The fact that the ListGrid itself displays the appropriate icon informing that an error occurred is not enough. The function for the validation of the remote listGrid_Results.validateRow (row_num) in the event of an error should return false, but returns true. This happens only in the case of remote validation.

                              if (!listGrid_Wyniki.validateRow(row_num)) {
                              SC.logWarn("Error in line:: " + Integer.valueOf(row_num + 1));
                              setCzyWystapilJakisBladDanych(true); // Mark the boolean variable that an error has occurred
                              }

                              Comment

                              Working...
                              X