cancel
Showing results for 
Search instead for 
Did you mean: 

Implicit validation only work when the InputField has changed

Former Member
0 Kudos

Hi all,

we're trying to implement implicit validation.

When we define a DDIC type with minLenght 5 the inputfield is not automatically checked if the mapped value has the lenght of 5. The inputfield is only checked if the user changes it.

Is there a trick archieving implicit validation even if the user didn't change any inputfield?

Best regards,

Christian

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

The same happens if I use the isValid and checkValid functions. Before the user didn't change the InputField I always get true on this methods!

Any idea?

Former Member
0 Kudos

Yes, of course, if checkValid() doesn't throw a DdException, the value in the input field (or better context attribute) <b>is valid</b> against the constraints of the SimpleType. What do you expect? Am i missing something?

Best regards

Stefan

Former Member
0 Kudos

Hi Stefan,

for clearance. I have a DDIC with minLength 3 mapped to an atrribute a node "Test". In the supplyFunction of the node "Test" I create a new node element and initialize the attribute with an empty string.

This empty string is in my understanding not valid cause it's to short compared to DDIC definition. When I now call the isValid function I get true.

Afterwards I change the value in an mapped InputField in the view. It is still shorter than 3 characters. When I now run the isValid function I get false as I would expect it!

So in my understanding the context element is invalid (against the DDIC definition) all the time. But the isValid function only behaves correctly when the inputfield has been touched.

Did I missed something?

Best regards,

Christian

Former Member
0 Kudos

Hi Stefan,

I've detected another strage behavior of the WebDynpro context which is supposed to be connected to the topic above:

As long as the attribute is a String longer than zero the implicit validation works. When it comes to a length of zero the validation doesn't say that the string is too short. When I now try to get the string length while the string in the context is zero, I get an nullpointer!

Former Member
0 Kudos

Hi Christian,

no, it works as expected. Create a value node "TestNode" with an value attribute Name5 in the context. Name5's type is a SimpleType base string with MaxLength = 32, MinLength = 5. Add a supplyFunction to TestNode. Then insert the following code into the supply function (adapt the view name of course):

StringBuffer sb = new StringBuffer();
IWDAttributeInfo name5Info = node.getNodeInfo().getAttribute(IPrivateDTView.ITestNodeElement.NAME5);
ISimpleType name5Type = name5Info.getSimpleType();

for (int ix = 0; ix < 10; ix++) {
  IPrivateDTView.ITestNodeElement el = node.createTestNodeElement();
  node.addElement(el);
  el.setName5(sb.toString());
  sb.append('A');
}
/* Checking */
for (int ix = 0; ix < 10; ix++) {
  IPrivateDTView.ITestNodeElement el = node.getTestNodeElementAt(ix);
  try {
    name5Type.checkValid(el.getName5());
  } catch (DdCheckException e) {
    wdComponentAPI.getMessageManager().reportInvalidContextAttributeException(
      el,
      name5Info,
      "Hoppla, zu kurz: " + e.getMessage(),
      false);
  }
}

You'll get 5 error lines displayed by message manager for the strings with 0..4 characters.

Hmmm? Please check, if this works for you too.

Best regards

Stefan

Former Member
0 Kudos

Hi Christian,

no, it works as expected. Create a value node "TestNode" with an value attribute Name5 in the context. Name5's type is a SimpleType base string with MaxLength = 32, MinLength = 5. Add a supplyFunction to TestNode. Then insert the following code into the supply function (adapt the view name of course):

StringBuffer sb = new StringBuffer();
IWDAttributeInfo name5Info = node.getNodeInfo().getAttribute(IPrivateDTView.ITestNodeElement.NAME5);
ISimpleType name5Type = name5Info.getSimpleType();

for (int ix = 0; ix < 10; ix++) {
  IPrivateDTView.ITestNodeElement el = node.createTestNodeElement();
  node.addElement(el);
  el.setName5(sb.toString());
  sb.append('A');
}
/* Checking */
for (int ix = 0; ix < 10; ix++) {
  IPrivateDTView.ITestNodeElement el = node.getTestNodeElementAt(ix);
  try {
    name5Type.checkValid(el.getName5());
  } catch (DdCheckException e) {
    wdComponentAPI.getMessageManager().reportInvalidContextAttributeException(
      el,
      name5Info,
      "Hoppla, zu kurz: " + e.getMessage(),
      false);
  }
}

You'll get 5 error lines displayed by message manager for the strings with 0..4 characters.

Hmmm? Please check, if this works for you too.

Best regards

Stefan

Former Member
0 Kudos

Hi Christian,

no, it works as expected. Create a value node "TestNode" with an value attribute Name5 in the context. Name5's type is a SimpleType base string with MaxLength = 32, MinLength = 5. Add a supplyFunction to TestNode. Then insert the following code into the supply function (adapt the view name of course):

StringBuffer sb = new StringBuffer();
IWDAttributeInfo name5Info = node.getNodeInfo().getAttribute(IPrivateDTView.ITestNodeElement.NAME5);
ISimpleType name5Type = name5Info.getSimpleType();

