MVNO패키지 개발 Wiki

 

JSF

Page history last edited by fullbox 3 yrs ago

JSF (Java Server Faces)

 

  • Rich Internet Application 의 붐
  1. 웹환경(Http기반)에서의 Xinternet 등의 최신 기술로 Client User interface 의 편리성, 효율성, 기능성 강조
  2. TrustForm, Flex.. etc.
  • JSF는 java 로 구현된 RAD
  1. JSF는 Custom Tag Library 로 표준 컴퍼넌트 정의
  2. 애플리케이션 UI 위젯 사용 : 팔레트에서 컴퍼넌트를 끌어서 사용
  3. MVC pattern 으로 구현 : view – controller – model
  4. 서버 요청에 의한 이벤트 중심
  5. JSF API를 이용하여 다양한 컴퍼넌트를 개발하여 사용가능
  6. 쉬운 오류 처리와 국제화를 위한 기능이 내장 지원
  7. AJAX 와 결합되어 interactive 한 UI 개발 – 서드파티 상용 컴퍼넌트 개발, 출시
  • 다양한 개발툴 지원
  1. IBM Ration Application Developer(RAD), Oracle JDeveloper
  2. Java Studio Creater, Eclipse plugin(Exadel Studio pro) etc..

 

 



JSF 개발 환경

 

 

  • 개발 환경
  1. JDK 1.3.x, J2EE 1.3 이상
  2. JSP 1.2, Servlet 2.3, JSTL 1.0 이상을 지원하는 jsp container 필요
  • 기반 환경
  1. HTML 4.01, XHTML 1.0, XML 1.0 기반
  • 필요 libraries
  1. commons-beanutils.jar: Utilities for defining and accessing JavaBeans component properties
  2. commons-collections.jar: Extensions of the J2SE Collections Framework
  3. commons-digester.jar: For processing XML documents
  4. commons-logging.jar: A general purpose, flexible logging facility to allow developers to instrument their code with logging statements
  5. jsf-api.jar: Contains the javax.faces.* API classes
  6. jsf-impl.jar: Contains the implementation classes of the JSF Reference Implementation
  7. jstl.jar, standard.jar : JSTL api and implementation

 


JSF Architecture

 

 

MVC pattern

 

 

Controller - FacesServlet

 

 

  • JSF에 이미 구현되어 있음 (javax.faces.webapp.FacesServlet)
  • FacesServlet 역할(Controller) 은 faces-config.xml 설정된 model 인 managed bean의 life scope 을 관리, view page 의 navigation rule 을 제어해주는 역할을 수행, 기타 등등 수행
  • web.xml 에 다음과 같이 설정

 

<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>

 

 

 

Model - Managed Beans

 

  • 이벤트 요청을 처리하거나 UIComponents 를 조작
  • faces-config.xml 에 설정되어야 사용가능
  • FacesContext 를 사용하여 JSF api 조작
  • useBean 과 같은 life scope 을 가짐
  1. application : Application 저장 -> 참조 : none, application
  2. session : Session 저장(반드시 java.io.Serializable 구현) -> 참조 : none, application, session
  3. request : Request 저장 -> 참조 : none, application, session, request
  4. none : page scope 와 동일 -> 참조 : none

 

 

 

View – jsp pages

  • UIComponents 의 조합으로 페이지 작성
  • taglib 선언

 

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

 

  • UIComponents 는 내에 작성되어야 함
  • 다양한 변환기, 검증기 제공(추가 구현)
  1. 변환기 구현 : javax.faces.convert.Converter
  2. 검증기 구현 : javax.faces.validator.Validator
  • 이벤트 리스너 구현(instance or method binding)
  1. instance 로 구현 : javax.faces.event.ActionListener
  2. method binding : public void applyLocale(ActionEvent event)

 

JSF 요청처리 생명주기

 

 

UIComponents Hierarchy

 


JSF 개발 방법

 

JSF 개발 순서

 

  • Base libraries 셋팅
  • 2. JSF 개발환경에 언급된 라이브러리를 WEB-INF/lib 위치
  • 추가적으로 필요한 라이브러리 설정
  • faces-config.xml 설정 (navigation-rule, managed-bean 등 설정)
  • Managed Bean 개발 (faces-config.xml 에 설정된 ManagedBean 사용)
  • jsp 페이지 개발 (faces-config.xml 에 설정된 navigation-rule, managed-bean 를 참조하여 Expression Language 를 사용하여 개발)
  • jsf 로 요청하여 테스트
  • jsf는 FacesServlet 의 Controller 를 통해 작동됨

 

 

 

faces-config.xml

 

  • faces-config.xml 기본 포멧

 

<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>
<managed-bean>
</managed-bean>
<navigation-rule>
</navigation-rule>
<application>
</application>
... Etc ...
</faces-config>

 

  • navigation-rule 설정 (faces-config.xml 에 설정된 navigation-rule)

 

