2011-11-18 55 views
1

我正在使用GWT 2.4。我正在用一些可編輯的表格單元構建一個CellTable。我的問題是,當單元格渲染時,如何強制它們在輸入標記中定義的「name」和/或「id」屬性進行渲染?現在,我的代碼有渲染單元是...GWT:我如何爲CellTable中的可編輯表格單元分配一個ID?

class EditableTableCell extends TextInputCell { 
    private final List<Node> colData; 

    public EditableTableCell(final List<Node> colData) { 
     super(); 
     this.colData = colData; 
    } 

    @Override 
    public void render(Context context, String value, SafeHtmlBuilder sb) { 
     final Integer index = context.getIndex(); 
     final Node childNode = colData.get(index); 

     if (childNode.getAttributes() != null && 
      childNode.getAttributes().get("edit") != null && 
      childNode.getAttributes().get("edit").getValue() != null && 
      childNode.getAttributes().get("edit").getValue().equalsIgnoreCase("yes")) { 
      super.render(context,value,sb); 
     } else { 
      sb.appendEscaped(value); 
     } // if 
    } 
} 

如果單元格可編輯,生成的HTML看起來像......

<td class="GCSPOWVPD GCSPOWVBE GCSPOWVCE GCSPOWVME"> 
    <div style="outline:none;" tabindex="0"> 
     <input type="text" value="\n\t\t\tABC\n\t\t" tabindex="-1"></input> 
    </div> 
</td> 

雖然「類型」,「值「和」tabindex「被定義,沒有」名稱「或」ID「。試圖找出如何做到這一點。謝謝, - 戴夫

回答

0

你在做什麼super.render(...),我會自己呈現該HTML,並手動爲input元素粘貼一個名稱和ID值。我回答了關於這個概念here的類似問題。想法略有不同,但實施將是相同的。

相關問題