User Guide 를 보면 2가지 방법을 소개하고 있다.

1. Page 클래스에서 ActionLink instance 를 생성하고, Control's listener 메소드를 추가한다. listener 메소드 이름은 꼴리는데로 사용해도 되지만, return type 은 boolean 으로 선언해야 한다. true, false 로 이벤트를 계속 처리할 지 말지를 결정하는 듯 싶다.

장점 : 코드를 간결하게 작성 할 수 있단다.
단점 : The disadvantage of this type of control listener binding is that no compile time safety is provided, and you miss out on the compiler refactoring capabilities provided with modern IDEs. (뭔소리임??) 대충 컴파일 하고 있을 때 안전하게 동작하지 않다는 말인듯..

page class
@Bindable protected ActionLink controlListenerType1 = new ActionLink(this, "onLinkClick");
@Bindable protected String msg1;

// controlListenerType1 control's listener
public boolean onLinkClick() {
    msg1 = "controlListenerType1 : HomePage#" +
                   hashCode() + " object method <tt>onLinkClick()</tt> invoked.";
    return true;
}

page template
page template
<b><a href="$controlListenerType1.href">Control Listener Type1</a></b>

#if($msg1)
    <div id = "msgDiv">$msg1</div>
#end 


2. 안전한 컴파일 시간을 제공(아마.. 컴파일 할때 바인딩을 해준다는 말인듯..)하는 ActionListener interfacre 를 사용한다.
page class
@Bindable protected ActionLink controlListenerType2 = new ActionLink();
@Bindable protected String msg2;

page template
public HomePage() {
        controlListenerType2.setActionListener(new ActionListener() {
          
            @Override
            public boolean onAction(Control source) {
                // TODO Auto-generated method stub
                msg2 = "controlListenerType2 : HomePage#"
                           + hashCode() + " object method <tt>onLinkClick()</tt> invoked.";
                return true;
            }
        });
    }

흠.. 매번 이벤트가 도착하면 instance를 새로 생성한다. 뭐.. 계속 읽다보면 다른 해결책일 있을듯.. 따로 찾아보기가 좀 귀찮다. 복덩이는 언제 오냐?? 쩌ㅃ~

setStateful(true);

위 코드를 추가하면 HttpSession 안에 해당 Page를 저장하기 때문에 기존에 작업하던 내용이 그대로 유지된다.


Posted by 짱가쟁이