éãã
ãããã£ãŠãç®æšã¯Java Webã¢ããªã±ãŒã·ã§ã³ãäœæããããšã§ãã ããã«èŠåŽããã«ãextJSã®ã€ã³ã¿ãŒãã§ã€ã¹ãjavaã®ãµãŒããŒããžãã¯ããã³ã°ã¢ããããHibernateã䜿çšããŠããŒã¿ããŒã¹ãæäœããŸããã³ã³ããŒãã³ãã®ååŸæ¬¡ã®ã³ã³ããŒãã³ããå¿ èŠã§ãã- Netbeans 6.5 JavaãŸãã¯AllïŒããããWindows 212ããã³249 mbã®å Žåãä»ã®OSã®å Žåããµã€ãºã«å€§ããªéãã¯ãããŸããïŒ ã
- ExtJs ããŒãžã§ã³2.0.2 ã
- Google Web Toolkit 1.5 ;
- äŒæ¢ç¶æ ã³ã¢ ;
- gwt-ext 2.0.5
Netbeansãã€ã³ã¹ããŒã«ãããšãã«å¿ èŠãªãªãã·ã§ã³ã
Netbeansã«GWTã®ãã©ã°ã€ã³ãé 眮ããŸãã
- [ããŒã«]ã¡ãã¥ãŒã®[ãã©ã°ã€ã³]ãéããŸãã
- [å©çšå¯èœãªãã©ã°ã€ã³]ã¿ããéããŸãã
- ãã©ã°ã€ã³Gwt4Nbãæ¢ããŠããŸãïŒæ€çŽ¢ã䜿çšã§ããŸãïŒã
裞ã®GWT
ãã®åŸãæ°ããWebãããžã§ã¯ããäœæããŸãïŒ [ãã¡ã€ã«]-> [æ°ãããããžã§ã¯ã]-> [Java Web]-> [Webã¢ããªã±ãŒã·ã§ã³] ïŒã ãããžã§ã¯ãã«ã¯ãååãšä¿åå Žæãæå®ããå¿ èŠããããŸãã TomcatããµãŒããŒïŒãŸãã¯ã奜ã¿ã«ããå¥ã®ãµãŒããŒïŒãšããŠæå®ããŸãã æåŸã®ããŒãžã¯ããããžã§ã¯ãã«å¿ èŠãªãã¬ãŒã ã¯ãŒã¯ã瀺ããŠããŸãã Google Web ToolkitãšHibernateãå«ãŸããŠããŸãã ãã®å ŽåãGWTã®å Žåãgwtã解åãããã£ã¬ã¯ããªãéžæããå¿ èŠããããŸãã ãã®ããã«$ ProjectPath / lib / gwtãã©ã«ããŒãéžæããŸããã ãŸããéçºããGWTã¢ãžã¥ãŒã«ã®ååãæå®ããå¿ èŠããããŸãã our.sample.Faceã«ããŸãã ãŸããäŒæ¢ç¶æ æ¥ç¶ãæ§æããå¿ èŠããããŸãããã®ããã»ã¹ã«ã€ããŠã¯èª¬æããŸãããããã«ã€ããŠã¯ãã§ã«å€ãã®ããšãè¿°ã¹ãŠããŸããããšãã°ãå°æ¬ãããŠãããã¿åé家garbuzã®èšäºãã芧ãã ããã ãã®åŸã[å®äº]ãã¯ãªãã¯ãããšç¶è¡ã§ããŸãããå®è¡ã®ã¡ã¢ãªå¶éãå¢ããã©ã³ã¿ã€ã ã®ãªãã·ã§ã³ãããã«èšå®ããããšããå§ãããŸãã ããã¯ãããžã§ã¯ãããããã£ã§å®è¡ããã [å®è¡]-> [VMãªãã·ã§ã³]ãã-Xmx512mãã«èšå®ãããŸãã ãŸããã³ã³ãã€ã©ãŒã®æ倧ã¡ã¢ãªãŒãå¢ããå¿ èŠããããŸããããã§å°ã工倫ããå¿ èŠããããŸããnetbeans/ build-gwt.xmlãã¡ã€ã«ãéããŠã次ã®ããã«å€æŽããå¿ èŠããããŸããç°å¢ã¯our.sample.clientããã³our.sample.serverããã±ãŒãžãäœæããŸããã æããŠãã ãã-ãããã®ãã£ã¬ã¯ããªã§ã¯ãããããã¯ã©ã€ã¢ã³ããšãµãŒããŒã®ã³ãŒãã«ãªããŸãã ããæ£ç¢ºã«ã¯ãã¯ã©ã€ã¢ã³ãããã±ãŒãžã®ã¯ã©ã¹ã¯ã³ã³ãã€ã«åŸã«ãµãŒããŒã«æ®ããŸããããµãŒããŒã®ã¯ã©ã¹ã¯ã¯ã©ã€ã¢ã³ãã«å°éããŸããã ããã«ãããããããç§ãã¡ã®softinkaã¯ãŸã çºå£²ã®æºåãã§ããŠããŸããã 次ã«ããããžã§ã¯ããå®è¡ããŠãããã©ã«ãã§äœæãããã¢ãžã¥ãŒã«ã確èªã§ããŸãã ågwtã¢ãžã¥ãŒã«ã«ã€ããŠããšã³ããªãã€ã³ããã¯ã©ã¹ã瀺ãããŸããããã¯ãmainïŒïŒã¡ãœãããåããã¯ã©ã¹ã®é¡äŒŒç©ã§ãããã·ã¹ãã ã¯ã¯ã©ã€ã¢ã³ãäžã§åäœãéå§ããŸãã ããã¯ãæåã®ãã©ãŒã ãæç»ããå§ããå Žæã§ããã2çªç®ã®ãã©ãŒã ã¯éåžžãããããæ¥ãŸãã ãã¹ãŠã人ã®ãããªãã®ã§ã:)ã ããã©ã«ãã®ãšã³ããªãã€ã³ãã¯ãã¯ã©ã¹$ ModuleName + EntryPointã§ããã®å Žåã¯our.sample.FaceEntryPointã§ãããããã°ãã¿ã³ãæŒããŠïŒå®è¡ãããµãŒããŒãŸãã¯ã¯ã©ã€ã¢ã³ãã®ãããã°ãéžæã§ããŸãïŒãã¢ããªã±ãŒã·ã§ã³ã®ãã«ããåŸ ã¡ãŸãã 次ã«ãå®è¡äžã®ãµã³ãã«ã確èªããŸãã....<br/> < java classpath ="${javac.classpath}:${src.dir}" failonerror ="true" <br/> classname ="com.google.gwt.dev.GWTCompiler" fork ="true" > <br/> < arg value ="-out" /> <br/> < arg path ="${build.web.dir}/" /> <br/> < arg value ="-style" /> <br/> < arg value ="${gwt.compiler.output.style}" /> < arg value ="-logLevel" /> <br/> < arg value ="${gwt.compiler.logLevel}" /> <br/> < arg value ="${gwt.module}" /> <br/> < jvmarg value ="-Xmx512m" /> <br/> </ java > <br/>.... < target name ="debug-connect-gwt-shell" if ="netbeans.home" depends ="init" > http://bankinform.ru/habraeditor/images/yu-logo.png<br/>... <br/> < java fork ="true" classname ="com.google.gwt.dev.GWTShell" failonerror ="true" > <br/> < jvmarg value ="-Xmx512m" /> <br/> ....<br/> </ java > <br/> </ target > <br/>.... <br/><br/> * This source code was highlighted with Source Code Highlighter .
è©Šé転ã
åæã«ãã¯ã©ã€ã¢ã³ãçšã«æ¬¡ã®ã³ãŒããäœæãããŸããã
ããã§èª¬æãå¿ èŠã ãšã¯æããªããpackage our.sample.client;<br/><br/>import com.google.gwt.core.client.EntryPoint;<br/>import com.google.gwt.user.client.ui.Button;<br/>import com.google.gwt.user.client.ui.ClickListener;<br/>import com.google.gwt.user.client.ui.Label;<br/>import com.google.gwt.user.client.ui.RootPanel;<br/>import com.google.gwt.user.client.ui.Widget;<br/><br/><br/> public class MainEntryPoint implements EntryPoint {<br/> // <br/> public void onModuleLoad() {<br/> // <br/> final Label label = new Label( "Hello, GWT!!!" );<br/> // <br/> final Button button = new Button( "Click me!" );<br/> <br/> // , . <br/> button.addClickListener( new ClickListener(){<br/> public void onClick(Widget w) {<br/> label.setVisible(!label.isVisible());<br/> }<br/> });<br/> <br/> // "" . <br/> RootPanel. get ().add(button);<br/> RootPanel. get ().add(label);<br/> }<br/>} <br/><br/> * This source code was highlighted with Source Code Highlighter .
GWT-Ext>
次ã«ãgwt-extã©ã€ãã©ãªèªäœãæ¥ç¶ããå¿ èŠããããŸããããã¯ãæšæºã®Webã³ã³ããŒãã³ããå¿ èŠãªãããã§ãã ãããè¡ãã«ã¯ããããžã§ã¯ãããããã£ïŒãããžã§ã¯ãããªãŒã®ã«ãŒããå³ã¯ãªãã¯ããŠ[ããããã£]ã³ã³ããã¹ãã¡ãã¥ãŒïŒãéãã[ ã©ã€ãã©ãª]-> [ã©ã€ãã©ãªãè¿œå ]-> [äœæ ]ã®é ã«ã¯ãªãã¯ããŸã ã 次ã«ãååãgwt-extããå ¥åããã¯ã©ã¹ïŒ[ã¯ã©ã¹ãã¹]ã¿ãïŒããã³ãœãŒã¹ã³ãŒãïŒ[ãœãŒã¹]ã¿ãïŒãšããŠãGwt-extã¢ãŒã«ã€ãããgwtext.jarãã¡ã€ã«ãæå®ããŸãã 次ã«ã[ã©ã€ãã©ãªã®è¿œå ]ãã¯ãªãã¯ããŸããgwt-extã©ã€ãã©ãªãæ¥ç¶ããŸãã
ãŸããweb / js / extãã©ã«ããŒã«ExtJS 2.0.2ãã¹ããŒããããšãå¿ããªãã§ãã ããã æåŸã«ãã¢ãžã¥ãŒã«ã«extJã«é¢é£ããæ°ããã³ã³ããŒãã³ããããããšãäŒããå¿ èŠããããŸãã ãããè¡ãã«ã¯ããã¡ã€ã«/ sample / Face.gwt.xmlãéãã次ã®ããã«ä¿®æ£ããŸãã
ããã§ã¯ãæå³ã®ããäœããæžããŸãããã 人ç©ã«é¢ããæ å ±ãå«ããã£ãŒã«ããå«ãPersonã¯ã©ã¹ãè¿œå ããã¯ã©ã€ã¢ã³ãããµãŒããŒã«ãã£ãŠããŒããããããŒã¿ããã®ã¯ã©ã¹ã«æç»ããããšããŸãã ãã®å ŽåãéåæãµãŒãã¹ïŒGWT RPCïŒã®ä»çµã¿ã瀺ããããšæããŸãã our.sample.clientããã±ãŒãžãå³ã¯ãªãã¯ããŠãPersonã¯ã©ã¹ãè¿œå ããŸãã<? xml version ="1.0" encoding ="UTF-8" ? > <br/> < module > <br/> < inherits name ="com.google.gwt.user.User" /> <br/> < inherits name ='com.gwtext.GwtExt' /> <br/> < entry-point class ="our.sample.client.FaceEntryPoint" /> <br/><br/> < stylesheet src ="js/ext/resources/css/ext-all.css" /> <br/> < script src ="js/ext/adapter/ext/ext-base.js" /> <br/> < script src ="js/ext/ext-all.js" /> <br/> </ module > <br/> <br/> * This source code was highlighted with Source Code Highlighter .
次ã«ããªã¯ãšã¹ãã«å¿ããŠPersonã®ã€ã³ã¹ã¿ã³ã¹ãã¯ã©ã€ã¢ã³ãã«æäŸãããµãŒãã¹ãäœæããŸãã ãããè¡ãã«ã¯ã our.sample.clientããã±ãŒãžãå³ã¯ãªãã¯ãã[ æ°èŠ ]- > [ãã®ä»]ãéžæããŠã[Google Web Toolkit]ã«ããŽãªãéžæãããã®äžã§GWT RPCãµãŒãã¹ãéžæããŸãã æ°ãããµãŒãã¹ã®ååãå ¥åããå¿ èŠããããŸããå¿ èŠã«å¿ããŠã[䜿çšäŸãäœæãã]ããã¯ã¹ããªã³ã«ããŸãã ãã®å Žåãã¯ã©ã€ã¢ã³ãåŽã§2ã€ã®ã€ã³ã¿ãŒãã§ã€ã¹ãäœæãããŸãããµãŒããŒåŽã®ã¯ã©ã¹ãšããã§ãã¯ããã¯ã¹ããªã³ã«ãªã£ãŠããå Žåã¯ããµãŒãã¹ã®äœ¿çšäŸãå«ãã¯ã©ã€ã¢ã³ãã¯ã©ã¹ãšã³ããªãã€ã³ãã§ãã PersonServiceãµãŒãã¹ã®ååãå ¥åããŸãã æçµçã«ã¯ã©ã¹ã次ã®ããã«ãªãããã«ã PersonService.javaã«ã³ãŒããè¿œå ããŸããpackage our.sample.client;<br/><br/>import com.google.gwt.user.client.rpc.IsSerializable;<br/><br/> // Person, <br/> // IsSerializable, . <br/> public class Person implements IsSerializable {<br/> private String name;<br/> private String surname;<br/> private String patronymic;<br/> private String email;<br/> private int age;<br/> // .... <br/> // - <br/> // .... <br/>}<br/> <br/> * This source code was highlighted with Source Code Highlighter .
ãã¹ããããAppã¯ã©ã¹ã䜿çšãããšããµãŒãã¹ã®ã€ã³ã¹ã¿ã³ã¹ãååŸã§ããŸããéåžžãç°å¢ãããèªäœãäœæããªãã®ã¯æããã§ã¯ãããŸãããã䜿çšäŸã«ãã®é¡äŒŒæ§ã瀺ããŸãããããã£ãŠããããçæããŠé©åãªå Žæã«ã³ããŒã§ããŸã ãã®åŸãç°å¢ã¯ãšã©ãŒã衚瀺ãããµãŒãã¹ã€ã³ã¿ãŒãã§ã€ã¹ã®åæããŒãžã§ã³ãšéåæããŒãžã§ã³ãåæããŠããªãããšã瀺ããŸããalt+ EnterããŒãæŒããšããšã©ãŒã®ä»£ããã«ããã¹ãã«ãŒãœã«ã眮ããŸããpackage our.sample.client;<br/><br/>import com.google.gwt.user.client.rpc.ServiceDefTarget;<br/>import com.google.gwt.user.client.rpc.RemoteService;<br/>import com.google.gwt.core.client.GWT;<br/> public interface PersonService extends RemoteService{<br/> public Person loadPerson( int someValue);<br/> <br/> public static class App {<br/> private static final PersonServiceAsync ourInstance;<br/> static {<br/> ourInstance = (PersonServiceAsync) GWT.create(PersonService. class );<br/> ((ServiceDefTarget) ourInstance).setServiceEntryPoint(GWT.getModuleBaseURL() + "PersonService" );<br/> }<br/> public static PersonServiceAsync getInstance()<br/> {<br/> return ourInstance;<br/> }<br/> }<br/>} <br/><br/> * This source code was highlighted with Source Code Highlighter .
ããã±ãŒãžour.sample.serverã§å®è£ ãè¡ããŸãïŒpackage our.sample.client;<br/>import com.google.gwt.user.client.rpc.AsyncCallback;<br/><br/> public interface PersonServiceAsync {<br/> public abstract void loadPerson( int someValue, AsyncCallback<Person> asyncCallback);<br/>}<br/> <br/><br/> * This source code was highlighted with Source Code Highlighter .
æ®å¿µãªãããgwt4nbãã©ã°ã€ã³ã¯ãäœããã®çµæãè¿ãã€ã³ã¿ãŒãã§ã€ã¹ã®ã¡ãœãããé©åã«èªèããŸããã ãµãŒãã¹ãPersonã®ã€ã³ã¹ã¿ã³ã¹ãè¿ãå¿ èŠããããgwt4nbãPersonãè¿ãã€ã³ã¿ãŒãã§ã€ã¹ã®éåæããŒãžã§ã³çšã®ã¡ãœããã®äœæãæäŸãããšããŸãã ãã ããããã¯ééã£ãŠããŸãããªããªã ãã¹ãŠã®çµæïŒããã³ãšã©ãŒã¡ãã»ãŒãžïŒã¯ãéåæã¡ãœããã®æåŸã®ãã©ã¡ãŒã¿ãŒïŒAsyncCallbackã€ã³ã¿ãŒãã§ã€ã¹ãå®è£ ããã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ïŒã䜿çšããŠååŸãããŸãã å®éãã¡ãœããããªããžã§ã¯ããè¿ãããã«ã¯ãã¡ãœããpublic abstract void loadPersonïŒint someValueãAsyncCallback asyncCallbackïŒãèšè¿°ããå¿ èŠããããŸãã ããã§ãæåã®ãã©ã¡ãŒã¿ãŒã¯å ¥åãã©ã¡ãŒã¿ãŒã§ãããAsyncCallbackã¯ãµãŒããŒã§ã®ã¡ãœããå®è¡ã®çµæã®åŠçãæäŸããå¿ èŠããããŸãã ç¹å®ã®ã¯ã©ã¹ã®ãªããžã§ã¯ããè¿ãã«ã¯ããã³ãã¬ãŒãïŒãã®å Žåã¯PersonïŒã§ãã®ã¯ã©ã¹ã眮ãæããå¿ èŠããããŸãã 䜿çšæ¹æ³ã«ã€ããŠã¯ã以äžãåç §ããŠãã ãããpackage our.sample.server;<br/>import com.google.gwt.user.server.rpc.RemoteServiceServlet;<br/>import our.sample.client.Person;<br/>import our.sample.client.PersonService;<br/><br/> public class PersonServiceImpl extends RemoteServiceServlet implements PersonService {<br/> <br/> public Person loadPerson( int someValue) {<br/> Person person = new Person();<br/> person.setSurname( "Some" );<br/> person.setName( "Usual" );<br/> person.setPatronymic( "Man" );<br/> person.setAge(someValue);<br/> person.setEmail( "man@domain.com" );<br/> return person;<br/> }<br/>}<br/> <br/> * This source code was highlighted with Source Code Highlighter .
ã³ãŒãã§ã¯æ¬¡ã®ããšãèµ·ãããŸããpackage our.sample.client;<br/><br/>import com.google.gwt.core.client.EntryPoint;<br/>import com.google.gwt.user.client.rpc.AsyncCallback;<br/>import com.google.gwt.user.client.ui.RootPanel;<br/>import com.gwtext.client.core.EventObject;<br/>import com.gwtext.client.core.Position;<br/>import com.gwtext.client.widgets.Button;<br/>import com.gwtext.client.widgets.MessageBox;<br/>import com.gwtext.client.widgets.Panel;<br/>import com.gwtext.client.widgets. event .ButtonListenerAdapter;<br/>import com.gwtext.client.widgets.form.*;<br/><br/><br/> public class FaceEntryPoint implements EntryPoint {<br/><br/> public FaceEntryPoint() {<br/> }<br/><br/> final static TextField txtName = new TextField( "" , "name" , 190);<br/> final static TextField txtSurname = new TextField( "" , "surname" , 190);<br/> final static TextField txtPatronymic = new TextField( "" , "patronymic" , 190);<br/> final static TextField txtEmail = new TextField( "Email" , "email" , 190);<br/> final static TextField txtAge = new TextField( "" , "age" , 190);<br/><br/> public void onModuleLoad() {<br/> Panel panel = new Panel();<br/> panel.setBorder( false );<br/> panel.setPaddings(15);<br/><br/> final FormPanel formPanel = new FormPanel(Position.CENTER);<br/> formPanel.setFrame( true );<br/> formPanel.setTitle( " " );<br/> formPanel.setWidth(500);<br/> formPanel.setLabelWidth(100);<br/><br/> FieldSet fieldSet = new FieldSet( "" );<br/> fieldSet.add(txtName);<br/> fieldSet.add(txtSurname);<br/> fieldSet.add(txtPatronymic);<br/> fieldSet.add(txtEmail);<br/> fieldSet.add(txtAge);<br/> txtEmail.setVtype(VType.EMAIL);<br/> txtAge.setVtype(VType.ALPHANUM);<br/><br/> fieldSet.setWidth(formPanel.getWidth() - 20);<br/> final Button btnLoad = new Button( "" , new ButtonListenerAdapter() {<br/> public void onClick(Button button, EventObject e) {<br/> PersonService.App.getInstance().loadPerson(29, new AsyncCallback<Person>() {<br/><br/> public void onFailure(Throwable caught) {<br/> MessageBox.alert( ", - !" );<br/> }<br/><br/> public void onSuccess(Person result) {<br/> txtName.setValue(result.getName());<br/> txtSurname.setValue(result.getSurname());<br/> txtPatronymic.setValue(result.getPatronymic());<br/> txtAge.setValue( String .valueOf(result.getAge()));<br/> txtEmail.setValue(result.getEmail());<br/> }<br/> });<br/> }<br/> });<br/> formPanel.add(fieldSet);<br/> formPanel.addButton(btnLoad);<br/> panel.add(formPanel);<br/> RootPanel. get ().add(panel);<br/> }<br/>}<br/> <br/> * This source code was highlighted with Source Code Highlighter .
- ãã£ãŒã«ãã¯ã¯ã©ã¹ã§å®£èšãããéçã«å®£èšãããŸãã ãªãããå°ãäžãèŠãŠãã ããã
- äžé£ã®ãã£ãŒã«ããäœæããã³ã«ã¹ã¿ãã€ãºããããã«ã«é 眮ããåäœãšè¡šç€ºãã«ã¹ã¿ãã€ãºããŸãã
- ãã¿ã³äžã®onClickã€ãã³ããã³ãã©ãŒãåæããŸãã ãã³ãã©ãŒã¯ãButtonListenerAdapterã€ã³ã¿ãŒãã§ãŒã¹ãå®è£ ããå¿åã¯ã©ã¹ã§ãã ããã¯ç¬ç«ããã¯ã©ã¹ã§ãããFaceEntryPointã¯ã©ã¹ã®ãã£ãŒã«ããæäœããå¿ èŠãããããããããã®ãã£ãŒã«ãã¯éçã§ãããšå®£èšããŸããã
- ãã¿ã³ã¯ãªãã¯ãã³ãã©å ã«ã¯ããã°ããããµãŒãã¹ãžã®åŒã³åºãããããŸãã ãã®ãµãŒãã¹ã¯ãã€ã³ã¿ãŒãã§ã€ã¹ã®å®è£ ïŒä»åã¯AsyncCallbackïŒãè¡šããŸãã æåãããšonSuccessã¡ãœãããåŒã³åºããããšã©ãŒãçºçãããšonFailureãåŒã³åºãããŸãã OnSuccessãã©ã¡ãŒã¿ãŒã¯ããã³ãã¬ãŒããã©ã¡ãŒã¿ãŒã«ãã£ãŠæ±ºå®ãããŸãã
WebãµãŒããŒçšã®warãã¡ã€ã«ãäœæããã«ã¯ããããžã§ã¯ãã©ã€ãã©ãªããgwt-dev-windows.jarãé€å€ããå¿ èŠãããããšã«æ³šæããŠãã ããã
ãããŠæåŸã«ãå°ãèªå·±æ¹å€ãšã³ã¡ã³ããããäœè£ããããŸãã
- gwt4nbãã©ã°ã€ã³ã¯ãç§ãé Œãã«ããªããã°ãªããªãã£ãããªãã¯ãããããããã«ãå°ã湿ã£ãŠããŸãã
- gwt 1.6 m1ã¯æ¢ã«ãªãªãŒã¹ãããŠãããèšäºã¯gwt 1.5ã«çŠç¹ãåœãŠãŠããŸãã
updïŒããããã¹ãŠç©ºã§äžå¿ èŠã«èŠããªãããã«ã gwt -extã®äŸãèŠãããšãã§ããŸãã