struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amashche...@apache.org
Subject [struts] 04/06: Add listTitle to optgroup tag
Date Thu, 13 Dec 2018 20:50:55 GMT
This is an automated email from the ASF dual-hosted git repository.

amashchenko pushed a commit to branch struts-2-5-x
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 1d49a062725a8eada6b96dac38cf9978a59b3340
Author: Aleksandr Mashchenko <amashchenko@apache.org>
AuthorDate: Tue Dec 4 23:02:31 2018 +0200

    Add listTitle to optgroup tag
    
    (cherry picked from commit 123a0906ce455c8ea7dc6a7580159a614c0b46bb)
---
 .../main/java/org/apache/struts2/components/OptGroup.java    |  5 +++++
 .../java/org/apache/struts2/views/jsp/ui/OptGroupTag.java    |  6 ++++++
 core/src/main/resources/template/simple/optgroup.ftl         |  9 +++++++++
 core/src/site/resources/tags/optgroup.html                   |  8 ++++++++
 .../java/org/apache/struts2/views/jsp/ui/OptGroupTest.java   |  2 ++
 .../resources/org/apache/struts2/views/jsp/ui/OptGroup-8.txt | 12 ++++++------
 6 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/core/src/main/java/org/apache/struts2/components/OptGroup.java b/core/src/main/java/org/apache/struts2/components/OptGroup.java
index 3042989..28c6783 100644
--- a/core/src/main/java/org/apache/struts2/components/OptGroup.java
+++ b/core/src/main/java/org/apache/struts2/components/OptGroup.java
@@ -150,4 +150,9 @@ public class OptGroup extends Component {
     public void setListCssStyle(String listCssStyle) {
         internalUiBean.setListCssStyle(listCssStyle);
     }
+
+    @StrutsTagAttribute(description = "Property of list objects to get title from")
+    public void setListTitle(String listTitle) {
+        internalUiBean.setListTitle(listTitle);
+    }
 }
