이 블로그 검색

2011년 8월 26일 금요일

Using Eclipse with Google Data APIs

  1. Google Data APIs Java Client를 다운후 필요한 jar파일을 프로젝트 빌드패스 라이브러리에 추가한다.

  2. 외부 jar파일을 다운후 필요한 jar파일을 프로젝트 빌드패스 라이브러리에 추가한다.
          - mail.jar                     Sun's JavaMail API
          - servlet-api.jar            Apache Tomcat
          - activation.jar             Sun's JavaBeans Activation Framework
          - guava-r09.jar             google-collect
    3. 소스 작성


참고 : 링크
         URL을 https://docs.google.com/feeds/default/private/full로 해야 동작함



Google Documents List Data API

2011년 8월 23일 화요일

jsp에서 useBean 과 import 의 차이


--------------------------------- 질문 -------------------------------------------
---------------------------------------------------------------------------------

일전에 jsp 페이지 내에서 useBean으로 객체를 생성하는 것과 객체의 직접 생성에 관한 글을 어디선가 봤었는데 다시 찾아보려니 찾을 수가 없습니다 ㅠ.ㅠ
<%@ import="test.Test"%>
<jsp:useBean name="test" class="test.Test" scope="session"/>
이것과
<%@ import="test.Test"%>
<%
      Test test = new Test();
%>
이렇게 만드는 방식에서의 scope 에 관해서
혹시 일전의 링크 주소를 알고 계시거나 위에 관해서 설명해 주실수 있는 분 부탁드립니다.


-----------------------------------답변----------------------------------------------
-------------------------------------------------------------------------------------
첫번째 질문만 답 드리께요..제가 아는 선에서만요..
useBean으로 생성한거랑 new 해서 생성한거랑의 차이점을 소스로 한번 확인해보세요..

각각의 경우 .java로 변환된 work폴더아래의 jsp.java파일을 보시면 이부분이 틀릴겁니다.

useBean으로 객체생성하면 아래 소스가 _jspService라는 메소드에 추가되거든요..

jsp 라이프 사이클 보시면 _jspService는 알수 있으리라 생각합니다.

synchronized (pageContext) {
sb= (oil.common.board.GongiLogic)
pageContext.getAttribute("sb",PageContext.PAGE_SCOPE);
if ( sb == null ) {
_jspx_specialsb = true;
try {
sb = (oil.common.board.GongiLogic) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "oil.common.board.GongiLogic");
} catch (ClassNotFoundException exc) {
throw new InstantiationException(exc.getMessage());
} catch (Exception exc) {
throw new ServletException (" Cannot create bean of class "+"oil.common.board.GongiLogic", exc);
}
pageContext.setAttribute("sb", sb, PageContext.PAGE_SCOPE);
}
}

제 생각엔 scope를 쓸 수 있느냐..없느냐 차이 같습니다. 맞는지 아닌지 딴 분들도 의견 주셨음 합니다.

그 외엔 sb = (oil.common.board.GongiLogic) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "oil.common.board.GongiLogic");

이 코드가 뭔가 특별한 건지..아마 이 코드를 아시면 알고자 하시는 차이점을 정확히 아실수 있을것 같아요..
저도 궁금..

일단 scope을 쓸수 있느냐 없느냐의 차이고 뭐 jsp에서 지원해주는 기능 마다하고 new 해서 생성하는건 적절한 코딩에서 멀어지는 길이니...
그럼 수고하세요..

위처럼 객체를 생성시에 scope에 관해서 부탁드립니다.






---------------------------------------------------------------------------------------








----------------------------------- 질문 -----------------------------------------------
Ok on a Java Server Page I can use a function in two ways:
Either I declare
<jsp:useBean id="myBean" scope="session" class="mypack.mysubpack.MyClass" />
or I declare
<%@ page import = "mypack.mysubpack.MyClass" %>

In each case I can call a function later by coding

MyClass.myFunction();

So what is the difference between the two variantes?

Why are Beans invented if we don't need them because we have the import statement ?

Ulf



---------------------------------------------------------------------------답변-------------------------------------------------------------


(Ulf Meinhardt) writes:

> Ok on a Java Server Page I can use a function in two ways:
> Either I declare
> <jsp:useBean id="myBean" scope="session" class="mypack.mysubpack.MyClass" />


This checks if an object called "myBean" exists in the session
attributes, and if necessary creates and puts it there. It also adds a
variable called "myBean" that can be referenced later, in e.g.
<%=myBean.getFoo()%>.

> or I declare
> <%@ page import = "mypack.mysubpack.MyClass" %>


This does nothing more than add an import statement in the beginning
of the generated servlet.

> In each case I can call a function later by coding
>
> MyClass.myFunction();
>
> So what is the difference between the two variantes?


See above.

> Why are Beans invented if we don't need them because we have the
> import statement ?


Because beans aren't limited to what you artificially limit them to.
You can do much more with beans than just call static methods in their
classes.

2011년 8월 12일 금요일

HasWidgets IsWidget


  • HasWidgets
A widget that implements this interface contains widgets and can enumerate them.

API 바로가기

 


  • IsWidget

Extended by view interfaces that are likely to be implemented by Widgets.

2011년 8월 11일 목요일

assert문

1.       assert expression1;

2.       assert expression1 : expression2;



위의 두 문장에서 expression1 이 검증이 필요한 Boolean 표현식이다. 이 표현식은 개발자가 프로그램이 수행되는 동안 항상 ‘참(true)’이 되어야 한다고 요구하는 조건이 된다. 두 번째 문장에 있는 expression2 는 검증이 실패했을 때 상세 정보를 표현하기 위한 메시지로 String으로 변환 가능한 형태여야 한다.

