在GWT ValueTextBox中呈现前导/尾随空格

在GWT ValueTextBox中呈现前导/尾随空格,gwt,Gwt,我正在用特定类型扩展GWT中的ValueListBox。构造函数需要一个 public String render(MyObject object) 我试图返回的只是其中一个属性object.title,前面有给定数量的空格。问题是,它们似乎被修剪了,并且在呈现ListBox项时不会显示&nbps;HTML也不起作用。 我找到了一个在常规GWT列表框上工作的解决方案,但它不适用于ValueTextBox。这个问题有解决办法吗 编辑: 现在列表框中的对象是由setAcceptableValues

我正在用特定类型扩展GWT中的ValueListBox。构造函数需要一个

public String render(MyObject object)
我试图返回的只是其中一个属性object.title,前面有给定数量的空格。问题是,它们似乎被修剪了,并且在呈现ListBox项时不会显示&nbps;HTML也不起作用。 我找到了一个在常规GWT列表框上工作的解决方案,但它不适用于ValueTextBox。这个问题有解决办法吗

编辑:
现在列表框中的对象是由setAcceptableValues定义的,它们是通过下面的渲染代码显示的。前者将其追溯到ValueListBox类,将每个值放在一个映射中,然后使用您的解决方案调用getListBox.addItemrenderer.rendervalue可以绕过此问题,但当我尝试选择元素时,会出现IndexAutoFrage异常,由于该项未正确添加到ValueListBox类中,因此私有属性列表值

带有renderCategory对象的实际类,可追加省略:

}

我直接从您的共享中尝试

请让我知道为什么它不适用于ValueTextBox,我可以尝试找出解决方案

提示:

您可以重写ValueTextBoxgetValue方法

您可以使用ValueTextBox.getElement.getChildNodes获取添加到ValueTextBox中的所有子项

截图:


浏览器总是折叠多个空格。您可以尝试通过使用非中断空格&nbps;,找到解决方法;,但这是一个黑客。你想达到什么目标?也许有更好的方法。现在列表框中的对象是由setAcceptableValues定义的,它们是通过render显示的。前者将其追溯到ValueListBox类,将每个值放在一个映射中,然后调用getListBox.addItemrenderer.rendervalue;通过使用您的解决方案,可以绕过此问题,但在尝试选择元素时,会出现IndexAutoFrage异常,因为该项尚未正确添加到ValueListBox类的私有属性列表中values@JonasRosenqvist请把它添加到你的问题中,作为编辑部分,以使其他人也清楚。好的,让我试着分析一下。
public class CategoryListBox extends GraphNotesListBox<Category>{
public CategoryListBox(){
    super(new Renderer<Category>() {

        @Override
        public String render(Category object) {
            StringBuilder sb = new StringBuilder();
            //nbr of parents determine the indentation
            int size = GraphNotes.getCache().getGraph().getParentChain(object.parent).size(); 
            for (int i = 0; i < size; i++){
                sb.append("&nbsp;"); //or sb.append(" ");
            }
            return sb.toString() + object.title;
        }
    });
    setValues(GraphNotes.getCache().getGraph().getAllCategories());
}
Element listElement = valueListBox.getElement();

OptionElement optionElement = Document.get().createOptionElement();
optionElement
        .setInnerSafeHtml(SafeHtmlUtils
                .fromTrustedString("&nbsp;&nbsp;&nbsp;you should see 3 spaces before this"));

listElement.appendChild(optionElement);