2.9.0 ListBox getItemText(i) trims result [possible bug]

71 views
Skip to first unread message

Joker Joker

unread,
Dec 25, 2020, 7:11:54 AM12/25/20
to GWT Users
I have an issue with GWT 2.9.0 ListBox#getItemText():

String name = listBox.getItemText(i);

The result is a string with extra spaces removed at the end.

Have anybody run into the same problem?

Browser - Chrome/Firefox(latest)


Joker Joker

unread,
Dec 28, 2020, 2:11:28 AM12/28/20
to GWT Users
I think I found the reason. It's the JS Implementation of  OptionElement#setText.
It discards the last spaces in the string. I see that in debugger. 
Here method input parametr "String text" contains space symbol at the end. 
But after executing  the line "this.text = text;"
this.text contains string without space symbol at the end; 

So do I need to replace all leading and trailing white space characters with " "?

OptionElement.java:
/**
* The text contained within the option element.
*/
public final native void setText(String text) /*-{
this.text = text;
}-*/;

пятница, 25 декабря 2020 г. в 16:11:54 UTC+4, Joker Joker:

Joker Joker

unread,
Dec 28, 2020, 2:34:30 AM12/28/20
to GWT Users
This html example explains the source of problem. 
I don't know why JS implementaion of ListBox doesn't mask space symbol with  
It's a normal practic for JS implementations for GWT components?

<!DOCTYPE HTML>
<html>
 <head>
  <meta charset="utf-8">
  <title>Тег OPTION</title>
 </head>
 <body> 

  <form action="option1.php">
   <p><select size="5" name="hero">
    <option disabled>     Выберите героя    </option>
    <option value="t1" selected>&nbsp&nbsp&nbsp&nbsp&nbspЧебурашка</option>
    <option value="t2">Крокодил Гена&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</option>
    <option value="t3">Шапокляк</option>
    <option value="t4">Крыса&nbsp&nbsp&nbsp&nbsp&nbspЛариса</option>
   </select></p>
   <p><input type="submit" value="Отправить"></p>
  </form>

 </body>
</html>



понедельник, 28 декабря 2020 г. в 11:11:28 UTC+4, Joker Joker:

Joker Joker

unread,
Dec 28, 2020, 7:21:03 AM12/28/20
to GWT Users
And workaround is to encode all string put into/extracted from list with function:

private String encodeString(String s) {
  StringBuilder sb = new StringBuilder(s.trim().replaceAll(" +", " "));
  return sb.toString();
}

Maybe this will help someone
понедельник, 28 декабря 2020 г. в 11:34:30 UTC+4, Joker Joker:
Reply all
Reply to author
Forward
0 new messages