2011-11-10 8 views
0

私はこれまでGWTで手伝ってきました。私の現在の傷は次のように記述できます:GWT:Column内のTextArea

  1. 私はCellTableを持っています。これには、いくつかのColumnsとTextColumnsが含まれています。 TextColumnsには、レポートオブジェクトの変数、列のラジオボタン、チェックボックスなどが含まれます。
  2. テーブル行ごとにTextAreaを提供する別の列を挿入したいと思います。
  3. 私の問題は、TextAreaの作成方法を理解できないことです。

誰でも私にコードスニペットを渡してもらえますか?

答えて

1

このショーケースをご覧ください:http://gwt.google.com/samples/Showcase/Showcase.html#!CwCellSampler目的に応じてTextInputCellを使用できます。

+0

あなたの答え、z00bsのための非常に多くのタクシー。私はTextInputClassのJavadocを読んでいて、TextInputCellのテキストを設定して取得するためにViewDataオブジェクトを設定して取得する必要があることを確認しています - これは正しいですか?もしそうなら、私に例を教えてもらえますか?私はGWTショーケースを成功なく探しました。 \t \t \t \t列 contextColumn =新しい列(新TextInputCell取得および設定する方法( \t \t \t \t \t \t \t \t \t \t \t \t //:これまでのところ私はこれを持っていますテキスト \t \t \t \t \t \t \t \t));? –

+0

謝罪 - 「私はTextInputCell用のJavadocを読んだ」 –

+0

心配はありません、私はコードの別のセクションのハックを行い、それを一緒に冠水しました。 –

1

テキストエリアが入力されたビルトインセルはありませんが、自分で作成することは簡単です。私はGWTの船であることTextInputCell後に私のTextAreaInputCellをモデリングしていhttp://code.google.com/webtoolkit/doc/latest/DevGuideUiCustomCells.html (およびガイドとしてTextInputCellEditTextCellソースコードのいずれかを見て)

+0

トーマスありがとう、私は自分のセルを作成しようとすると、パッド入りのものの中に私と一緒に終わるだろうと恐れている! ;) –

0

を参照してください。これは、テンプレートの情報がテキストエリアに特異的であることを除いて、基本的には同じコードだ(あなたがコピーすることができます/このクラスを貼り付け、それは完全に機能します):

package com.xxx.scorecard.client.view.cell; 

import com.google.gwt.cell.client.AbstractCell; 
import com.google.gwt.cell.client.AbstractInputCell; 
import com.google.gwt.cell.client.ValueUpdater; 
import com.google.gwt.core.client.GWT; 
import com.google.gwt.dom.client.Element; 
import com.google.gwt.dom.client.InputElement; 
import com.google.gwt.dom.client.NativeEvent; 
import com.google.gwt.safehtml.client.SafeHtmlTemplates; 
import com.google.gwt.safehtml.client.SafeHtmlTemplates.Template; 
import com.google.gwt.safehtml.shared.SafeHtml; 
import com.google.gwt.safehtml.shared.SafeHtmlBuilder; 

/** 
* An {@link AbstractCell} used to render a text input. 
*/ 
public class TextAreaInputCell extends AbstractInputCell<String, TextAreaInputCell.ViewData> { 

    interface Template extends SafeHtmlTemplates { 
     @Template("<textarea type=\"text\" cols=\"30\" rows=\"5\" tabindex=\"-1\">{0}</textarea>") 
     SafeHtml input(String value); 
    } 

    /** 
    * The {@code ViewData} for this cell. 
    */ 
    public static class ViewData { 
     /** 
     * The last value that was updated. 
     */ 
     private String lastValue; 

     /** 
     * The current value. 
     */ 
     private String curValue; 

     /** 
     * Construct a ViewData instance containing a given value. 
     * 
     * @param value 
     *   a String value 
     */ 
     public ViewData(String value) { 
      this.lastValue = value; 
      this.curValue = value; 
     } 

     /** 
     * Return true if the last and current values of this ViewData object 
     * are equal to those of the other object. 
     */ 
     @Override 
     public boolean equals(Object other) { 
      if (!(other instanceof ViewData)) { 
       return false; 
      } 
      ViewData vd = (ViewData) other; 
      return equalsOrNull(lastValue, vd.lastValue) && equalsOrNull(curValue, vd.curValue); 
     } 

     /** 
     * Return the current value of the input element. 
     * 
     * @return the current value String 
     * @see #setCurrentValue(String) 
     */ 
     public String getCurrentValue() { 
      return curValue; 
     } 

     /** 
     * Return the last value sent to the {@link ValueUpdater}. 
     * 
     * @return the last value String 
     * @see #setLastValue(String) 
     */ 
     public String getLastValue() { 
      return lastValue; 
     } 

     /** 
     * Return a hash code based on the last and current values. 
     */ 
     @Override 
     public int hashCode() { 
      return (lastValue + "_*[email protected][email protected]!*_" + curValue).hashCode(); 
     } 

     /** 
     * Set the current value. 
     * 
     * @param curValue 
     *   the current value 
     * @see #getCurrentValue() 
     */ 
     protected void setCurrentValue(String curValue) { 
      this.curValue = curValue; 
     } 

     /** 
     * Set the last value. 
     * 
     * @param lastValue 
     *   the last value 
     * @see #getLastValue() 
     */ 
     protected void setLastValue(String lastValue) { 
      this.lastValue = lastValue; 
     } 

     private boolean equalsOrNull(Object a, Object b) { 
      return (a != null) ? a.equals(b) : ((b == null) ? true : false); 
     } 
    } 

    private static Template template; 

    /** 
    * Constructs a TextInputCell that renders its text without HTML markup. 
    */ 
    public TextAreaInputCell() { 
     super("change", "keyup"); 
     if (template == null) { 
      template = GWT.create(Template.class); 
     } 
    } 

    @Override 
    public void onBrowserEvent(Context context, Element parent, String value, NativeEvent event, 
      ValueUpdater<String> valueUpdater) { 
     super.onBrowserEvent(context, parent, value, event, valueUpdater); 

     // Ignore events that don't target the input. 
     InputElement input = getInputElement(parent); 
     Element target = event.getEventTarget().cast(); 
     if (!input.isOrHasChild(target)) { 
      return; 
     } 

     String eventType = event.getType(); 
     Object key = context.getKey(); 
     if ("change".equals(eventType)) { 
      finishEditing(parent, value, key, valueUpdater); 
     } else if ("keyup".equals(eventType)) { 
      // Record keys as they are typed. 
      ViewData vd = getViewData(key); 
      if (vd == null) { 
       vd = new ViewData(value); 
       setViewData(key, vd); 
      } 
      vd.setCurrentValue(input.getValue()); 
     } 
    } 

    @Override 
    public void render(Context context, String value, SafeHtmlBuilder sb) { 
     // Get the view data. 
     Object key = context.getKey(); 
     ViewData viewData = getViewData(key); 
     if (viewData != null && viewData.getCurrentValue().equals(value)) { 
      clearViewData(key); 
      viewData = null; 
     } 

     String s = (viewData != null) ? viewData.getCurrentValue() : value; 
     if (s != null) { 
      sb.append(template.input(s)); 
     } else { 
      sb.appendHtmlConstant("<input type=\"text\" tabindex=\"-1\"></input>"); 
     } 
    } 

    @Override 
    protected void finishEditing(Element parent, String value, Object key, ValueUpdater<String> valueUpdater) { 
     String newValue = getInputElement(parent).getValue(); 

     // Get the view data. 
     ViewData vd = getViewData(key); 
     if (vd == null) { 
      vd = new ViewData(value); 
      setViewData(key, vd); 
     } 
     vd.setCurrentValue(newValue); 

     // Fire the value updater if the value has changed. 
     if (valueUpdater != null && !vd.getCurrentValue().equals(vd.getLastValue())) { 
      vd.setLastValue(newValue); 
      valueUpdater.update(newValue); 
     } 

     // Blur the element. 
     super.finishEditing(parent, newValue, key, valueUpdater); 
    } 

    @Override 
    protected InputElement getInputElement(Element parent) { 
     return super.getInputElement(parent).<InputElement> cast(); 
    } 
} 

そして、ここであなたはセルを使用方法は次のとおりです。

Column<ScorecardEntryDTO, String> commentColumn = new Column<ScorecardEntryDTO, String>(new TextAreaInputCell()) { 
     @Override 
     public String getValue(ScorecardEntryDTO object) { 
      return object.getComment(); 
     } 
    }; 
0

このようなものを試してください:

TextArea outputArea = new TextArea(); 
outputArea.getElement().setAttribute("cols", "100"); 
outputArea.getElement().setAttribute("rows", "20"); 
locPanel.add(outputArea);