読者です 読者をやめる 読者になる 読者になる

liguofeng29’s blog

個人勉強用ブログだっす。

Struts2 - タグ - UIタグ

struts2のUIタグは、formタグと非formタグ2種類ある。

formタグ

非formタグ

  • actionerror : getActionErrors() != nullの場合、内容出力
  • actionmessage : getActionMessages() != nullの場合、内容出力
  • fielderror : データ変換、検証エラーの場合、内容出力
  • component : カスタム部品を生成

checkboxlist

<%@ page contentType="text/html; charset=UTF-8" language="java" errorPage="" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
    <title>s:checkboxlistタグ</title>
    <s:head/>
</head>
<body>
<h3>s:checkboxlistは複数のcheckboxを生成する</h3>
<s:form>
<!-- List -->
<s:checkboxlist
    name="a"
    label="List"
    labelposition="top"
    list="{'checkbox1', 'checkbox2', 'checkbox3'}"/>

<!-- Map -->
<s:checkboxlist name="b" label="Map"
    labelposition="top"
    list="#{'key1':'value1','key2':'value2','key3':'value3'}"
    listKey="key"
    listValue="value"/>
</s:form>
</body>
</html>

f:id:liguofeng29:20160324213114p:plain

radio

<%@ page contentType="text/html; charset=UTF-8" language="java" errorPage="" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
    <title>s:radio</title>
    <s:head/>
</head>
<body>
<h3>s:radioは複数のradioボタンを生成する</h3>
<s:form>
<!-- List -->
<s:radio name="a"
    label="List"
    labelposition="top"
    list="{'checkbox1', 'checkbox2', 'checkbox3'}"/>

<!-- Map -->
<s:radio name="b" label="Map"
    labelposition="top"
    list="#{'key1':'value1','key2':'value2','key3':'value3'}"
    listKey="key"
    listValue="value"/>
</s:form>
</body>
</html>

f:id:liguofeng29:20160324213435p:plain

select

<%@ page contentType="text/html; charset=UTF-8" language="java" errorPage="" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
    <title>s:select</title>
    <s:head/>
</head>
<body>
<h3>s:selectはプルダウンを生成する</h3>
<s:form>
<!-- List -->
<s:select name="a" label="LIST_SELECT" labelposition="top"
    multiple="true"
    list="{'要素1','要素2','要素33333333333333'}"/>

<!-- Map -->
<s:select name="b" label="MAP_SELECT" labelposition="top"
    list="#{'key1':'value1','key2':'value2','key3':'value3'}"
    listKey="key"
    listValue="value"/>
</s:form>
</body>
</html>

f:id:liguofeng29:20160324213734p:plain

optgroup

<%@ page contentType="text/html; charset=UTF-8" language="java" errorPage="" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
    <title>s:optgroupタグ</title>
    <s:head/>
</head>
<body>
<h3>s:optgroupはプルダウンのoption groupを生成する</h3>
<s:form>
<!-- 直接使用Map为列表框生成选项 -->
<s:select label="MAP" name="element" size="15"
    list="#{'key1':'value2'
      ,'key2':'value2'
      ,'key3':'value3'}"
    listKey="value"
    listValue="key">

    <!-- 使用Map对象来生成选择框的选项组 -->
    <s:optgroup label="Rod Johnson"
        list="#{'key10':'value10','key11':'value11','key12':'value12'}"
        listKey="value"
        listValue="key"/>

    <s:optgroup label="David Flanagan"
        list="#{'key20':'value20','key21':'value21','key22':'value22'}"
        listKey="value"
        listValue="key"/>
</s:select>
</s:form>
</body>
</html>

f:id:liguofeng29:20160324214241p:plain

updownselect

<%@ page contentType="text/html; charset=UTF-8" language="java" errorPage="" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
    <title>s:updownselectタグ</title>
    <s:head/>
</head>
<body>
<h3>s:updownselectは移動できるプルダウンを生成する</h3>
<s:form>

<!-- 
属性
allowMoveUp
allowmoveDown
allowSelectAll
moveUpLabel
moveDownLable
selectAllLabel
 -->
<s:updownselect name="a" label="移動可能SELECT1"
    labelposition="top"
    moveUpLabel="上移動"
    list="{'要素1', '要素2', '要素3'}"/>


<s:updownselect name="b" label="移動可能SELECT2"
    labelposition="top"
    moveDownLabel="下移動"
    list="#{'key1':'value1','key2':'value2','key3':'value3'}"
    listKey="key"
    emptyOption="true"
    listValue="value"/>
</s:form>
</body>
</html>

f:id:liguofeng29:20160324214757g:plain

doubleselect

<%@ page contentType="text/html; charset=UTF-8" language="java" errorPage="" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
    <title>s:doubleselectタグ</title>
    <s:head/>
</head>
<body>
<h3>s:doubleselect</h3>

<s:set name="map1" value="#{'key1': {'value1-1','value1-2','value1-3'},
  'key2': {'value2-1','value2-2'},
  'key3': {'value3-1','value3-2','value3-3'}}"/>

<s:form action="x">
    <s:doubleselect
        label="選択"
        size="3"
        name="author" list="#map1.keySet()"
        doubleList="#map1[top]"
        doubleSize="3"
        doubleName="child"/>
</s:form>
</body>
</html>

f:id:liguofeng29:20160324215729g:plain

optiontransferselect

<%@ page contentType="text/html; charset=UTF-8" language="java" errorPage="" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
    <title>s:optiontransferselectタグ</title>
    <s:head/>
</head>
<body>
<h3>s:optiontransferselect</h3>
<s:form>

 <s:optiontransferselect
    label="要素一覧"
    name="elementList"
    leftTitle="LEFT:"
    rightTitle="RIGHT:"
    list="{'要素1' ,'要素2','要素3','要素4'}"
    multiple="true"
    addToLeftLabel="←"
    selectAllLabel="SELCT ALL"
    addAllToRightLabel="⇒"
    headerKey="key-left"
    headerValue="--- LEFT ELEMENT ---"
    emptyOption="true"
    doubleList="{'要素5','要素6'}"
    doubleName="enBook"
    doubleHeaderKey="key-right"
    doubleHeaderValue="--- RIGHT ELEMENT ---"
    doubleEmptyOption="true"
    doubleMultiple="true"
/>
</s:form>
</body>
</html>

f:id:liguofeng29:20160324220727p:plain