cancel
Showing results for 
Search instead for 
Did you mean: 

DropDownByKey problem!

Former Member
0 Kudos

Hi all,

Have a doubt about DropDownByKey UI Element.

I have a DropDownByKey with information from a Simple Type from my Local Dictionary. I when I run my application, I have to compare the value that I select from my Dropdownbykey with another string... he code I'm using for this is..

String str1 =

(String) wdContext.currentContextElement.getcontext1();

String str2 =

(String) "Test";

if (str1 == str2) {

//do something

}

else {

//do something

}

So, the problem is...when I try to compare this two strings and I already know they are the same, the program also takes de else option and never goes throught the if condition.

Please, help me with this...

Thanks in advance,

Jesus

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Jesus,

Just a wild Guess...! Are you using '==' to compare the strings. (It compares the objects). If so use .equals() or .equalsIgnoreCase().

If this is not the case, pls let me know. I'll send you the code for this.

Hope this helps,

Best Regards,

Nibu.

Former Member
0 Kudos

Ok, Thank you very much to Nibu and Santhosh. It was very helpful your answer and it helped me to sove my problem.

Regards,

Jesus

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Jesus,

Change the if condition like the following

if (str1.equals(str2)) {

//do something

}

else {

//do something

}

This should solve your problem

Regards,

Santhosh.C

Former Member
0 Kudos

hi

What do you mean by "<i>So, the problem is...when I try to compare this two strings and I already know they are the same, the program also takes de else option and never goes throught the if condition.</i>"

Well say you have a simple type element called ST_List which has a set of values like Blue, Yellow,Orange etc.

Now you create a context attribute say str1 which is of type ST_List.

Now check with .equals .

In the onSelect event of dropdown write code like

String dropdownvalue = wdContext.currentContextElement().getStr1();

String otherStr = "Blue";

if(dropdownvalue.equals(otherStr))

{

///do code

}

else

{

///do code

}

Well moreover see when you say wdContext.currentContextElement().getStr1() it will get you the current selected element. Now when you are comparing with the otherStr and as per your post you say you have fixed it as some value. Now only if the selected value from the dropdown matches the otherStr then it would go into the else and execute it. Just a thought. I dont know what exactly you meant by that line but just in case do let me know if it worked.

regards

ravi