7. 태그 라이브러리
struts2 태그는 일반 태그(Generic Tag)와 사용자 인터페이스 태그(UI Tag)로 나뉜다. 일반 태그는 컨트로 태그
(Control Tag)와 데이터 태그(Data Tag)로 구성된다. 사용자 인터페이스 태그는 태스크 폼 태그(Form Tag)와
넌 폼 태그(Non-Form Tag)로 구성된다.
- 일반 태그
- 컨트로 태그: if~elseif~else, append, generator, iterator, merge, sort, subset
- 데이터 태그: a, action, bean, date, debug, i18n, include, param, push, set, text, url, property
- 사용자 인터페이스 태그
- 폼 태그: checkbox, checkboxlist, combobox, datetimepicker, doubleselect, head, file, form, hidden, label
optiontransferselect, optgroup, password, reset, select, submit, textarea, textfield, token, updownselect
- 넌-폼 태그: checkbox, checkboxlist, combobox, datetimepicker, doubleselect, head, file, form, hidden, label,
optiontransferselect, optgroup, password, reset, select, submit, textarea, textfield, token,
updownselect, actionerror, actionmessage, component, div, fielderror, table, tabbedPanel,
tree, treenode
7.1. 태그 라이브러리 설정
<%@ taglib prefix=”s” uri=”/struts-tags” %>
[형식]
<s:tagName name=”property” />
7.2. OGNL
OGNL은 Object Graph Navigation Language의 약어. OGNL 표현식을 사용하여 밸류스택에 저장된 여러
액션 객체의 정보를 얻어온다.
밸류스택은 XWork와 스트럿츠2의 동적 컨텍스트 기반의 핵심 부분으로 객체의 스택이다.
스트럿츠2에서는 액션이 실행될 때마다 액션을 스택 상에 저장하여 밸류스택이 구축된다.
액션이 실행되는 동안 밸류스택에 쌓인 여러 개의 액션 객체의 정보를 스트럿츠2의 태그 라이브러리는
OGNL 표현식으로 얻어온다.
예)
아이디: <input type=”text” name=”userid” value=”${userid}” />
==
<s:textfield label=”아이디” name=”userid” value=”%{userid}” />
스트럿츠2에서는 %{…} 내에 기술된 내용을 OGNL 표현식으로 평가한다.
[Login.java]
public class Login extends ActionSupport{
private String userid;
private String username;
private String message;
[Login.jsp]
<%@ tablib prefix=”s” uri=”/struts-tags” %>
<s:property value=”username” />
<s:property value=”message” />
<s:textfield label=”아이디” name=”userid” value=”%{userid}” />
- OGNL 참조 개체
- application
- session
- value stack
- request
- parameters
- attr
OGNL은 액션 컨텍스트의 객체를 참조하기 위해 #application, #session, #request, #attr, #parameters와 같이
#기호를 사용한다.
예)
<s:property value=”#session.user” />
'Struts2' 카테고리의 다른 글
리절트 개요와 종류 (0) | 2014.12.11 |
---|---|
스트럿츠2 아키텍쳐 (0) | 2014.12.11 |
도메인 오브젝트 (0) | 2014.12.11 |
Action (0) | 2014.12.11 |
struts.xml (0) | 2014.12.11 |