在mac里添加环境变量,可以更改系统的/etc/profile,或者更改用户的.bash-profile.推荐后者。
在Terminal下执行echo命令:(以添加Derby_home为例来添加derby的环境变量,其中xxx为路径)
echo ‘export DERBY_HOME=xxx$DERBY_HOME’ >> ~/.bash_profile
或者直接用vi更改也可以
memcache其实也不算是一个很新的概念了,在各种大型网站中是运用的非常的多的。著名的Twitter的白鲸事件,也和memcache有着巨大的关系。想了解其背景概念的和八卦的,不妨Google一下。简而言之,memcache就是将那些经常需要查询的数据或者经常需要调用的外部文件,存在缓存之中,来减少数据库查询或者远程网络调用的浪费。这个概念在数据库的缓存中已经十分的悠久了,但是由于涉及到太多极低层次的代码编写,一般的程序员是不会接触到这的。现在有了memcache的帮助,能够很好的将这一思想移植到应用层面来,对大型项目的开发有着很大的帮助。
Google App Engine很早就有了memcache的支持,算是其天生的一个优势,在这里我简单的介绍一下如何在GAE/J中使用memcache。对Python感兴趣的同学就十分抱歉了。
首先我们假象一个例子,在GAE/J中有一个学校的学生系统,在一个有着4-5万人的大学里,如果该系统包括了所有的诸如选课,学习,注册,论坛等等各种信息,对于数据库的查询需求是非常的大的。不过,这种网虫又往往局限在部分学生之中,就比如学校邮箱,喜欢经常去check的和很少去check的都会存在。于是怎么能让那些经常使用的数据能够得到更好的利用呢?我们假定数据库中存有一个表,是Student表专门存放学生信息,学生无论是登录,还是做什么也好,都需要查询其Student信息。于是,我们来看memcache如何实现对Student的缓存。
首先我们生成一个JDO的POJO类,来存放学生信息,在这里简单开来:
[java]@PersistenceCapable(identityType = IdentityType.APPLICATION)
@Inheritance(customStrategy = “complete-table”)
public class Student implements Serializable{
@PrimaryKey
@Persistent
private String uuid;
@Persistent
private String name;
@Persistent
private String email;
@Persistent
private String address;
public Student(){
this.uuid = UUID.randomUUID().toString();
//setter&getter
}[/java]
接着,我们需要创立一个Cache类,来负责缓存层的操作:
[java]
public class QueryCache {
private static final Logger log = Logger.getLogger(QueryCache.class
.getName());
private static QueryCache instance;
private Cache cache;
private QueryCache(){
try{
CacheFactory cacheFactory = CacheManager.getInstance().getCacheFactory();
cache = cacheFactory.createCache(Collections.emptyMap());
}catch(CacheException e){
log.severe(”Error in creating the cache”);
}
}
public static synchronized QueryCache getInstance(){
if(instance==null){
instance = new QueryCache();
}
return instance;
}
public void putInCache(String address, String student){
cache.put(address, student);
}
public String findInCache(String address){
if(cache.containsKey(address)){
return (String)cache.get(address);
}else{
return null;
}
}
}
[/java]
在这个类中,其单例模式下的构造函数生成了一个新的Cache,它的内部结构是一个Map。同时我们定义了两个方法,一个是将学生信息放进cache,一个是从cache中取出学生信息。
最后,我们创建一个Servlet,来进行学生信息的查询:
public class QueryServlet extends HttpServlet{
private static final Logger log = Logger.getLogger(QueryServlet.class.getName());
@Override
protected void doGet(HttpServletRequest req, HttpServletResposne resp) throws ServletException, IOException{
log.info(”Now start……”);
QueryCache cache = QueryCache.getInstance();
String studentC = cache.findInCache(”Address7694″);
if(studentC!=null){
resp.getWriter().write(”Found the item in cache!”);
}else{
resp.getWriter().write(”No hit in cache!”);
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(Student.class);
query.setFilter(”address==’Address7694′”);
List students = List query.execute();
if(students.iterator().hasNext()){
log.info(”Found one:”+student.toString());
resp.getWriter().write(”Found one:”+student.toString());
cache.putInCache(”Address7694″, student.toString());
}else{
log.info(”None found!”);
resp.getWriter().write(”None Found!”);
}
}
}
这样一个很简单的例子,显示出了整个memcache在GAE/J中的运用方法。当然这只是最最基础的,还有许多的东西需要思考,比如该在什么样的地方使用memcache,memcache的有效时间是多少等等。
| Entitlement details | |
|---|---|
| Current date and time | Tue Mar 16 14:40:10 EST 2010 |
| Passport number | |
| Visa class/subclass | WA 010 |
| Visa description | BRIDGING |
| Visa applicant | Primary |
| Visa status | In Effect |
| Visa grant date | 16/03/2010 |
| Visa expiry date | |
| Visa grant number | 804951595**** |
| Entries allowed | No travel |
| Must not arrive after | |
| Period of stay | Indefinite |
| Visa type | Bridging visa |
| Included in this visa | |
| Visa conditions | |
1)ACS认证:墨大的IT的所有的课都可以顺利通过ACS认证,不需要为此而担心
2) 按照目前的政策,直接来读硕士的,必须至少读两年才能移民。读一年半的只能直接回国。
3)墨大的IT是偏软的,甚至从某种意义上是完全的软件方向。如果你个人对network感兴趣的话,可以在学完一年半的IT课程后,继续读一年的TELECOMMUNICATION,但是显然这是很耗费时间和金钱的。并且最新的SOL DRAFT上,网络方向的IT已经不在名单上了,前途未卜。
4)建议:打好基本功,提高英语能力。移民走一步看一步。
“羽东学长您好,我叫罗一木,湖北天门滴~
本科毕业于北京交通大学信息与计算科学专业(其实就是数学),现在刚来墨大读Master of Information Technology。
本来来之前并没有考虑PR的事,而且我课程也只是一年半的,后来需要读语言(L8R9W6S5.5……),课就变成两年的了。来之后发现周围这么多人都在为PR奋斗,在澳洲拿PR又有这么多的好处,自己也不免有些心动,嘿嘿~
我也明白这事儿任重道远,有几个问题想请教您一下:
ACS的accredited courses是怎么回事?我们学院的有MIT和MSSE,我看您的课程不在里面,对申请有什么影响吗?
我之前听说两年的Master课程申请时加5分,一年半的没有加分,这是两者在申请时的最大区别么?还有什么需要注意的地方?
P.S. 我现在才意识到我的课程偏软件方面的,但我自己偏向于network方向,也准备在这边考CCNA思科认证了,学院只有telecommunication这门课程(一年),还只收通信专业的,我一度想过转到他们专业,但好像跟PR不相符..现在也去旁听他们的课,学长有什么建议呢?
祝学长和我都好运~~~”
THIS IS A SYSTEM GENERATED E-MAIL, PLEASE DO NOT RESPOND TO THE E-MAIL ADDRESS SPECIFIED ABOVE.
PRIMARY APPLICANT: Yudong LI
DATE OF BIRTH: 07/10/1984
TRANSACTION RECORD NUMBER: EGNUF9****
TRIM FILE REFERENCE: BCC2010/10****
PERMISSION REQUEST ID: 124053****
CLIENT ID: 6350911****
LODGEMENT DATE: 03 March 2010
Dear Mr LI
This email confirms receipt of an application by Yudong LI for a Skilled - Independent (VB 885) visa which was lodged on the above date.
There are two locations where General Skilled Migration visa applications are processed: Adelaide and Brisbane. The department will automatically direct the application to the appropriate processing centre.
If you lodged an online application for one of the following subclasses it will be processed at the Brisbane Skilled Processing Centre.
Skilled - Independent (subclass 885)
Skilled - Sponsored (subclass 886)
Skilled - Regional (subclass 887)
Skilled - Graduate (subclass 485)
Skilled - Regional Sponsored (subclass 487)
All other applications will be processed at the Adelaide Skilled Processing Centre.
PROCESSING INFORMATION
Visa processing times vary and are affected by a range of factors outside of the department’s control. Please note that as the department receives a large number of applications you will not be contacted immediately. For information on specific processing times please refer to: http://www.immi.gov.au/skilled/general-skilled-migration/after-you-lodge.htm.
You will be contacted once your application is allocated to a case officer. Information concerning allocation timeframes is updated regularly and can be obtained by sending a blank email to: aspc.processing@immi.gov.au (for applications being processed in Adelaide) or gsmb.information@immi.gov.au (for applications being processed in Brisbane).
This is an automated service providing processing information only. Please do not send any other enquiry or information to this email address.
PRIORITY PROCESSING
Section 51 of the Migration Act 1958 gives the Minister for Immigration and Citizenship powers to consider and finalise visa applications in an order of priority that the Minister considers appropriate. This Direction applies to both new applications and those applications awaiting a decision.
The Priority Processing Direction gives priority to people who have particular skills or qualifications. This Direction responds to the changing needs of the Australian economy. For further information on how the current processing priorities will affect your application see the department’s website at http://www.immi.gov.au/skilled/general-skilled-migration/whats-new.htm.
The order in which your application will be assigned to a case officer will depend on its priority under the Priority Processing Direction. Please do not contact the department to request your application be exempt from the Priority Processing Direction. Case officers must adhere to the Direction.
If your application is not currently a priority under the Direction, you should expect significant delays before your application is allocated to a case officer.
Processing priorities are subject to change. Any changes to these priorities or processing times will be updated on the website. We recommend that you check this website regularly for updates.
YOUR IMMIGRATION STATUS
If you have applied for an onshore GSM visa, you will have been granted a Bridging visa in association with this application, enabling you to remain in Australia while your application is processed.
If you have applied for an offshore GSM visa, you are not entitled to a Bridging visa.
DOCUMENT REQUIREMENTS
If you have not already done so, you will need to provide the department with the documents listed below by attaching these documents to the eVisa browser:
- birth certificate or other evidence of age;
- copy of passport Personal Particulars/Photograph(bio-data) page;
- IELTS English Test Report Results;
- evidence of recent Australian qualifications - this includes transcript(s) and letter(s) of completion or evidence of recent work experience;
- form 80 - Personal Particulars for Character Assessment;
- form 1221 - Additional Personal Particulars Information;
- passport photograph;
- receipt for application for AFP check and your AFP check (if you have applied for an onshore GSM visa);
- evidence of arrangements to undergo a medical examination (if you have applied for an onshore GSM visa);
- satisfactory skills assessment for your nominated occupation. Please include all evidence of work experience you used to obtain this assessment. If you applied for an onshore GSM visa please also provide evidence of when you applied for your skills assessment
- overseas police clearances (if you have applied for an onshore GSM visa) - you must provide a police clearance certificate from each country where you have lived for a total of 12 months or more in the last 10 years. These 12 months are calculated cumulatively, not consecutively. The Character Requirements Penal Clearance Certificates form (formerly known as form 47P) provides country-specific instructions on how to obtain a police clearance and is available on the department’s website: http://www.immi.gov.au/allforms/.
If you have applied for an offshore GSM visa, your case officer will contact you when you need to undertake health and character checks.
TIMEFRAME FOR RESPONSE
Where applicable you must provide all additional documents (identified above) within 28 days after the date of this email, otherwise your application may be decided without the additional information being taken into account.
PROVIDING DOCUMENTS
Electronic lodgement of applications provides an effective service for applicants to provide documents to the department. eVisa applicants should attach documents online at: https://www.ecom.immi.gov.au/visas/attachment/start.do?attachType=VISA_APPLICATION&group=travel
The reference details for this application are: Primary Applicant’s name; Transaction Reference Number; and Permission Request ID. These details are located on the top left hand corner of the first page of this letter.
Reference details should be included as the first part of the subject line in any correspondence you send to the department. Including reference details in the subject line will help us to quickly locate your application.
Do not send us original documents unless we ask you for them. If you send copies of your documents they must be certified copies.
Please note that, while the department acknowledges the receipt of an application, the receipt of subsequent correspondence is not acknowledged.
CERTIFIED COPIES
For the purposes of the migration legislation, a document is to be certified in writing as a true copy of the original document by:
If the copy is certified in Australia:
- a Justice of the Peace; or
- a Commissioner for Declarations; or
- a person before whom a statutory declaration may be made under the Statutory Declarations Act 1958 (for example a nurse, medical practitioner, pharmacist or dentist); or
- a registered migration agent (whose registration is not suspended or subject to a caution).
If the copy is certified outside Australia:
- a person who is the equivalent of a Justice of the Peace or Commissioner for Declarations in that place; or
- a registered migration agent (whose registration is not suspended or subject to a caution).
Where applicable, the copies of both the original document and the translation must be certified as true copies.
Applicants are advised to retain in their records the original and certified copy of any document that is sent to the department, as we may request hard copies of these documents at a later date.
TRANSLATING YOUR DOCUMENTS
Original documents in languages other than English should be accompanied by an English translation. English translations must be official certified translations from a National Accreditation Authority for Translators and Interpreters accredited translator. Translations provided by non-accredited translators outside Australia should be endorsed by the translator with their full name, address, telephone number, and details of their qualifications and experience in the language being translated.
CHANGE OF CIRCUMSTANCES
If your circumstances have changed since you made your visa application, and as a result an answer to a question on your visa application form or the information you have given to the Department of Immigration and Citizenship about your visa application is no longer correct, you must advise us in writing as soon as possible.
Examples of changes in circumstances include:
- changes to address and/or contact details;
- changes to employment, for example a new job;
- obtaining a new passport;
- new member of the family unit;
- you or a secondary applicant has become pregnant;
- discovery that information previously provided is incorrect.
You can provide this information to the GSM processing office by letter or email, together with any accompanying documents. If you are notifying the department of a change to your email address by sending an email from your new email address, you must include details of your previous email address, as evidence that you have authorised the change.
The following forms are useful for notifying the department of changes in circumstances and are available on the department’s website at http://www.immi.gov.au/allforms:
- form 929 Change of Address;
- form 1022 Notification of Changes in Circumstances;
- form 1023 Notification of Incorrect Answer(s);
- form 1193 Communication by Email.
PROGRESS OF THE APPLICATION
You can keep up to date with the progress of your visa application by using the Online Visa Enquiry service once your application is allocated to a case officer. You can use your Transaction Reference Number (TRN) to access this free 24 hour service through our website at http://www.immi.gov.au/e_visa.
CONTACTING GSM PROCESSING OFFICES
After reading the information at the beginning of this letter on Skilled Migration priority processing arrangements and expected timeframes for the processing of applications, should you have any enquiry relating to your GSM application please use the online enquiry form available on our website at: http://www.immi.gov.au/contacts/forms/gsm/post.htm.
In Australia you can call 1300 364 613 and from outside Australia by calling +61 1300 364 613 between 9 am and 4 pm Monday to Friday.
For general enquiries you can call 13 18 81 between 9 am and 4 pm Monday to Friday.
ENTITLEMENTS TO MEDICARE
If you wish to know whether you are entitled to Medicare, please visit the following link:
http://www.immi.gov.au/living-in-australia/settle-in-australia/to-do-first/register-medicare.htm.
Department of Immigration and Citizenship
04 March 2010
Disclaimer: The preceding correspondence is intended solely for the use of the individual to which it is addressed and may contain privileged and/or confidential information. If this email has been sent in error, then the recipient is prohibited from disclosing, reproducing or using the information contained within.
——————————————————————–
Important Notice: If you have received this email by mistake, please advise
the sender and delete the message and attachments immediately. This email,
including attachments, may contain confidential, sensitive, legally privileged
and/or copyright information. Any review, retransmission, dissemination
or other use of this information by persons or entities other than the
intended recipient is prohibited. DIAC respects your privacy and has
obligations under the Privacy Act 1988. The official departmental privacy
policy can be viewed on the department’s website at www.immi.gov.au. See:
http://www.immi.gov.au/functional/privacy.htm
Dear Mr Yudong Li,
Thank you for your Skills Assessment Application to the Australian Computer Society. Your application reference number is 465***.
Please be advised that your result letter is about to be posted to you by registered post and the tracking number is 50201009****.
If you wish to track your registered letter please call Australia Post on 13 13 18 and quote your tracking number. Note that your tracking number may not be available immediately. Allow two working days before checking. Alternatively you can submit an online enquiry via the Australia Post website at online enquiry and enter your tracking number in the enquiry section.
If you have any other queries please email assessment@acs.org.au.
Regards,
Skills Assessment Processing Department
Australian Computer Society
ACS REFERS YOU TO THE IMPORTANT DISCLAIMER AND NOTICE ABOUT THIS EMAIL AThttp://www.acs.org.au/disclaimer.htm
又一次坐在了香港机场的板凳上,这两年在香港机场出现的次数算是比较多了,但是突然有个发现,就是一旦我要在这里转机,那必然是一个长时间的等待,这个长度平均下来,连我自己都不相信我就在这无聊地耗掉了这么多时间。
1. 2008年2月17日, 转机时间9小时
2. 2008年6月22日, 转机时间 18小时
3. 2008年7月27日, 转机时间9小时
4. 2009年9月9日, 转机时间8小时
5. 2009年10月13日,转机时间5个半小时
6. 2009年12月22日,转机时间7个小时
7. 2009年1月9日, 转机时间10小时
8. 2009年2月6日(今天),转机时间6小时
9. 2009年2月19日(下次),转机时间4小时
我把我宝贵的生命浪费了多少在香港机场啊。下次要好好考虑下自己的行程了。
PS:
经过多次的挑选经验,发现在香港机场吃东西,绝对不能进去以后吃,不然起步价就是50。我也在这上过两次当吃了70的拉面。在CHECKIN的这边,有几家还算比较廉价,不过我个人推荐2号航站楼的入口处的千烧百味,价格算是不错的了,不超过30,早餐和午晚餐都不错,烧腊算是让我比较满意了,虽然量不够多,但是在这还有什么好挑剔的呢。
PS2:
为什么QANTAS的办票柜台这么偏啊,都是ONEWORLD的成员不至于档次这么低啊,尽然排在和国航东航南航一起,属于最偏偏的偏厅。真是奇怪啊。要说QANTAS每天航班也不少啊,至少LHR一班,SYD二班,MEL, BNR, PER都有一班啊。而占据中庭的则是强大的SIA, JAL, ANA, AA这些。
PS3:
我想研究一下这里的办台湾签证的,每次都看到一大群人,被一个人拉着说教,站在中华旅行社这个之前,也就是CHECKIN柜台最偏最偏的角落。不过话又说回来,这可是休息的最好地方,人少,位置多,当然离厕所也近。
明年回国考虑走走BANKOK,或者TAIPEI,顺道玩玩是个不错的选择!
以前曾经提到过,作为一个疑似恐怖分子,我在墨尔本,悉尼机场均被海关人员拦下来过然后送往小房间审问。至于原因是什么,第一次觉得是巧合,第二次觉得是自己没梳洗太邋遢,直到第三次才让我有点愤怒了。于是,回国的时候,我就说,我要投诉。当时心理的想法是,如果能够在一个星期之内有个答复,我对澳大利亚这个国家就还没有那么失望。
回来后一直很忙,把这件事忘记在了脑后。前天澳洲国庆日的时候,突然想起了,于是说那我就国庆日来投诉一番吧。1月26日下午4点钟,把第一封信寄到了Custom的投诉处。(补充一下,每个部门都有支持很好的网上投诉入口,不要钱,不麻烦,填个表格谁都会)。很快,1月27日早上11点,也就是上班后两个小时,我的回信收到,说给我盖章的是海关的,但是到小房间审问的是DIAC的,于是要我把信转递给DIAC.
Can you please confirm that the issue you refer to is action of Customs Officers or Immigration Officers?
If for some reason you discover that Customs was actually involved in this matter, please let us know the specific details of Customs involvement and we will investigate it.
National Coordinator | Complaints and Compliments Management Unit | NPAC
Australian Customs and Border Protection Service
P: 1800 228 227 | F: 03 9244 8160
E: comments@customs.gov.au
W: www.customs.gov.au
于是在1月27日下午下班以后,我将第二封信寄到DIAC的投诉初。今天早上11点,收到了确认信,说将会在五天内解决。然后下午34点的时候,我的回复已经受到:
Dear Mr Yudong LI,
Subject: Sydney and Melbourne International Airport Referrals – Mr Yudong LI
Thank you for contacting us regarding your referrals at Sydney and Melbourne International Airports.
You have been referred to Departmental officers at both Sydney and Melbourne International Airports to verify your identity. On all occasions, you have been assessed as a ‘non match’ to any persons of concern on our Departmental Movement Alert List (MAL), and this has resulted in you being allocated a Green MAL status.
A Green MAL status enables a client to travel without being referred as a result of the MAL system, unless new information comes to DIAC’s attention that requires a client to be reassessed.
Unfortunately, as new information has been loaded onto our MAL, containing client data that is similar to yours (on multiple occasions over the past two years), your MAL status has reverted to Amber. This means that DIAC has then been required to assess your identity to ensure that you are not a match to any of these new persons of concern listed on the MAL. As mentioned above, on all occasions you have been reassessed as a ‘non match’.
I can confirm that you currently have a Green MAL status, which means it is unlikely that you will be referred on your next departure, unless new information has come to DIAC’s attention before your departure date, requiring your identity to be reassessed. This business is consistent with the dynamic nature of the Movement Alert List.
I apologise for any inconvenience that these referrals have caused.
Thank you for bringing this matter to our attention.
Yours sincerely,
Gary Sheppard
Director
Border Operations Centre
Border Security Division
Telephone: 02 6264 3091
没想到所有的事情这么快就有了结果,很详细的解释,很清除的说明。只能说让我非常满意。
是谁以前说澳洲办事效率低的?我现在是不会在这么觉得了。制度化的东西的确是好。
PS:这次回国,在武汉第二公证处,感觉他们的服务态度还是非常不错的,特别是公证员。不过那几个收钱的却好像总是欠人钱样的。我的建议是,国内的各种公共机关,应该有更好的服务,首先就可以解决的是电子服务,把自己的办事流程,详细的写在网上应该不是麻烦事。最好,能够加上电子办理,那自然是最好了。还有潜力可挖阿!
1. GWT与Restlet的结合
目前进行的项目中,使用App Engine作为底层以及数据库的平台,Restlet是作为HTTP调用的库,然后GWT来前台界面的实现。基本上整个架构是严格按照Google的思路来进行的。最近把重心从底层慢慢走到了前台,于是对GWT有了些研究。把一些经验和总结列举出来。
首先,可以看到Restlet在最新的2.0m6和Snapshot之中,有五种版本,每一种版本的JAR的结构和路径都不一样。我们的项目在后台是使用的J2EE的版本,而在前台需要使用的是for GWT版本,于是这里就产生了第一个问题,在同一个项目中均需要使用这两个版本的冲突。在两个JAR包下都有org.restlet.jar存在。于是一个很简单的方法,就是改变其中一个JAR包的名字,来避免冲突。这里一定要注意的是,之后在引用JAR包时,一定要看清楚你的类是属于前台还是后台的,如果是前台的,一般包名是以com.google.gwt.core.client开头的。
2. – GWT的项目结构
在一个创建好的GWT项目中,一般会有以下三个重要的部分,第一个是项目名.gwt.xml,这个文件是整个项目的核心文件,里面包括了模块的引用,入口点的定义以及其他的一些配置方面的设置。接下来两部分分别存在两个包中,client包和server包。其中,client包就是为了做前台界面而存在的包,而server包可以认为是后台的,当然你可以使用你已经做好的而不是强制性非要放在里面。client包下的项目名同名java文件,即是在配置文件中定义的入口点,这个文件定义了界面UI的结构,以及各种事件的触发,就等于是一个以java而写的界面。GWT在编译过程中,是将其转化为javascript而给浏览器运行的。
现在有这样一个问题存在,如何实现页面的跳转。我们知道对于AJAX实现的Web应用,习惯于只用单页面来实现不同的内容,也就是利用同样的定位符如div等,来不断改变其中的内容。那么在GWT中,有没有比较好的办法做到这一点呢。我采用的方法,是使用一个单例模式下的固定div来实现。我们可以将不同的页面均视作为Content的不同实现,然后只需要替换页面下的Content即可。具体办法为:
1)创建一个Content的抽象类继承Composite类,这个类将作为所有通用的内容类,在主页面中替换使用。
public abstract class Content extends Composite {
}
2)在项目名java文件中,利用单例模式定一个该入口点的实例,同时创建一个Content实例,这个实例用来承载不同的实现内容类。同时加上一个setContent(Content content)方法,用来设定当前的Content。
public class XXX implements EntryPoint {
private static final XXX INSTANCE = new XXX();
private Content content;
private XXX(){}
public static XXX getInstance(){
return INSTANCE;
}
@Override
public void onModuleLoad() {
XXX.getInstance().setContent(new LoginContent());
}
public void setContent(Content content){
this.content = content;
RootPanel.get(”content”).clear();
RootPanel.get(”content”).add(content);
}
}
3)对于每一个不同的实现页面,分别创建一个类继承Content类,在这个类的构造函数中定义其界面和事件的触发函数。
public class LoginContent extends Content {
private Label usrLabel = new Label(”Username”);
……
public LoginContent(){
usrPanel.add(usrLabel);
usrPanel.add(usrTextBox);
……
initWidget(verPanel);
}
4)在今后的每次需要更换页面的时候,只需要获得该项目下的Content实例,进行替换即可。
3. – GWT下的UiBinder的实现
用上面的方法来实现界面存在的一个问题是,经常需要在类文件中写大量的界面元素的定义,如同Swing一样。一来对于Java程序员不太方便,二来对于界面程序员更为苦恼。于是在最新的GWT的版本中,Google推出了UiBinder,这是一个采用xml来作为界面管理器的实现方法,将界面的元素与功能实现了脱离,一方面简化了代码,另一方面也给前台和后台的程序员提供了便利。
在uiBinder下,我们如果需要创建一个新的界面,不再直接使用类来实现,而是创建一个UiBinder对象,在Eclipse下,new一个UiBinder会生成两个文件,一个是扩展了Composite的类,另一个是同名的.ui.xml文件。在.ui.xml中,xmlns:g=”urn:import:com.google.gwt.user.client.ui”的空间下定义的是所有的Widget,于是可以就像使用Java一样,列出这些需要的Widget了。在<ui:style>中,还可以定义所需要使用的样式,当然也可以单独在CSS中定义。以下是一个简单的例子:
<!DOCTYPE ui:UiBinder SYSTEM “http://dl.google.com/gwt/DTD/xhtml.ent”>
<ui:UiBinder xmlns:ui=”urn:ui:com.google.gwt.uibinder”
xmlns:g=”urn:import:com.google.gwt.user.client.ui”
xmlns:c=”urn:import:com.featheast.client”>
<ui:style>
.important {
font-weight: bold;
}
.bolder {
font-weight: bold;
}
</ui:style>
<g:HTMLPanel>
Hello,
<g:Button styleName=”{style.important}” ui:field=”button” />
<g:Label styleName=”{style.bolder}” text=”This is my label in bold!”></g:Label>
<g:VerticalPanel ui:field=”myPanelContent” spacing=”5″></g:VerticalPanel>
</g:HTMLPanel>
</ui:UiBinder>
对于每一个在.ui.xml中的元素,我们都有一个在类文件中的对应,比如这里,我们有一个Button,一个Label,这些可以操作的值在类中分别有
@UiField
Button button;
@UiField
Label label;
的对应。这样的结果就是我们能更好的操作这些元素。在该类的构造函数中,可以定义这些元素的事件函数和其他的操作。这样将界面和执行分隔开,效果的确比较好,思路也更加清晰。以下是一个对应的示例:
public class MyUIBinder extends Composite {
private static MyUIBinderUiBinder uiBinder = GWT.create(MyUIBinderUiBinder.class);
interface MyUIBinderUiBinder extends UiBinder<Widget, MyUIBinder> {}
@UiField
Button button;
@UiField
VerticalPanel myPanelContent;
public MyUIBinder(String firstName) {
initWidget(uiBinder.createAndBindUi(this));
button.setText(firstName);
HTML html1 = new HTML();
html1.setHTML(”<a href=’http://www.google.com’>Click me!</a>”);
myPanelContent.add(html1);
HTML html2 = new HTML();
html2.setHTML(”This is my sample <b>content</b>!”);
myPanelContent.add(html2);
}
@UiHandler(”button”)
void onClick(ClickEvent e) {
RootPanel.get().add(new FavouriteColorWidget());
}
}
运用同样的单例模式,我们可以更改同一个界面的内容,在此就不重复了。