diff --git a/core/src/main/java/org/apache/struts2/views/jsp/ui/OptGroupTag.java b/core/src/main/java/org/apache/struts2/views/jsp/ui/OptGroupTag.java
index 870c754..bd90ff5 100644
--- a/core/src/main/java/org/apache/struts2/views/jsp/ui/OptGroupTag.java
+++ b/core/src/main/java/org/apache/struts2/views/jsp/ui/OptGroupTag.java
@@ -38,6 +38,7 @@ public class OptGroupTag extends ComponentTagSupport {
     protected String listValue;
     protected String listCssClass;
     protected String listCssStyle;
+    protected String listTitle;
 
     public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse
res) {
         return new OptGroup(stack, req, res);
@@ -54,6 +55,7 @@ public class OptGroupTag extends ComponentTagSupport {
         optGroup.setListValue(listValue);
         optGroup.setListCssClass(listCssClass);
         optGroup.setListCssStyle(listCssStyle);
+        optGroup.setListTitle(listTitle);
     }
 
     public void setList(String list) {
@@ -83,4 +85,8 @@ public class OptGroupTag extends ComponentTagSupport {
     public void setListCssStyle(String listCssStyle) {
         this.listCssStyle = listCssStyle;
     }
+
+    public void setListTitle(String listTitle) {
+        this.listTitle = listTitle;
+    }
 }
diff --git a/core/src/main/resources/template/simple/optgroup.ftl b/core/src/main/resources/template/simple/optgroup.ftl
index 0f04f21..a424fe7 100644
--- a/core/src/main/resources/template/simple/optgroup.ftl
+++ b/core/src/main/resources/template/simple/optgroup.ftl
@@ -47,6 +47,12 @@
 			<#assign optGroupItemCssStyle= stack.findString(optGroupInternalListUiBean.parameters.listCssStyle)/>
 		</#if>
 	</#if>
+	<#assign optGroupItemTitle = ''/>
+	<#if optGroupInternalListUiBean.parameters.listTitle??>
+		<#if stack.findString(optGroupInternalListUiBean.parameters.listTitle)??>
+			<#assign optGroupItemTitle= stack.findString(optGroupInternalListUiBean.parameters.listTitle)/>
+		</#if>
+	</#if>
 	<option value="${tmpKeyStr?html}"<#rt>
 	<#if tag.contains(parameters.nameValue, tmpKey) == true>
 	selected="selected"<#rt>
@@ -57,6 +63,9 @@
 	<#if optGroupItemCssStyle?has_content>
 	style="${optGroupItemCssStyle?html}"<#rt/>
 	</#if>
+	<#if optGroupItemTitle?has_content>
+	title="${optGroupItemTitle?html}"<#rt/>
+	</#if>
 	>${tmpValue?html}<#t>
 	</option><#lt>
 <#assign trash=stack.pop() />
diff --git a/core/src/site/resources/tags/optgroup.html b/core/src/site/resources/tags/optgroup.html
index 111fdae..5a57e95 100644
--- a/core/src/site/resources/tags/optgroup.html
+++ b/core/src/site/resources/tags/optgroup.html
@@ -82,6 +82,14 @@ Please do not edit it directly.
 					<td align="left" valign="top">Set the listKey attribute.</td>
 				</tr>
 				<tr>
+					<td align="left" valign="top">listTitle</td>
+					<td align="left" valign="top">false</td>
+					<td align="left" valign="top"></td>
+					<td align="left" valign="top">false</td>
+					<td align="left" valign="top">String</td>
+					<td align="left" valign="top">Property of list objects to get title from</td>
+				</tr>
+				<tr>
 					<td align="left" valign="top">listValue</td>
 					<td align="left" valign="top">false</td>
 					<td align="left" valign="top"></td>
diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/OptGroupTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ui/OptGroupTest.java
index 4505c5b..07da6f6 100644
--- a/core/src/test/java/org/apache/struts2/views/jsp/ui/OptGroupTest.java
+++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/OptGroupTest.java
@@ -260,12 +260,14 @@ public class OptGroupTest extends AbstractUITagTest {
         selectTag.setList("%{#{'ONE':'one','TWO':'two','THREE':'three'}}");
         selectTag.setListCssClass("'option-css-class'");
         selectTag.setListCssStyle("'background-color: green;'");
+        selectTag.setListTitle("'option-title'");
 
         OptGroupTag optGroupTag1 = new OptGroupTag();
         optGroupTag1.setLabel("My Label 1");
         optGroupTag1.setList("%{#{'AAA':'aaa','BBB':'bbb','CCC':'ccc'}}");
         optGroupTag1.setListCssClass("'optgroup-option-css-class'");
         optGroupTag1.setListCssStyle("'background-color: blue;'");
+        optGroupTag1.setListTitle("'optgroup-option-title'");
 
         OptGroupTag optGroupTag2 = new OptGroupTag();
         optGroupTag2.setLabel("My Label 2");
diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/OptGroup-8.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/OptGroup-8.txt
index 52de292..fbde2bc 100644
--- a/core/src/test/resources/org/apache/struts2/views/jsp/ui/OptGroup-8.txt
+++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/OptGroup-8.txt
@@ -2,21 +2,21 @@
     <td class="tdLabel"><label for="mySelection" class="label">My Selection:</label></td>
     <td class="tdInput">
 <select name="mySelection" id="mySelection">
-    <option value="ONE" class="option-css-class" style="background-color: green;">one</option>
-    <option value="TWO" class="option-css-class" style="background-color: green;">two</option>
-    <option value="THREE" class="option-css-class" style="background-color: green;">three</option>
+    <option value="ONE" class="option-css-class" style="background-color: green;" title="option-title">one</option>
+    <option value="TWO" class="option-css-class" style="background-color: green;" title="option-title">two</option>
+    <option value="THREE" class="option-css-class" style="background-color: green;" title="option-title">three</option>
 
 <optgroup 
     label="My Label 1"
 >
 
-    <option value="AAA" class="optgroup-option-css-class" style="background-color: blue;"
+    <option value="AAA" class="optgroup-option-css-class" style="background-color: blue;"
title="optgroup-option-title"
     >aaa
     </option>
-    <option value="BBB" class="optgroup-option-css-class" style="background-color: blue;"
+    <option value="BBB" class="optgroup-option-css-class" style="background-color: blue;"
title="optgroup-option-title"
     >bbb
     </option>
-    <option value="CCC" class="optgroup-option-css-class" style="background-color: blue;"
+    <option value="CCC" class="optgroup-option-css-class" style="background-color: blue;"
title="optgroup-option-title" 
     >ccc
     </option>
 </optgroup>


Mime
View raw message