6

セッションからの値とイテレータからの葯の2つの値を比較しようとしています

<s:iterator value="themes" status="currentRecord"> 
    <s:if test="%{usertheme}) == %{themeName}">
        <td align="center" bgcolor="red">
    </s:if>
    <s:else>
        <td align="center" bgcolor="green">
    </s:else>
</s:iterator>

しかし、私は自分の価値観を比較することができません。どこで間違いを犯しているのか教えてください。

4

3 に答える 3

8

%{}(必要に応じて) 文の途中ではなく、すべての文の周りに配置する必要があります。

.equals文字列の場合は、、、など.equalsIgnoreCaseを使用する必要があります... ではありません。.contains.indexOf==

これに変更します。

<s:iterator value="themes" status="currentRecord"> 
   <s:if test="%{#session.usertheme.equalsIgnoreCase(themeName)}">
      <td align="center" bgcolor="red">
   </s:if>
   <s:else>
      <td align="center" bgcolor="yellow">
   </s:else>
....

これも機能します:

   <s:if test="#session.usertheme.equalsIgnoreCase(themeName)">
于 2012-12-24T15:47:27.600 に答える
5

(答えではありませんが、2 つの提案があり、書式設定が必要でした。Andrea の答えは正しいです。)

あなた自身と後に続く人のために、JSP のチャンクを 1 行に変えてください。

  <s:iterator value="themes">
    <tr>
      <s:set var="currTheme" value="%{userTheme == themeName ? 'red' : 'green'}"/>
      <td bgcolor="${currTheme}">Cell content</td>
    </tr>
  </s:iterator>

インライン CSS の代わりにテーマ名の CSS を使用することを検討し、大まかに言えば完全に回避します。

td.theme1 {
  background-color: red;
}

td.theme2 {
  background-color: green;
}

td.theme3 {
  background-color: #daa520;
}

(「theme1」、「theme2」、「theme3」という名前のテーマを想定していますが、それは関係ありません。)

<table class="themed-table">
  <s:iterator value="themes">
    <tr>
      <td class="${themeName}">Cell content</td>
    </tr>
  </s:iterator>
</table>

のように、スタイル情報を 1 レベル「上」に移動した方table.theme1 tdがよいでしょうが、アイデアはわかります。そうすることで、テーマ情報がどこから来るかなど、多くの柔軟性が可能になります。

于 2012-12-24T20:04:30.447 に答える
0
    <!--name attribute inside select tag must be a variable in action class with getter/setter -->
<!-- test variable sets the value of selected item in action class -->
<select name="test">
    <!-- name attribute could be anything you want but value attribute must be a model class variable-->
    <s:set name="lead_string_LS_ID" value="MasterDataModel.string_LS_ID" />
        <!-- value attribute must be a list to iterate, status (an instanceof IteratorStatus will be pushed into stack upon each iteration)or result  -->
        <!-- var Name used to reference the value pushed into the Value Stack (my list contain leadSource_String_Id)-->
        <s:iterator value="leadSource_list" status="result" var="leadSource_String_Id">
                <!--#lead_string_LS_ID is value taken from <set> tag above. Note # must be in-front of the name
                    leadSource_String_Id is element specified in var of <iterator> tag  
                -->
                <s:if test='(#lead_string_LS_ID.equals(leadSource_String_Id))'>

                    <option value="<s:property value='leadSource_String_Id'/>" selected="selected">
                        <s:property value="leadSource_String_Name" />
                    </option>
                </s:if>
                <s:else>
                    <option
                        value="<s:property value='leadSource_String_Id'/>">
                        <s:property value="leadSource_String_Name" />
                    </option>
                </s:else>
        </s:iterator>
</select>
于 2013-07-19T08:58:37.987 に答える