<navigation-rule>
<from-view-id>/pages/ex_set_no_cache.jsp</from-view-id>
<navigation-case>
<from-outcome>ex_cache_result</from-outcome>
<to-view-id>/pages/ex_cache_result.jsp</to-view-id>
</navigation-case>
</navigation-rule>

 

  • managed-bean 설정 (faces-config.xml 에 설정된 managed-bean)

 

<managed-bean>
<managed-bean-name>orderMgmtBean</managed-bean-name>
<managed-bean-class>com.skcc.pilot.order.bean.OrderMgmtBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>productMgmtBean</property-name>
<value>#{productMgmtBean}</value>
</managed-property>
<managed-property>
<property-name>serviceMgmtBean</property-name>
<value>#{serviceMgmtBean}</value>
</managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>productMgmtBean</managed-bean-name>
<managed-bean-class>com.skcc.pilot.order.bean.ProductMgmtBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>serviceMgmtBean</managed-bean-name>
<managed-bean-class>com.skcc.pilot.order.bean.ServiceMgmtBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

 

  • message bundle 설정 : message 의 여러 locale 버젼을 설정 후 UIComponent 에서 변경, 적용 가능
  • 한글 message bundle 의 경우 native2ascii 로 인코딩 필요 (ant task 사용)

 

<application>
<message-bundle>com.skcc.pilot.jsf.resource.PilotMessage
</message-bundle>
<locale-config>
<!--default-locale>en</default-locale-->
<supported-locale>en</supported-locale>
</locale-config>
</application>

 

 

  • PilotMessage_kr.properties 가 추가되는 경우 다음을 추가함

 

<supported-locale>kr</supported-locale>

 

 

EL (Expression Language)

 

  • JSP 2.0 의 EL 근간 : ${}가 아닌 #{}
  • ex) bbsBean 의 getList() 메소드 호출 : #{bbsBean.list}
  • EL 로 내장객체 사용
  1. applicationScope, sessionScope, requestScope. etc..
  2. ex) session.getAttribute(“user”); -> #{sessionScope'user'}
  3. 내장객체의 경우 실제 객체에 binding 된 key,value의 모음인 Map 객체임
  4. ex) #{myMap[foo.bar.baz]}
  5. ex) #{myMap‘foo’.list5}
  6. EL 로 제어문 사용

#{view.locale != ‘en_US’} : true | false 리턴
#{(user.balance > 100) ? ‘loaded’ : ‘not loaded’}

 

 

 

EL 을 Managed bean 에서 사용

  • Value binding

 

ex) #{weather.temp / 32}
* example
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext ec = fc.getExternalContext();
HttpSession session = (HttpSession)ec.getSession(false);
User user = (User)Session.getAttribute(“user”);
* EL 사용하여 작성
FacesContext fc = FacesContext.getCurrentInstance();
Application app = fc.getApplication();
User user = (User)app.createValueBinding(“#{sessionScope[‘user’]}”).getValue(fc);

 

  • method binding

 

ex) #{myBean.methodName}
* example
<h:commandButton id="cmd_2“     value="apply locale by actionListener“
actionListener="#{fooLocaleTest.myActionListener}“
type="submit"/>
* EL 사용하여 작성
FacesContext fc = FacesContext.getCurrentInstance();
Application app = fc.getApplication();
MethodBinding mb = app.createMethodBinding(“#{myBean.myActionListener}”, new Class[] {ActionEvent.class});
myUICommand.setActionListener(mb);

 

 

 


Exadel Studio Pro 소개

 

 


NetAdvantage 소개

 

 


CCBS Pilot sample

 

 


JSF 요약

 

JSF 장점

  • JSF는 “J2EE 웹 애플리케이션에 사용되는 서버사이드 사용자 인터페이스 컴포넌트 프레임워크”라 정의
  • JSF는 기존의 HTML을 컴포넌트화하고, 클라이언트의 상태를 서버에서 관리하며, 브라우저에서 발생한 이벤트를 서버가 제어할 수 있도록 하여 스윙 스타일의 객체지향 웹 애플리케이션 개발이 가능
  • 재사용성 가능한 UI 컴포넌트로 UI 작성의 편리성
  • UI와 애플리케이션 데이터간의 데이터 변환이 용이함
  • server request를 통해 UI 상태를 서버에서 관리
  • 클라이언트가 발생시킨 이벤트를 서버 애플리케이션 코드가 관리하는 모델 제공
  • Custom UI 컴포넌트 개발의 용이성

 

 

JSF 단점

  • 최신 기술로서 Reference site 부재
  • JSF 를 사용하기 위해 많은 라이브러리 참조, 각 라이브러리 및 개발 환경의 버젼 복잡
  • JSF 로 구현된 jsp 페이지의 컴파일이 느리며 tag 및 managed bean 사용 시 에러 발생에 대한 디버깅 어려움
  • 특정 프로젝트의 UI Custom tag, 및 script 추가 개발 필요
  • 좀더 강력한 UI Design tools 필요(상용 tools)
  • UI Layer인 JSF에서 Business layer 의 framework 과 연동 고려
  • JSF navigation rule 및 managed bean의 설명을 위한 산출물 필요

Comments (0)

You don't have permission to comment on this page.