Search code examples
javagwtgwt2

how to trim text of richtextarea in gwt


I have used "RichTextArea" in GWT. Now i want to trim the text of the richtextarea.gettext() when i am submitting the form.

But if i have only entered spaces and enter key in my textarea then richtextarea.gettext() will not going to trim it as it will convert them to &nbsp and < br>.

Any suggestion if there are only entered spaces and enter key in my textarea then on trim it should give me blank string value?


Solution

  • That you get &nbsp and < br> is the correct value what you get from the RichTextArea because it supplies HTML.

    Implement your own trim-method:

    public String trim(String s) {
    
       String result = s.trim(); 
       String x = result.replaceAll("<br>", "");
       x = x.replaceAll("&nbsp", "");
       x = x.trim();
       if(x.equals("")) {
           return x;
       } else {
           return result;
       }
    }