pirkak公式サイト|株式会社 オリエンタルアーツ
HOMEpirka TOP > サンプル集
pirka サンプル集

> 戻る

多重ループ内のラジオボタンの使い方


≪サンプル説明≫  

サンプル画面のラジオボタンはどれも同じ2重ループ(外側:3ループ、内側:4ループ)中にあります。

左欄(青)のラジオボタンのgroupLevelは全て2が設定されています。
そのためラジオボタンは2重ループの2つ外側、つまりループの外となり
全ラジオボタンが同じグループに属すため、左欄で一度に選択できるラジオボタンは1つだけとなります。

中欄(緑)のラジオボタンのgroupLevelは全て1が設定されています。
そのためラジオボタンは2重ループの1つ外側、つまり外側のループ単位で同じ
グループに属すため、中欄ので一度に選択できるラジオボタンは外側のループ数と同じ3つとなります。

右欄(赤)のラジオボタンのgroupLevelは全て0(デフォルト)が設定されています。
そのためラジオボタンは2重ループの一番内側のループ単位で同じグループに属します。
右欄ので一度に選択できるラジオボタンは外側のループ数(3)x内側のループ数(4)と同じ12個となります。


≪作成時注意点≫ 

・多重の繰り返し(ループ)中のラジオボタンのグループの制御はgroupLevel
 プロパティを設定することにより任意のループ階層でのグループの指定が可能です。

・デフォルトではgroupLevelは0でありループの最深でグループ化されます。

・1を指定すると一つ外側のループの繰り返し単位でグループ化されます。
 以降一つ増える毎に外側のループでグループ化されます。

