Rich UI 핸들러 간의 Non-Infobus 통신
애플리케이션을 조직하는 한 방법은 한 Rich UI 핸들러에서 표현된 사용자 상호작용을 두 번째 Rich UI 핸들러에서 표현된 비즈니스 데이터 백엔드 처리로부터 분리하는 것입니다. 이 절에서는 일부 메커니즘을 제외하고 한 핸들러가 다른 핸들러와 통신할 수 있는 Infobus—by에 대한 아웃라인을 제공합니다.
임베딩 핸들러로부터 데이터 푸시
Handler EmbeddingHandler type RUIHandler
{ onConstructionFunction = onConstructionFunction }
embeddedHandler EmbeddedHandler;
function onConstructionFunction()
myString STRING = "Received from somewhere";
embeddedHandler.function01(myString);
end
end
위임 사용
다른 가능성은 임베디드 핸들러가 임베딩 핸들러에서 함수를 호출하는 것입니다. 이 경우 임베딩 핸들러는 임베디드 핸들러의 위임에 지정된 값을 업데이트합니다. 위임은 특정 유형의 함수를 참조하는 변수입니다. 즉 이 변수는 특정한 특성 세트가 있는 함수에 대한 액세스를 제공합니다.
delegate switchPart() end
다음 예에서는 두 웹 페이지 간을 전환하는 방법을 보여줍니다. 여기에는 switch라는 이름의 위임을 선언하는 임베디드 핸들러 Page2가 있습니다.
handler Page2 type RUIHandler { onConstructionFunction = myFirstFunction,
initialUI = [content] }
content Box{children = [secondLabel, button], columns = 1};
secondLabel TextLabel{text = "page2!"};
button Button{text="switch back to first page", onClick ::= switchToFirst};
//declaration of a delegate
switch switchPart{};
function myFirstFunction()
end
function switchToFirst(e Event in)
switch();
end
end
switchToFirst 내에서 switch()를 호출할 때 실행되는 로직이 무엇인지에 대한 질문이 있을 수 있습니다. 위임에 해당 함수를 지정하는 임베딩 핸들러 Page1에 답이 있습니다.
handler Page1 type RUIHandler
{ onConstructionFunction = myFirstFunction, initialUI = [page] }
page Box{ columns = 1, children = [firstLabel, button]};
firstLabel TextLabel{text = "page1!"};
button Button{text = "switch to page 2", onClick ::= switchTo2};
page2 Page2{};
function myFirstFunction()
page2.switch = switchBack;
end
function switchTo2(e Event in)
page.children = [page2.content];
end
function switchBack()
page.children = [firstLabel, button];
end
end
위임을 사용하여 여러 페이지를 탐색
이전 예를 확장하면 이후의 여러 웹 페이지에 대한 탐색을 제어하는 페이지 핸들러(MainHandler라고 함)를 정의할 수 있습니다. 웹 애플리케이션에 대한 전통적인 접근 방식과 같이 이벤트 플로우를 한 페이지씩 작성합니다. Rich UI를 사용하여 런타임 이벤트에 대한 응답에서 웹 페이지의 부분들을 업데이트할 수 있다는 점을 알고서 이와 같은 접근 방식으로 시작할 수 있습니다.
delegate SwitchToPagePart( TargetPage STRING in) end
여기서는 세 개의 Rich UI 핸들러가 호출됩니다. 다음은 사용 가능한 옵션을 표시하는 첫 번째 ButtonHandler의 출력입니다.

handler ButtonHandler type RUIHandler{initialUI = [button1, button2, button3]}
switchFunction SwitchToPagePart;
button1 Button{text = "Go To Main Page", onClick::= toMain};
button2 Button {text = "Stay Here"};
button3 Button{text = "Go to TextField", oncLick::=toText};
function toMain(e Event in)
switchFunction("MainHandler");
end
function toText(e Event in)
switchFunction("TextFieldHandler");
end
end
다음은 두 번째 핸들러 TextFieldHandler의 출력입니다.

handler TextFieldHandler type RUIHandler
{initialUI = [instructions, Field1, myButton]}
// a delegate
switchFunction SwitchToPagePart;
instructions TextLabel {text = "Type a page name and click the button."};
Field1 Textfield{width = 200};
myButton Button{text = "Go to the specified page", onClick ::= handleEvent};
function handleEvent(e Event in)
switchFunction(Field1.text);
end
end
handler MainHandler type RUIHandler{initialUI = [mainBox]}
mainBox Box{columns = 1, children = [mainLabel]};
mainLabel TextLabel{
text = "Click to see your options.",
onClick::= mainEvent};
buttonHandler ButtonHandler{switchFunction = switchTo};
textFieldHandler TextFieldHandler{switchFunction = switchTo};
function switchTo(target string in)
case (strlib.upperCase(target))
when ("TEXTFIELDHANDLER")
mainBox.children = [textFieldHandler.instructions,
textFieldHandler.Field1,
textFieldHandler.myButton];
when ("BUTTONHANDLER")
mainBox.children = [buttonHandler.button1,
buttonHandler.button2,
buttonHandler.button3];
when ("MAINHANDLER")
mainBox.children = [mainLabel];
end
end
function mainEvent (e Event in)
switchTo("ButtonHandler");
end
end
서비스 호출 후 임베딩 핸들러에 알림
임베디드 핸들러에는 위젯이 없을 수 있지만 서비스를 호출할 수 있습니다. Rich UI에서 서비스 액세스에서 설명한 대로 Rich UI에서의 서비스 호출은 항상 비동기입니다. 이는 요청자(Rich UI 핸들러)가 서비스로부터의 응답을 기다리지 않고 계속해서 실행됨을 의미합니다. Rich UI 핸들러가 서비스에서 응답이 오기를 기다리는 동안 사용자는 여전히 사용자 인터페이스와 상호작용할 수 있습니다. 호출 후에 서비스는 일부 태스크를 수행하고 대부분의 경우 Rich UI 핸들러에서 코딩한 함수를 호출하여 요청자에 응답합니다. 해당 함수는 콜백 함수라고 합니다.
delegate notifyPart() end
handler MyModel type RUIHandler { onConstructionFunction = myFirstFunction }
//declaration of a delegate
notify notifyPart{};
function myFirstFunction()
call myService.myOperation(12) returning to myCallback;
end
function myCallback(returnValue STRING)
notify();
end
end
handler MyHandler type RUIHandler { onConstructionFunction = myFirstFunction }
theModel MyModel;
function myFirstFunction()
theModel.notify = myNotification();
end
function myNotification()
// respond, perhaps by accessing details from the embedded handler
end
end