One Star

[resolved] tmsbox, tjava

HI,
I use a tmsgbox : question (TOS 4.2.3) link (onComponentOK) to tjava component . I want to say what's value the OK and Cancel buttons return.
I want to test what's button the user click, in the tjava component.
This is the code i use in tjava component :
String result=(String)globalMap.get("tMsgBox_1_RESULT");
if(result.equals("0")){ //You have clicked on 'Yes' button
globalMap.put("continues", true);
}
if(result.equals("1")){ //You have clicked on 'NO' button
globalMap.put("continues", false);
}
but it don't work.
Best regards
1 ACCEPTED SOLUTION

Accepted Solutions
Moderator

Re: [resolved] tmsbox, tjava

Hi, Fab972
Thanks for your attention on Talend. From your code:
String result=(String)globalMap.get("tMsgBox_1_RESULT");
if(result.equals("0")){ //You have clicked on 'Yes' button
globalMap.put("continues", true);
}
if(result.equals("1")){ //You have clicked on 'NO' button
globalMap.put("continues", false);
}

You will get three results:
1. If the user typing answer?such as ?i am Fab972?, click ok, the value of (String)globalMap.get("tMsgBox_1_RESULT") is "i am Fab972",
2. if the user don't input any answer, click directly OK button, the value of (String)globalMap.get("tMsgBox_1_RESULT") is "" //it is an empty string
3. if the user click Cancel button, the value of (String)globalMap.get("tMsgBox_1_RESULT") is null
So, the return value of (String)globalMap.get("tMsgBox_1_RESULT") is not 1 or 0, the returned value are the three cases as above.
For testing, you can use print the return value on the console using this code:
System.out.println((String)globalMap.get("tMsgBox_1_RESULT") );

. And you can change the code to :
if(result==null){ //You have clicked on 'Cancel' button
globalMap.put("continues", false);
}else{
//You have clicked on 'Yes' button
globalMap.put("continues", true);
}

Hope it will help you!
Best Regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
4 REPLIES
Seventeen Stars

Re: [resolved] tmsbox, tjava

I have no idea whats wrong with your code. For me it works perfectly!
Seven Stars

Re: [resolved] tmsbox, tjava

If you're using the Question option for tMsgBox then (String)globalMap.get("tMsgBox_1_RESULT") contains the user input but is null if they click Cancel.
For all the other tMsgBox options, (String)globalMap.get("tMsgBox_1_RESULT") contains the number of the button clicked, starting from zero left-to-right.
Moderator

Re: [resolved] tmsbox, tjava

Hi, Fab972
Thanks for your attention on Talend. From your code:
String result=(String)globalMap.get("tMsgBox_1_RESULT");
if(result.equals("0")){ //You have clicked on 'Yes' button
globalMap.put("continues", true);
}
if(result.equals("1")){ //You have clicked on 'NO' button
globalMap.put("continues", false);
}

You will get three results:
1. If the user typing answer?such as ?i am Fab972?, click ok, the value of (String)globalMap.get("tMsgBox_1_RESULT") is "i am Fab972",
2. if the user don't input any answer, click directly OK button, the value of (String)globalMap.get("tMsgBox_1_RESULT") is "" //it is an empty string
3. if the user click Cancel button, the value of (String)globalMap.get("tMsgBox_1_RESULT") is null
So, the return value of (String)globalMap.get("tMsgBox_1_RESULT") is not 1 or 0, the returned value are the three cases as above.
For testing, you can use print the return value on the console using this code:
System.out.println((String)globalMap.get("tMsgBox_1_RESULT") );

. And you can change the code to :
if(result==null){ //You have clicked on 'Cancel' button
globalMap.put("continues", false);
}else{
//You have clicked on 'Yes' button
globalMap.put("continues", true);
}

Hope it will help you!
Best Regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: [resolved] tmsbox, tjava

Hi Sabrina,
Thanks for you reply. It's work.
best regards
Fab