cancel
Showing results for 
Search instead for 
Did you mean: 

Validating empty spaces in Input field.

Former Member
0 Kudos

Hi,

I'm having an input field. if user enters blank space over there and tries to save it, i need an exception.

i need taa validation for that. how to validate for empty spaces on click of an action

Thanks & Regards,

Suresh

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

if your input field is binded to attribute under nodexxxx then follow this code:

IWDMessageManager msgMan = wdControllerAPI.getComponent().getMessageManager();

// Get field value of attribute under investigation

String value = wdContext.node<xxx>.currentxxxElement().getAttributeAsText(fieldname);

// Check if any input is provided

if (value.length() == 0) {

// if not: report error, which is related to context attribute under investigation

msgMan.reportContextAttributeMessage(

wdContext.nodexxx().currentxxxElement(),Attr,

IMessageEx7Comp.MISSING_INPUT,new Object[] { fieldname },true);

}

here MissingInput is the error defined in message pool of componenet to display "Entry of a valid is required for proceeding." when no input is given for the input field.

Former Member
0 Kudos

Hi

If you want to validate value only on some action, you must write validation code into action handler:


final String value = wdContext.current<your node>().get<your attribute>();
if (value.trim().length() == 0) {
  wdComponentAPI.wdGetMessageManager().reportInvalidContextAttributeException(
    wdContext.current<your node>(),
    wdContext.node<your node>().getNodeInfo().getAttribute("<your attribute name">),
    "<message about wrong value>",
    true);
}

But if you want to use WD validation mechanisms, set corresponding ISimpleValueServices instance for your attribute simple type.

Former Member
0 Kudos

Hi,

Inside the action try this.

String Input=wdContext.current<node>Element().get<inputfield>();

if(Input== null || Input== "" || Input== " " || Input.trim().equalsIgnoreCase("")){

wdComponentAPI.getMessageManager().raiseException("Please Enter the Value.",false);

}

Hope this helps!!!!!

-Swati

Former Member
0 Kudos

Hi,

Use the given code

if(wdContext.currentContextElement.get<InputFieldVal>.equals(""))

{

wdComponentAPI.getMessageManager().reportException("Message",false);

}

Regards,

Padma N

|

Former Member
0 Kudos

Hi,

You can do the required validation as:

if(null == wdContext.current<ur_node>element().getIpFld() || wdContext.current<ur_node>element().getIpFld().trim().equals(""))
{
        //. . . Raise exception or render error message
        wdComponetAPI.getMeassageManager().reportexception("Your Error Message",false);
}
else
{
       //. . . Continue processing 
}

Regards,

Alka.

srinivas_sistu
Active Contributor
0 Kudos

Hi,

you cant use a trim function as trim() is a compare type function. Means it works if and if there is atleast on character in the string...

String s="test ";

now s.trim() works but if

String ss=" ";

now ss.trim() will not work...

and if

String strst=" ";

then

if(strss==null) will also not wok, as string has a space characte inside it...

Regards,

Srinivas

Former Member
0 Kudos

Hi shrinivas,

Try executing this:

String empty = " ";
		
System.out.println(empty.trim().concat("Plus"));
System.out.println(empty.concat("Plus"));

Best Regards,

Alka.