2011年4月2日土曜日

GWT UiBinder で RadioButton を使う




  1. <!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">  
  2. <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" xmlns:g="urn:import:com.google.gwt.user.client.ui">  
  3.   <ui:style>  
  4.     .my-RadioButton {  
  5.       font-weight: bold;  
  6.     }  
  7.   </ui:style>  
  8.   <g:HTMLPanel>  
  9.     <g:VerticalPanel>  
  10.       <g:HTML><h3>Select your favorite color:</h3></g:HTML>  
  11.       <g:RadioButton name="color" value="true">blue</g:RadioButton>  
  12.       <g:RadioButton name="color">red</g:RadioButton>  
  13.       <g:RadioButton name="color" enabled="false">yellow</g:RadioButton>  
  14.       <g:RadioButton name="color">green</g:RadioButton>  
  15.       <g:HTML><h3>Select your favorite sport:</h3></g:HTML>  
  16.       <g:RadioButton name="sport">Baseball</g:RadioButton>  
  17.       <g:RadioButton name="sport">Basketball</g:RadioButton>  
  18.       <g:RadioButton name="sport" value="true">Football</g:RadioButton>  
  19.       <g:RadioButton name="sport">Hockey</g:RadioButton>  
  20.       <g:RadioButton name="sport">Soccer</g:RadioButton>  
  21.       <g:RadioButton name="sport" styleName="{style.my-RadioButton}">Water Polo</g:RadioButton>  
  22.     </g:VerticalPanel>  
  23.   </g:HTMLPanel>  
  24. </ui:UiBinder>   


スコープを指定するための name 属性が必須になります。


  1. package yanzm.example.hellowtgt.client;  
  2.   
  3. import com.google.gwt.core.client.GWT;  
  4. import com.google.gwt.uibinder.client.UiBinder;  
  5. import com.google.gwt.user.client.ui.Composite;  
  6. import com.google.gwt.user.client.ui.Widget;  
  7.   
  8. public class RadioButton extends Composite {  
  9.   
  10.   private static RadioButtonUiBinder uiBinder = GWT.create(RadioButtonUiBinder.class);  
  11.   
  12.   interface RadioButtonUiBinder extends UiBinder<Widget, RadioButton> {  
  13.   }  
  14.   
  15.   public RadioButton() {  
  16.     initWidget(uiBinder.createAndBindUi(this));  
  17.   }  
  18. }  

■ その他
Java code による実装例 (Showcase)
com.google.gwt.user.client.ui.RadioButton


 

0 件のコメント:

コメントを投稿