for (int ix = 0; ix < 10; ix++) {
  IPrivateDTView.ITestNodeElement el = node.createTestNodeElement();
  node.addElement(el);
  el.setName5(sb.toString());
  sb.append('A');
}
/* Checking */
for (int ix = 0; ix < 10; ix++) {
  IPrivateDTView.ITestNodeElement el = node.getTestNodeElementAt(ix);
  try {
    name5Type.checkValid(el.getName5());
  } catch (DdCheckException e) {
    wdComponentAPI.getMessageManager().reportInvalidContextAttributeException(
      el,
      name5Info,
      "Hoppla, zu kurz: " + e.getMessage(),
      false);
  }
}

You'll get 5 error lines displayed by message manager for the strings with 0..4 characters.

Hmmm? Please check, if this works for you too.

Best regards

Stefan

Former Member
0 Kudos

Hi Christian,

obviously my last answer was lost (i can't see it). SDN is little bit tricky these days. I repost it here:

#############################

Hi Christian,

no, it works as expected. Create a value node "TestNode" with an value attribute Name5 in the context. Name5's type is a SimpleType base string with MaxLength = 32, MinLength = 5. Add a supplyFunction to TestNode. Then insert the following code into the supply function (adapt the view name of course):

StringBuffer sb = new StringBuffer();
IWDAttributeInfo name5Info = node.getNodeInfo().getAttribute(IPrivateDTView.ITestNodeElement.NAME5);
ISimpleType name5Type = name5Info.getSimpleType();

for (int ix = 0; ix < 10; ix++) {
  IPrivateDTView.ITestNodeElement el = node.createTestNodeElement();
  node.addElement(el);
  el.setName5(sb.toString());
  sb.append('A');
}
/* Checking */
for (int ix = 0; ix < 10; ix++) {
  IPrivateDTView.ITestNodeElement el = node.getTestNodeElementAt(ix);
  try {
    name5Type.checkValid(el.getName5());
  } catch (DdCheckException e) {
    wdComponentAPI.getMessageManager().reportInvalidContextAttributeException(
      el,
      name5Info,
      "Hoppla, zu kurz: " + e.getMessage(),
      false);
  }
}

You'll get 5 error lines displayed by message manager for the strings with 0..4 characters.

Hmmm? Please check, if this works for you too.

Best regards

Stefan

PS: If this answer appears multiple times, ignore it, since i'm currently getting exceptions posting it

Former Member
0 Kudos

Hi Stefan,

thanks a lot for your answer! Working with the checkValid function works as you descriped it. But the following code should have the same effect

 wdComponentAPI.getValidationCheck().isValidNodeElement(wdContext.currentTestnodeElement()) 

. Could you maybe try it in your test scenario?

The same function seems to be called by the implicit validation of the WD framework.

It behaves as described in the notes above. So if the attribute is set in the supplyFunction it returns true (=valid), the same happens if the InputField gets empty later on.

So in my opinion implicit validation couldn't be used at all?

Another thing I discovered is that I get an nullpointer when trying to access an context attribute if the context is an empty string, do you know about that?

Thanks again,

Christian

Former Member
0 Kudos

Hi Christian,

well this might be a little bit misleading. The isValidNodeElement() method checks, if you <b>reported</b> invalid context attribute messages before for any attributes of a node element.

So, without your checks and without invocation of the reportInvalidContext... method, the method does simply nothing, before the client does the implicit checks (this is the behaviour you mentioned before).

<b>You</b> are responsible to tell the message manager (which implements IWDValidationCheck finally), what is wrong.

The empty string works for me, mapped and unmapped, empty and null. This seems to be a problem with your version.

Hope that helps.

Best regards

Stefan

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Christian,

no, it works as expected. Create a value node "TestNode" with an value attribute Name5 in the context. Name5's type is a SimpleType base string with MaxLength = 32, MinLength = 5. Add a supplyFunction to TestNode. Then insert the following code into the supply function (adapt the view name of course):

StringBuffer sb = new StringBuffer();
IWDAttributeInfo name5Info = node.getNodeInfo().getAttribute(IPrivateDTView.ITestNodeElement.NAME5);
ISimpleType name5Type = name5Info.getSimpleType();

for (int ix = 0; ix < 10; ix++) {
  IPrivateDTView.ITestNodeElement el = node.createTestNodeElement();
  node.addElement(el);
  el.setName5(sb.toString());
  sb.append('A');
}
/* Checking */
for (int ix = 0; ix < 10; ix++) {
  IPrivateDTView.ITestNodeElement el = node.getTestNodeElementAt(ix);
  try {
    name5Type.checkValid(el.getName5());
  } catch (DdCheckException e) {
    wdComponentAPI.getMessageManager().reportInvalidContextAttributeException(
      el,
      name5Info,
      "Hoppla, zu kurz: " + e.getMessage(),
      false);
  }
}

You'll get 5 error lines displayed by message manager for the strings with 0..4 characters.

Hmmm? Please check, if this works for you too.

Best regards

Stefan

PS: If this answer appears multiple times, ignore it, since i'm currently getting exceptions posting it

Former Member
0 Kudos

Hi Christian,

you validate the context attribute the input field's value property is bound to. You can use one of the

boolean isValid(<type> value);

methods or the

void checkValid(Object o) throws DdException

method of the ISimpleType instance, if the context attribute has a simple type (since you defined a minLength, your attribute has a SimpleType ;). If false is returned or a DdException is thrown, you can call one of the

reportInvalidContextAttributeException()

methods of the IWDMessageManager API.

Hope that helps.

Regards

Stefan