・groupLevelの設定はsetGroupLoopLevelメソッドを使用して設定します。

 【例】FieldMap field = getFieldMap();

    for (int i = 0; i < 3; i++) {
    FieldMap newField = createLoopFieldMap("loop1");
    field.addFieldMap("loop1", newField);

    for (int j = 0; j < 4; j++) {
    FieldMap newField2 = createLoopFieldMap("loop2");
    newField.addFieldMap("loop2", newField2);
    newField2.setValue("r$s1", "r1-" + i + "-" + j);
    newField2.setGroupLoopLevel("r$s1", 2);

・チェック状態の取得・設定はgroupLevelで指定されるループのフィールドマップに
 対してgetGroupValueメソッド、setGroupValueメソッドを使用してください。


ソースファイル
LoopRadio.html  サンプル画面のHTMLファイル

<html>
<head>
<head>
<title>pirka逆引きサンプル 多重ループ内のラジオボタンの使い方</title>
</head>
<body>
<center>
<span style="color: #8080ff">pirka逆引きサンプル 多重ループ内のラジオボタンの使い方</span><br>
<hr>
<br>
<span name="errorMessage" style="color: #ff0000"></span>
<br>
<br>
<form name="testForm" method="post">
ループ時のラジオボタン<br>
<table border="2">
<tr>
<th>groupeLevel=2</th><th>groupeLevel=1</th><th>groupeLevel=0</th>
</tr>
<div type="loop" name="loop1">
<div type="loop" name="loop2">
<tr>
<td name="td01">
<input type="radio" name="r$s1" id="r_s1"><label name="label_s1" for="r_s1"></label>&nbsp;
<input type="radio" name="r$s2" id="r_s2"><label name="label_s2" for="r_s2"></label>&nbsp;
</td>
<td name="td02">
<input type="radio" name="r$s3" id="r_s3"><label name="label_s3" for="r_s3"></label>&nbsp;
<input type="radio" name="r$s4" id="r_s4"><label name="label_s4" for="r_s4"></label>&nbsp;
</td>
<td name="td03">
<input type="radio" name="r$s5" id="r_s5"><label name="label_s5" for="r_s5"></label>&nbsp;
<input type="radio" name="r$s6" id="r_s6"><label name="label_s6" for="r_s6"></label>&nbsp;
</td>
</tr>
</div>
</div>
</table>
<br><br>
選択 【 <span name="msg"></span> 】<br><br>
<input type="submit" name="exec2Button" value="radio1-1-3 radio4-1-3をONにする">
<BR><BR>

<input type="submit" name="execButton" value="チェック値取得">&nbsp;
<input type="submit" name="returnButton" value="戻る"><Br>
<BR><BR>

</form>
</center>
</body>
</html>




LoopRadio.java  サンプル画面のJavaソースファイル

package jp.oarts.pirka.sample.instruction.is102700;

import jp.oarts.pirka.core.kernel.FieldMap;
import jp.oarts.pirka.core.win.PirkaWindow;

public class LoopRadio extends PirkaWindow {

/**
* コンストラクタ
*/
public LoopRadio() {
FieldMap field = getFieldMap();

// ループ作成
int c = 0;
for (int i = 0; i < 3; i++) {
FieldMap newField = createLoopFieldMap("loop1");
field.addFieldMap("loop1", newField);

for (int j = 0; j < 4; j++) {
FieldMap newField2 = createLoopFieldMap("loop2");
newField.addFieldMap("loop2", newField2);

newField2.setOption("td01", "style", "background-color: #c0c0ff");

newField2.setValue("r$s1", "r1-" + i + "-" + j);
newField2.setGroupLoopLevel("r$s1", 2);
newField2.setValue("label_s1", "radio1-" + i + "-" + j);

newField2.setValue("r$s2", "r2-" + i + "-" + j);
newField2.setGroupLoopLevel("r$s2", 2);
newField2.setValue("label_s2", "radio2-" + i + "-" + j);

if ((i % 2) == 0) {
newField2.setOption("td02", "style", "background-color: #d0ffd0");
} else {
newField2.setOption("td02", "style", "background-color: #a0ffa0");
}
newField2.setValue("r$s3", "r3-" + i + "-" + j);
newField2.setGroupLoopLevel("r$s3", 1);
newField2.setValue("label_s3", "radio3-" + i + "-" + j);

newField2.setValue("r$s4", "r4-" + i + "-" + j);
newField2.setGroupLoopLevel("r$s4", 1);
newField2.setValue("label_s4", "radio4-" + i + "-" + j);

if (((c++) % 2) == 0) {
newField2.setOption("td03", "style", "background-color: #ffa0a0");
} else {
newField2.setOption("td03", "style", "background-color: #ffd0d0");
}
newField2.setValue("r$s5", "r5-" + i + "-" + j);
newField2.setValue("label_s5", "radio5-" + i + "-" + j);

newField2.setValue("r$s6", "r6-" + i + "-" + j);
newField2.setValue("label_s6", "radio6-" + i + "-" + j);
}
}
}

/**
* チェック値取得ボタン処理
*/
public void execButton() {
FieldMap field = getFieldMap();

StringBuilder sb = new StringBuilder();
sb.append(field.getGroupValue("r"));
sb.append(" ");

int size1 = field.getFieldMapSize("loop1");
for (int i = 0; i < size1; i++) {
FieldMap loop1Field = field.getFieldMap("loop1", i);
sb.append(loop1Field.getGroupValue("r"));
sb.append(" ");

int size2 = loop1Field.getFieldMapSize("loop2");
for (int j = 0; j < size2; j++) {
FieldMap loop2Field = loop1Field.getFieldMap("loop2", j);
sb.append(loop2Field.getGroupValue("r"));
sb.append(" ");
}
}
field.setValue("msg", sb.toString());
}

/**
* radio1-1-3 radio4-1-3をONにするボタン処理
*/
public void exec2Button() {
FieldMap field = getFieldMap();

field.setGroupValue("r", "r1-1-3");

FieldMap loop1Field = field.getFieldMap("loop1", 1);
loop1Field.setGroupValue("r", "r4-1-3");
}

/**
* 戻るボタン処理
*/
public PirkaWindow returnButton() {
return null;
}

}

ページのTOPへ このページの先頭へ
oriental arts pirka