Announcement

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

    Validation message not displaying when using a serverCustor

    Hello,

    I have a field that I am trying to add a serverCustom validator, but when the validation fires, I don't get the error message displayed on the ListGrid.

    The validator looks like this:
    public class ServiceTypeValidator {
    private static final Logger log = LoggerFactory.getLogger(ServiceTypeValidator.class);

    @SuppressWarnings({"rawtypes", "unchecked"})
    public boolean condition(Object value, Validator validator, String fieldName, Map record, DataSource ds, HttpSession session) throws Exception {
    log.debug("ServiceTypeValidator");
    // validator.addErrorMessageVariable("CODE", "Ouch");
    return false;
    }
    }

    The validation in the datasource xml file looks like this:
    <validators>
    <validator type="required" />
    <validator type="lengthRange" min="6" max="6" />
    <validator type="serverCustom">
    <serverObject className="net.someproject.smartclient.validators.ServiceTypeValidator" methodName="condition"/>
    <errorMessage>I don't think so.</errorMessage>
    </validator>
    </validators>
    The "required" and "lengthRange" validators both work fine:
    Click image for larger version

Name:	required.png
Views:	343
Size:	10.3 KB
ID:	268412

    Here's the editing:
    Click image for larger version

Name:	Screen Shot 2022-08-03 at 9.06.20 AM.png
Views:	247
Size:	4.9 KB
ID:	268415
    Click image for larger version

