cancel
Showing results for 
Search instead for 
Did you mean: 

Identifying the Enter pressed by the user in the Inputfield

Former Member
0 Kudos

Hi all,

We have one Comment field on Portal screen that is given by the user (User may press enter while giving the comments). We are sending that field value to R3 through RFC and when we are getting back that comment field value from R3 we need to identify the Enter pressed by the user. We are writing the code for identifying "/n" in that comments field but that is not working. Can anyone help me out in this? This is really urgent.

Thanxs in advance!!!

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

You can write the code onActionEnter for your UI Element. In this you can append a "\n" to the comment everytime an enter is pressed. The comment text you can get from the context attribute mapped to the UI element.

Suppose you have the text entered as "AAAA" and an enter pressed and then "BBBB". Now after appending the "\n" it will go to backend as "AAAA\nBBBB ".

If you take the same data while retrieving it, i.e without any manipulation for "AAAA\nBBBB " the string from the backend, it will display as:

AAAA

BBBB

in your UI. Hope you are using TextEdit UI for user comments.

thanks & regards,

Manoj

Former Member
0 Kudos

Hi Manoj,

Thanxs for th reply.. I am using TextEdit for comments field.Problem is when I am getting the comments field I have find out where user has press the Enter key because I want to replace the NewLine with space. For eg: If user has enter

AAAA

BBBB

then when I am getting back I want to show that as

AAAA BBBB. When I am writing the code for replacing /n with space it is not recognizing /n. Is there any way to do this?

Former Member
0 Kudos

Hi Gurmat,

Now i got your exact problem.

Hence i am extremely sorry for my previous reply which was completely wrong.

There is no onEnter action associated with textEdit UI. Therefore it is not possible to track when user has pressed enter. Another thing is that if you try to print the comments entered by the user as:

AAAA

BBBB

it will print it as normal AAAA BBBB, but in textEdit it will take it as:

AAAA

BBBB

If the text entered is:

AAAA BBBB

then also it will print it as normal AAAA BBBB.

Well i hope the other gurus here will have some idea about the wrapping of textEdit UI.

thanks & regards,

Manoj

former_member197348
Active Contributor
0 Kudos

Hi Gurmat,

You can find out and replace the new-line character with any character in TextEdit using String methods like this.

e.g. If the context attribute text is bound to the TextEdit.

You need to get the attribute and replace it

String newText = wdContext().currentContextElement().getText().replace('\n','#' );

Now newText contains the string which replaces '\n' with '#'

In place of '#' you can use whichever character you want.

By default one space i.e.' ' is added at the end of each line.

regards,

Siva

Former Member
0 Kudos

Thanks Shiva and Manoj for understanding the problem.

Shiva, I tried doing the same thing but the code is not able to read "/n".

Gurmat

Former Member
0 Kudos

sorry "\n"

Former Member
0 Kudos

Hi,

Ya even i tried the same thing. Because there is no "\n" between the sequence of Strings.

thanks & regards,

Manoj

former_member197348
Active Contributor
0 Kudos

Hi Gurmat,

It is surprising. Actually I too had doubt regarding this, so I tried and worked out successfully before posting the previous message. I used the same code to replace '\n'.

I have given the below input in TextEdit:

Siva (pressed enter)

Rama

I got output as:

Siva #Rama

I don't think you are doing this mistake but just to confirm: Are you using single quotes ' ' or double quotes ""?

You must use single quotes.

regards,

Siva

Former Member
0 Kudos

Hi Shiva,

What you said is absolutely correct. But it doesn't solve the problem.

You can check it. For example you have entered:

Siva (pressed enter)

Rama

You got output as:

Siva #Rama

But in the textEdit you will get the output as:

Siva

#Rama

The linebreak is still there.

thanks & regards,

Manoj

former_member197348
Active Contributor
0 Kudos

Hi Gurmat and Manoj,

Do you want to replace the TextEdit too? I thought only to print or send to backend. No problems. We can do change in TextEdit as well.

My input in TextEdit is:

How

are

you

Manoj?

After button click I got output in TextEdit and TextView(I used button to trigger event):

How are you Manoj?

In onActionButton() my code is:

StringBuffer buffer = new StringBuffer(wdContext.currentContextElement().getText());

for (int i = 0,index=buffer.indexOf("\n"); i < buffer.length(); i++) {

if(i==index){

buffer.replace(i-1, i+1," ");

index = buffer.indexOf("\n");

if (index==-1)

break;

}

}

In StringBuffer use "" only

regards,

Siva

Former Member
0 Kudos

Hi Siva,

I believe that this is the requirement of Gurmat.

Thats the solution. Thanx.

Hope Gurmat will also agrees with it.

thanks & regards,

Manoj

Former Member
0 Kudos

Hi Siva/Manoj,

This works for me ...thanks alot. I have given you the points.

Gurmat

former_member197348
Active Contributor
0 Kudos

Hi Gurmat,

I did not get clear idea of your problem. I assume for comment input field you are using onEnter action and appending "/n" to the text.

You need to use "\n" as a new-line character but not "/n".

regards,

Siva