I'm using GWT 2.4. I have a form in which I create a submit button like so
private Button createSaveButton() {
final Button saveButton = new Button("Save");
saveButton.getElement().setAttribute("name", SaveXmlServlet.SAVE_BUTTON_PARAM_NAME);
saveButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
formPanel.submit();
}
});
return saveButton;
} // createSaveButton
I define an onComplete handler for the form like so
formPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() {
@Override
public void onSubmitComplete(SubmitCompleteEvent event) {
Window.alert(event.getResults());
}
});
The servlet I submit the form to returns results as plain text.
res.setContentType("text/plain");
final PrintWriter out = res.getWriter();
out.print(saveSucceeded);
out.close();
However, when I actually do the alert, it will attach "<pre>" tags to the output. For example, if the servlet outputs "true", what is alerted to the user is "<pre>true</pre>". How do I get this only to output what was written to the response? I could do some string manipulation to remove the "<pre>" tags, but that seems like I'm not addressing the core issue. Thanks, - Dave
There is another solution - to set content type to text/html
.
I don't think you can do anything about that, but it's easy to work around without weird text manipulations:
public String getPlainTextResult(SubmitCompleteEvent event) {
Element label = DOM.createLabel();
label.setInnerHTML( event.getResults() );
return label.getInnerText();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With