Bean Shell Validator Must Fill Value Not working

Confluence User - 23 Mar, 2022

Hi, i wan to use bean shell validator for must fill and range value. But for must fill value is not working. Here is my script:


if(Integer.parseInt(values[0]) == ""){

formData.addFormError("total_value", "Please fill the value"); //not working

return false;

}else if(Integer.parseInt(values[0]) < 3000){

formData.addFormError("total_value", "Value must between 30001-4000."); //working

return false;

}else if(Integer.parseInt(values[0]) > 4000){

formData.addFormError("total_value", "Value must between 30001-4000."); //working

return false;

}

else{

return true;

}


forms;userviews;user

5


24 Mar, 2022
confluenceUser
confluenceUser

Hi, the problem is that after converting the value into an integer, you are comparing it to an empty string. You need to perform comparison using the same types.

Integer.parseInt(values[0]) == ""



24 Mar, 2022
confluenceUser
confluenceUser

Hi, it is impossible for a primitive type like int to be null or empty. You can try to initialize a variable with -1 (to indicate negative value) and assign Integer.parseInt(values[0]) to it, then check if it's still equal to -1 after the assignment.

Try to refer to this: https://stackoverflow.com/questions/13747859/how-to-check-if-an-int-is-a-null

25 Mar, 2022
confluenceUser
confluenceUser

so instead use this how can i call the field id on joget?

if(  ................   == "")

30 Mar, 2022
confluenceUser
confluenceUser

Try using values[0] directly without calling Integer.parseInt.

31 Mar, 2022
confluenceUser
confluenceUser

ok tq..

RELATED QUESTIONS

Your answer


To answer a question you'll need an account.

Print