Name:	Screen Shot 2022-08-03 at 8.35.38 AM.png
Views:	261
Size:	5.2 KB
ID:	268413

    But when I fire off the serverCustom validation, nothing shows up, though I see this in the log:
    === 2022-08-215 08:36:17.768 DEBUG ValidationContext - Adding validation errors at path '/L_PEC/CODE/CODE': {severity=ERROR, errorMessage=I don't think so.}
    === 2022-08-215 08:36:17.768 INFO Validation - Validation error: [
    {
    CODE:{
    severity:"ERROR",
    errorMessage:"I don't think so."
    }
    }
    ]

    Here it is stuck in "Pending" after the validations fire:
    Click image for larger version

Name:	Screen Shot 2022-08-03 at 8.35.50 AM.png
Views:	241
Size:	6.3 KB
ID:	268414

    It just sits there in a "Pending" state. So the ListGrid is prevented from saving the record.

    This happens whether the serverCustom is Java based or in Groovy.

    If I'm doing something wrong, please let me know. Maybe I'm missing a step.

    Environment:
    SmartClient Version: v12.1p_2021-11-02/Enterprise Deployment (built 2021-11-02)
    Chrome version 103.0.5060.134 (Official Build) (x86_64)
    Firefox 103.0 (64-bit)

    #2
    Hi pfincke,

    can you show the full field definition in CODE tags here (so it's nicely formatted) as well as the server answer from the Developer Console's RPC Tab (again in CODE tags)?

    Best regards
    Blama

    Comment


      #3
      We created a test case based on yours and tested against the latest 12.1p code, and all is working correctly. Our test implements the condition in Groovy rather than Java, but you say that also isn't working in your case, right? We added additional validators to one of the existing sample dataSources (worldDS) as shown below. This causes the server response shown (taken from the Developer Console RPC tab), and an error icon to appear in the ListGrid. This was the only change needed, and it does seem like you have done pretty much the same thing. Please verify that your test case does fail when the condition is implemented in Groovy, just so we know we are testing the same thing, and try your case with the latest 12.1p build.

      DataSource change:
      Code:
              <field name="capital"       type="text"       title="Capital"          >
                  <validators>
                      <validator type="required"/>
                      <validator type="lengthRange" min="1" max="40"/>
                      <validator type="serverCustom">
                          <serverCondition language="groovy"><![CDATA[
                              value.charAt(0) >= 'A' && value.charAt(0) <= 'Z'
                          ]]></serverCondition>
                          <errorMessage>Capital must start with a Capital!</errorMessage>
                      </validator>
                  </validators>
              </field>
      Server response:
      Code:
      {
          affectedRows:0,
          errors:[
              {
                  capital:{
                      severity:"ERROR",
                      errorMessage:"Capital must start with a Capital!"
                  }
              }
          ],
          invalidateCache:false,
          isDSResponse:true,
          operationType:"update",
          queueStatus:-1,
          status:-4,
          data:null
      }
      UI appearance:
      Click image for larger version

Name:	serverCustom.png
Views:	187
Size:	9.9 KB
ID:	268420

      Comment


        #4
        I am embarrassed to say it, but I've never once opened the RPC tab in the console. What I found on the update of our table is this:

        Code:
        {
            affectedRows:0,
            data:"Validator script evaluation threw exception: java.lang.Exception with error: Unable to load engine by name or extension: groovy. Please make sure you have the required JARs for this engine in WEB-INF/lib",
            invalidateCache:false,
            isDSResponse:true,
            queueStatus:-1,
            status:-1
        }
        This was using a Groovy validation. Which seems like more of a configuration error than anything. I'll try to test again with the Java code once I get my test back up and running and see what it says.

        Comment


          #5
          The mystery deepens. I decided to use an Email Address Validator we already have in place that I know works. The place it is used is on a DynamicForm. So not quite the same thing. But I found another editable grid and applied the email validator to the COMMENTS field.
          Code:
          <field name="COMMENTS" title="Comment" type="text" length="2147483647">
          <validators>
              <validator type="required"/>
                  <validator type="serverCustom">
                      <serverObject className="net.some.project.smartclient.validators.EmailValidator" methodName="condition" />
                      <errorMessage>Please enter a valid email address.</errorMessage>
                     </validator>
              </validators>
          </field>
          and then verified. It works great.
          Click image for larger version  Name:	Screen Shot 2022-08-04 at 3.56.40 PM.png Views:	0 Size:	17.2 KB ID:	268426

          I added the same validation to the ListGrid that's not working. I added it to both the CODE and the TITLE fields.
          Code:
          <field name="CODE" title="Code" showErrorIcons="true">
              <validators>
                  <validator type="required" />
                  <validator type="lengthRange" min="6" max="6" />
                  <validator type="serverCustom">
                      <serverObject className="net.some.project.validators.EmailValidator" methodName="condition" />
                      <errorMessage>Please enter a valid email address.</errorMessage>
                  </validator>
              </validators>
          </field>
          <field name="TITLE" title="Title">
              <validators>
                  <validator type="required" />
                  <validator type="lengthRange" min="1" max="60" />
                  <validator type="serverCustom">
                      <serverObject className="net.some.project.smartclient.validators.EmailValidator" methodName="condition" />
                      <errorMessage>Please enter a valid email address.</errorMessage>
                  </validator>
              </validators>
          </field>
          When I update this grid, the problem still occurs. Though I do see this as the Raw Response on the update operation:

          Code:
          {
              affectedRows:0,
              errors:[
                  {
                      TITLE:{
                          severity:"ERROR",
                          errorMessage:"Please enter a valid email address."
                      }
                  }
              ],
              invalidateCache:false,
              isDSResponse:true,
              operationType:"update",
              queueStatus:-1,
              status:-4,
              data:null
          }
          I'm still stuck in a pending state.
          Click image for larger version  Name:	bad.png Views:	0 Size:	12.9 KB ID:	268425
          So there's something whack-a-do about the one ListGrid that, having just proved above that the ListGrid *does* work with validations above, I suspect makes the issue fall on my plate and not yours.

          However... Should you choose to delve into the matter further or if you have some suggestion as to how to resolve it quickly, I would be grateful.

          As for Groovy? That's another story. The rumor I heard was that we weren't supporting Groovy in our application anymore.

          I just wish the individual that made that decision had gone through and replaced all the Groovy we have in there already.

          Comment


            #6
            And just like that, I get to wear the internet idiot hat for today. The first thing I changed on the grid was...

            Code:
            validateOnChange: true,
            It looks like this now:
            Click image for larger version

Name:	Screen Shot 2022-08-04 at 4.18.47 PM.png
Views:	248
Size:	18.3 KB
ID:	268428

            Thank you. I'll be here all week. Don't forget to tip your waiter or waitress.

            Comment

            Working...
            X