Validation out of java action?

3
Can I do a "Show validation message" like used in the micrflows send out of java action? I try to do following: The user is working with a request with many attributes and a state. He's saving the request and if select a specific action on the request which will change the state some fields a required. The Java function shall receive the request an the mandatory field name and show the validation message. I created and call the action: CheckFilledAttributeOfObject(IMendixObject MendixEntityParameter1, String MendixAttributeParameter1) out of the microflow with the entity and the attribute name to validate. In the action I call a helper action: public boolean CheckFilledAttributeOfObject(IContext context, UserAction action, IMendixObject MendixEntityParameter1, String MendixAttributeParameter1) { String attributeValue = String.valueOf(MendixEntityParameter1.getMember(context, MendixAttributeParameter1).getOriginalValue(context)); if(attributeValue.matches("") || attributeValue == null || attributeValue.matches("null")) { Map<string,string> members = new HashMap<string,string>(); members.put(MendixAttributeParameter1, MendixAttributeParameter1 + "must be filled"); action.addDatavalidationFeedback(MendixEntityParameter1.getId(), members); return false; } else { return true; } } So I think I do not use the "addDatavalidationFeedback" in the right way? Thanks, Tobias
asked
5 answers
1

To use a microflow I think is no option. Than I have the same problem as before that I must create a validation message for every attribute again.

So I try to use the method "addDatavalidationFeedback" in the java action. But only adding it doesn't to anything. Someone know how to use it?

answered
1

See the addDatavalidationFeedback items in the core action API

Providing the MendixIdentfier of the object (should probably the same as on which the original microflow was invoked) and a HashMap of field -> error should do the trick. If it doesn't, can you describe the whole flow?

answered
0

You can at least invoke a microflow from a java action that does the message or throw an exception with a descriptive message but you have to handle that in the java action call. The disadvantage that your flow is stopped.

answered
0

I call the action:

CheckFilledAttributeOfObject(IMendixObject MendixEntityParameter1, String MendixAttributeParameter1)

out of the microflow with the entity and the attribute name to validate.

In the action I a helper action:

public static boolean CheckFilledAttributeOfObject(IContext context, UserAction action, IMendixObject MendixEntityParameter1, String MendixAttributeParameter1) { String attributeValue = String.valueOf(MendixEntityParameter1.getMember(context, MendixAttributeParameter1).getOriginalValue(context)); if(attributeValue.matches("") || attributeValue == null || attributeValue.matches("null")) { Map<string,string> members = new HashMap<string,string>(); members.put(MendixAttributeParameter1, MendixAttributeParameter1 + "must be filled"); action.addDatavalidationFeedback(MendixEntityParameter1.getId(), members); return false; } else { return true; } }

So I think I do not use the "addDatavalidationFeedback" in the right way?

answered
0

The following code snipped will do the trick.

Java Action with 3 parameter:

  1. ObjectToCheck(Object)
  2. AttributeName (String)
  3. Message (String)

    // BEGIN USER CODE
    IContext context = this.getContext();
    String attributeValue = String.valueOf(this.ObjectToCheck.getMember(context, this.AttributeName).getOriginalValue(context)); 
    Core.getLogger("CheckField").info("Member"+this.AttributeName +":"+attributeValue);
    if(attributeValue.matches("") || attributeValue == null || attributeValue.matches("null")) { 
        Map<String,String> members = new HashMap<String,String>(); 
        members.put(this.AttributeName, this.Message); 
        this.addDatavalidationFeedback(this.ObjectToCheck.getId(), members); 
        return false; 
    } 
    else { 
        return true; 
    } 
    // END USER CODE
    
answered