cancel
Showing results for 
Search instead for 
Did you mean: 

Query about Text Field

Former Member
0 Kudos

Hi,

1)I have a text field.In that text field i can only enters numbers.If suppose someone enters something other than numbers,then it should display a message that "Enter Valid number".How can i do this?

2)I have an application.Suppose i want to create a new user,then it should display a auto generated number in UserID field.How can i do this?

Thanx & Regards

Anirudh

Message was edited by: Armin Reichert

(deleted exclamation marks)

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

For query 1) you can do this:

try
{
    int i = Integer.parseInt(wdContext.currentContextElement.myfield);
}
catch (NumberFormatException e)
{
   wdComponentAPI.getMessageManager.reportContextAttributeMessage(nodelement,attribute,messageItem, object[]{},false);

}

For query 2, auto-generation usually has persistency involved. Is this persistency in R/3 ? If yes and maintained as a number range in SNRO transaction, you can use NUMBER_GET_NEXT function module to retrieve the next number.

Regards,

Subramanian V.

Answers (5)

Answers (5)

Former Member
0 Kudos

hi

here r the solutions for your Queries plz try.

try

{

int i = Integer.parseInt(wdContext.currentContextElement.myfield);

}

catch (NumberFormatException e)

{

wdComponentAPI.getMessageManager.reportContextAttributeMessage(nodelement,attribute,messageItem, object[]{},false);

}

Plz set the identity column property to 'yes' in the design of that DB table using Enterprise manager.

or

in query analyzer you can include the following line while creating table.

<column name> <datatype> identity(<start from>,<increment>)

strat from -> starting number like 1 or 10 etc..

increment -> increment value like 1 or 2..

this will generate an auto numbers in that column and we need not to insert.

FYI : kindly dont forget to reward points.

Former Member
0 Kudos

for Query 1, you can bind the integer datatype attribute to the text field. then if you enter other than numbers, it will handle the validation and raise the exception with a messsage.

for Query 2,

type 1: you can set the identity column property to 'yes' in the design of that DB table using Enterprise manager.

type 2: in query analyzer you can include the following line while creating table.

<column name> <datatype> identity(<start from>,<increment>)

strat from -> starting number like 1001 or 100001 etc..

increment -> increment value like 1 or 2..

it will generate auto numbers in that column.we need not to insert.

Former Member
0 Kudos

Hi,

1.Parse the context attribute of type string,as

try

{

Integer.parseInt(wdContext.currentContextElement.get<Attribute>);

}

catch(Exception e)

{

wdComponent.getMessageManager().reportWarning("Your message of validation");

}

}

2.If u use database means , find the maximum and add to that and display

Regards,

Saravanan K

Former Member
0 Kudos

One correction: It does not raise an exception but displays an error message on that context

Former Member
0 Kudos

For query 1: If you are not really particular about what error message should be displayed, then you can bind the input field to a context attribute of type 'integer'. Web Dynpro will do the validation and raise a context validation exception for you.

suresh_krishnamoorthy
Active Contributor
0 Kudos

Other way to validate field. keep all validation for number, Id and alphanumeric in java class inside webdynpro project.

Use that java class for validation

Validation.java:

public boolean numberValidation(String number) {

final char[] numbers = number.toCharArray();

int count=numbers.length;

for (int length = 0; length <count; length++) {

letter = numbers[length];

if ((letter >= '0') && (letter <= '9')) continue;

return false; // invalid

}

return true; // valid

}

In webdynpro

if (EmpID ==null || EmpID.trim().length()==0 ){

manager.reportContextAttributeMessage(

context,attributeInfo,

IMessageEmpComponent.EmpID_NULL,new Object[]{""},true);

}else if(!validation.numberValidation(EmpID)){

manager.reportContextAttributeMessage(

context,attributeInfo,

IMessageEmpComponent.EMP__INVALID,new Object[]{""},true);

}

manager.raisePendingException();

Second Question: waiting for experts reply.

Regards

Suresh KB