tomcat의 webapp/mayaa 디렉토리에 if.html과 if.mayaa파일을 작성해서 확인한다.
조건 분기
if.html
<html>
<body>
<span id="visible">
<span id="message">dummy message</span>
</span>
</body>
</html>
if.mayaa
<?xml version="1.0" encoding="UTF-8"?>
<m:mayaa xmlns:m="http://mayaa.seasar.org">
<m:if m:id="visible" test="${ 1 == 1 }" />
<m:write m:id="message" value="Hello Mayaa!" />
</m:mayaa>
test결과가 true이므로 id="message"의 태그의 내부가 유효가 된다. 단 자신의 replace="true"이므로 표시되지 않는다. m:if와 m:write가 따로 따로 기술된 점에 주의한다. 마야 엔진은 html의 구조를 기준으로 처리하기 때문에 mayaa자체의 순서는 의미가 없다.
실행결과:
<html>
<body>
Hello Mayaa!
</body>
</html>
test결과가 false이면 물론 출력되지 않는다.
<?xml version="1.0" encoding="UTF-8"?>
<m:mayaa xmlns:m="http://mayaa.seasar.org">
<m:if m:id="visible" test="${ 1 < 1 }" />
<m:write m:id="message" value="Hello Mayaa!" />
</m:mayaa>
실행결과:
<html>
<body>
</body>
</html>
xml의 속성을 적을때 escape해야 하는 것에 주의한다.(< → < , > → > , & → &)
루프
루프는 아래와 같이 한다.
for.html
<html>
<body>
<span id="loop">
<span id="message">dummy message</span>
</span>
</body>
</html>
for.mayaa
<?xml version="1.0" encoding="UTF-8"?>
<m:mayaa xmlns:m="http://mayaa.seasar.org">
<m:for m:id="loop"
init="${ var i = 0 }"
test="${ i < 5 }"
after="${ i++ }" />
<m:write m:id="message"
value="Hello Mayaa!<br>" escapeXml="false" />
</m:mayaa>
init을 먼저 처리한 후, test결과가 true일 동안 body를 실행하고 마지막으로 after를 실행하게 된다. message를 출력할 때 <br>을 <br>로 변환되어서 출력되는 것을 방지하기위해 excapeXml을 false로 지정한다.
실행결과:
<html>
<body>
Hello Mayaa!<br>
Hello Mayaa!<br>
Hello Mayaa!<br>
Hello Mayaa!<br>
Hello Mayaa!<br>
</body>
</html>
i는 <span id="loop">의 내부가 가시영역이다.
<m:write m:id="message" vlaue="${i}"...
라는 식으로 출력하거나 접근할 수 있다.