[출처] 자바 assert|작성자 스나이퍼

uiBinder안에 composite을 넣고 composite에서 발생한 이벤트 받기


In the definition of my Country-and-State view, I added 
  public class CountryStateView extends Composite implements
HasValueChangeHandlers<Object> 

and I implemented the required method with: 
  @Override
    public HandlerRegistration addValueChangeHandler(
        ValueChangeHandler<Object> handler) {
      return addHandler(handler, ValueChangeEvent.getType());
    } 

Whenever the country or state listboxes changes, I do: 
   ValueChangeEvent.fire(...the.composite.object..., null); 
and finally, in the UiBinder created form, I wrote 
  @UiHandler("countryStateView")
  void uiOnChange(ValueChangeEvent<Object> event) {
    // ...do whatever needs be done...
  } 

This is working perfectly (at least to my eyes!) but I'd like to know
if it could/should be done in a better way. 

2011년 8월 10일 수요일

gwt vs jquery


I agree with Russ Cam that it depends on what your team is familiar with. When I am doing work for my personal business apps, I much prefer GWT. I find javascript, even with jquery, to have annoying object oriented syntax. If you have an app with 10,000 lines of UI code, jquery strikes me as something that would lead to a mess of hard to maintain code with poor reuse.
Does anyone know of a large scale project done in jquery?
I think if you are trying to squeeze every last byte out of the resulting filesize, don't use any library and write the javascript from scratch (ie: google homepage fade effect).
Something to think about regarding javascript/jquery versus gwt. If you use common object oriented principles and design patterns, you will likely get better performing code with gwt. Why?
Let's take the example of polymorphism. If you write an app that uses heavy polymorphism in javascript, you will get the benefit of maintanability and code reuse this provides. However, your code will also get the performance hit of using polymorphism.
Now, if you used gwt, you will also get the benefit of maintanability and code reuse this provides, BUT the gwt compiler will optimize away the polymorphism into concrete class usage, hence increasing performance.





I would go with JQuery.
I had the chance of maintaining a GWT project that eventually forced me to re-write it twice. First as a refactored GWT. Second as a JQuery.
I haven't touched Javascript seriously for a very long time. Last time was 2002? I'm a Java developer so my first impression with GWT is awesome. But that was just the impression.
Problems I found with GWT:
  1. It forces you to follow it's client/server structure. At the end all I want is AJAX and those good widgets. GWT's widget by itself doesn't seem that really great looking. Aesthetically, I'd preferred Adobe Flex! But to keep the comparison closer, JQuery's UI look better than GWT's. In addition you have that wonderful Theme Roller support from JQuery.
  2. I've tried DWR. It's great. It's far easier to enable AJAX in your Java using DWR than GWT.
  3. If you're using GWT, eventually you will be forced to learn JavaScript. Arjen of SpringSource once said about XML and SOAP (though not the exact quote): "How can you develop WebServices and not knowing XML? SOAP is XML. You can't avoid it". Same thing with GWT. It's still Javascript at the end.
  4. Realistically Javascript isn't that hard to learn vs Java. More people know Javascript than Java. Even web designers know them. You're a programmer, and you're scared of Javascript?
  5. Back to the project I rewrote. When I rewrote our GWT application it took me almost two months to rewrite it. With JQuery it took me two weeks for someone who is rusty with JavaScript.
  6. With JQuery you don't really write that hardcorde JavaScript. That's why you have JQuery in the first place. Maintaining code with GWT is horrible. You wanna see the latest changes you did in the code...go compile..wait for GWT...5 minutes...rinse...and repeat and hope it doesn't throw an error. If it does, you'll be recompiling again, wait for 5 minutes. Rinse and repeat. With JQuery change a line, refresh your browser. Done.
I know I'm not being precise here, but I'm just sharing my experience :) The moral is don't be scared with Javascript. Google use Javascript anyway




I agree with Russ Cam that it depends on what your team is familiar with. When I am doing work for my personal business apps, I much prefer GWT. I find javascript, even with jquery, to have annoying object oriented syntax. If you have an app with 10,000 lines of UI code, jquery strikes me as something that would lead to a mess of hard to maintain code with poor reuse.
Does anyone know of a large scale project done in jquery?
I think if you are trying to squeeze every last byte out of the resulting filesize, don't use any library and write the javascript from scratch (ie: google homepage fade effect).
Something to think about regarding javascript/jquery versus gwt. If you use common object oriented principles and design patterns, you will likely get better performing code with gwt. Why?
Let's take the example of polymorphism. If you write an app that uses heavy polymorphism in javascript, you will get the benefit of maintanability and code reuse this provides. However, your code will also get the performance hit of using polymorphism.
Now, if you used gwt, you will also get the benefit of maintanability and code reuse this provides, BUT the gwt compiler will optimize away the polymorphism into concrete class usage, hence increasing performance.

2011년 8월 9일 화요일

자바스크립트 변수


  • 자바스크립트에서 덧셈, 뺄셈을 할때는 주의를 해야한다. 문자로 인식을 해서 2+1이 21로 인식하게 된다. 
  • 이 오류를 찾느라 엄첨 고생했다.

var iRowNum = 3;


  1. 잘못된 예

for(var i=0; i < iRowNum+1; i++){
}

    2. 옳은 예

for(var i=0; i < parseInt(iRowNum)+1; i++){
}

2011년 8월 5일 금요일

java.lang.noclassdeffounderror org json jsonexception

java.lang.noclassdeffounderror org json jsonexception

-> 이클립스 lib에 다운받은 gwt의 gwt-servlet-deps.jar 파일을 추가한다.