cancel
Showing results for 
Search instead for 
Did you mean: 

InputField Numeric Only

Former Member
0 Kudos

Hello All.

How to restrict inputFields in WebDynpro Java to numbers only ?

Thanks in advance..

Taylor

Accepted Solutions (1)

Accepted Solutions (1)

SandipAgarwalla
Active Contributor
0 Kudos

Taylor,

Add a validating action for the inputfield which would check if its numeric or not,

here is how to check,


public void checkIfNumeric( java.lang.String fieldName )
  {
    //@@begin checkIfNumeric()
	IWDMessageManager msgMgr = wdComponentAPI.getMessageManager();
	String fieldValue = wdContext.currentVaSearchFiltersElement().getAttributeAsText(fieldName);
	IWDAttributeInfo attributeInfo = wdContext.nodeVaSearchFilters().getNodeInfo().getAttribute(fieldName);	
	try{	
	Integer.parseInt(fieldValue);		
	}catch(NumberFormatException nfe){
		msgMgr.reportContextAttributeMessage(wdContext.currentVaSearchFiltersElement(),attributeInfo,IMessageSecurityReportComp.ROB__VER__NOT__NUMERIC,
		null, true);
	}
    //@@end
  }

In the fieldName - pass the context attribute name and modify the node and sttribute info as required..

Sandip

Former Member
0 Kudos

Hello Sandip.

Thanks for send the validation code.

Its work fine.

Points add.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Create Context attribute and type is integer

and write the java code for numeric restriction

Regards,

Manivannan P

Former Member
0 Kudos

If the "value" property is bound to some numeric dictionary type, you don't need to write any validation code, this happens automatically.

Armin

SandipAgarwalla
Active Contributor
0 Kudos

Armin,

If you bind the attribute to a dictionary type, can you validate numbers wiht decimal digits e.g. 5.6?

Thanks

Sandip

former_member191569
Active Participant
0 Kudos

As Armin said, WebDynpro framework will validate the data types in the next server round-trip (if it is a validating action).

In the numeric dictionary data type it can be defined the number of decimal digits, so you can also validate it.

Hope it helps,

David

Former Member
0 Kudos

Use "float" or create your own DDIC type with built-in type "float".

Armin