struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (WW-4987) Setting Struts2 <s:select> options Css Class
Date Thu, 06 Dec 2018 09:09:00 GMT

    [ https://issues.apache.org/jira/browse/WW-4987?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16711169#comment-16711169
] 

ASF GitHub Bot commented on WW-4987:
------------------------------------

lukaszlenart closed pull request #286: WW-4987 Add list attributes to optgroup tag
URL: https://github.com/apache/struts/pull/286
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 95d94d26e..5f2e2ace2 100644
--- a/core/src/main/java/org/apache/struts2/components/OptGroup.java
+++ b/core/src/main/java/org/apache/struts2/components/OptGroup.java
@@ -140,4 +140,19 @@ public void setListKey(String listKey) {
     public void setListValue(String listValue) {
         internalUiBean.setListValue(listValue);
     }
+
+    @StrutsTagAttribute(description = "Property of list objects to get css class from")
+    public void setListCssClass(String listCssClass) {
+        internalUiBean.setListCssClass(listCssClass);
+    }
+
+    @StrutsTagAttribute(description = "Property of list objects to get css style from")
+    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 da2c1dcd4..bd90ff5a3 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
@@ -36,6 +36,9 @@
     protected String disabled;
     protected String listKey;
     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);
@@ -50,6 +53,9 @@ protected void populateParams() {
         optGroup.setDisabled(disabled);
         optGroup.setListKey(listKey);
         optGroup.setListValue(listValue);
+        optGroup.setListCssClass(listCssClass);
+        optGroup.setListCssStyle(listCssStyle);
+        optGroup.setListTitle(listTitle);
     }
 
     public void setList(String list) {
@@ -71,4 +77,16 @@ public void setListKey(String listKey) {
     public void setListValue(String listValue) {
         this.listValue = listValue;
     }
+
+    public void setListCssClass(String listCssClass) {
+        this.listCssClass = listCssClass;
+    }
+
+    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 765591cca..fc4c78fda 100644
--- a/core/src/main/resources/template/simple/optgroup.ftl
+++ b/core/src/main/resources/template/simple/optgroup.ftl
@@ -35,10 +35,31 @@
 	<#assign tmpKey=stack.findValue(optGroupInternalListUiBean.parameters.listKey) />
 	<#assign tmpValue=stack.findValue(optGroupInternalListUiBean.parameters.listValue) />
 	<#assign tmpKeyStr = tmpKey.toString() />
+	<#assign optGroupItemCssClass = ''/>
+	<#if optGroupInternalListUiBean.parameters.listCssClass??>
+		<#assign optGroupItemCssClass= stack.findString(optGroupInternalListUiBean.parameters.listCssClass)!''/>
+	</#if>
+	<#assign optGroupItemCssStyle = ''/>
+	<#if optGroupInternalListUiBean.parameters.listCssStyle??>
+		<#assign optGroupItemCssStyle= stack.findString(optGroupInternalListUiBean.parameters.listCssStyle)!''/>
+	</#if>
+	<#assign optGroupItemTitle = ''/>
+	<#if optGroupInternalListUiBean.parameters.listTitle??>
+		<#assign optGroupItemTitle= stack.findString(optGroupInternalListUiBean.parameters.listTitle)!''/>
+	</#if>
 	<option value="${tmpKeyStr?html}"<#rt>
 	<#if tag.contains(parameters.nameValue, tmpKey) == true>
 	selected="selected"<#rt>
 	</#if>
+	<#if optGroupItemCssClass?has_content>
+	class="${optGroupItemCssClass?html}"<#rt/>
+	</#if>
+	<#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 3198d0e6d..5a57e954d 100644
--- a/core/src/site/resources/tags/optgroup.html
+++ b/core/src/site/resources/tags/optgroup.html
@@ -57,6 +57,22 @@ <h2>Attributes</h2>
 					<td align="left" valign="top">String</td>
 					<td align="left" valign="top">Set the list attribute.</td>
 				</tr>
+				<tr>
+					<td align="left" valign="top">listCssClass</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 css class from</td>
+				</tr>
+				<tr>
+					<td align="left" valign="top">listCssStyle</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 css style from</td>
+				</tr>
 				<tr>
 					<td align="left" valign="top">listKey</td>
 					<td align="left" valign="top">false</td>
@@ -65,6 +81,14 @@ <h2>Attributes</h2>
 					<td align="left" valign="top">String</td>
 					<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>
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 d4bd0e2d9..5a2b35153 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
@@ -253,4 +253,40 @@ public void testOptGroupWithValueKey() throws Exception {
         verify(SelectTag.class.getResource("OptGroup-6.txt"));
     }
 
+    public void testOptGroupListAttributes() throws Exception {
+        SelectTag selectTag = new SelectTag();
+        selectTag.setName("mySelection");
+        selectTag.setLabel("My Selection");
+        selectTag.setList("#{'ONE':'one','TWO':'two','THREE':'three'}");
+        selectTag.setListCssClass("'option-css-class ' + key");
+        selectTag.setListCssStyle("'background-color: green; font-family: ' + key");
+        selectTag.setListTitle("'option-title' + key");
+
+        OptGroupTag optGroupTag1 = new OptGroupTag();
+        optGroupTag1.setLabel("My Label 1");
+        optGroupTag1.setList("#{'AAA':'aaa','BBB':'bbb','CCC':'ccc'}");
+        optGroupTag1.setListCssClass("'optgroup-option-css-class ' + key");
+        optGroupTag1.setListCssStyle("'background-color: blue; font-family: ' + key");
+        optGroupTag1.setListTitle("'optgroup-option-title' + key");
+
+        OptGroupTag optGroupTag2 = new OptGroupTag();
+        optGroupTag2.setLabel("My Label 2");
+        optGroupTag2.setList("#{'DDD':'ddd','EEE':'eee','FFF':'fff'}");
+        optGroupTag2.setListCssClass("notExistingProperty");
+        optGroupTag2.setListCssStyle("notExistingProperty");
+        optGroupTag2.setListTitle("notExistingProperty");
+
+        selectTag.setPageContext(pageContext);
+        selectTag.doStartTag();
+        optGroupTag1.setPageContext(pageContext);
+        optGroupTag1.doStartTag();
+        optGroupTag1.doEndTag();
+        optGroupTag2.setPageContext(pageContext);
+        optGroupTag2.doStartTag();
+        optGroupTag2.doEndTag();
+        selectTag.doEndTag();
+
+        //System.out.println(writer.toString());
+        verify(SelectTag.class.getResource("OptGroup-8.txt"));
+    }
 }
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
new file mode 100644
index 000000000..79468fe93
--- /dev/null
+++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/OptGroup-8.txt
@@ -0,0 +1,40 @@
+<tr>
+    <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 ONE" style="background-color: green; font-family:
ONE" title="option-title ONE">one</option>
+    <option value="TWO" class="option-css-class TWO" style="background-color: green; font-family:
TWO" title="option-title TWO">two</option>
+    <option value="THREE" class="option-css-class THREE" style="background-color: green;
font-family: THREE" title="option-title THREE">three</option>
+
+<optgroup 
+    label="My Label 1"
+>
+
+    <option value="AAA" class="optgroup-option-css-class AAA" style="background-color:
blue; font-family: AAA" title="optgroup-option-title AAA"
+    >aaa
+    </option>
+    <option value="BBB" class="optgroup-option-css-class BBB" style="background-color:
blue; font-family: BBB" title="optgroup-option-title BBB"
+    >bbb
+    </option>
+    <option value="CCC" class="optgroup-option-css-class CCC" style="background-color:
blue; font-family: CCC" title="optgroup-option-title CCC" 
+    >ccc
+    </option>
+</optgroup>
+<optgroup 
+    label="My Label 2"
+>
+
+    <option value="DDD"
+    >ddd
+    </option>
+    <option value="EEE"
+    >eee
+    </option>
+    <option value="FFF"
+    >fff
+    </option>
+</optgroup>
+
+</select>
+</td>
+</tr>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Setting Struts2 <s:select> options Css Class
> --------------------------------------------
>
>                 Key: WW-4987
>                 URL: https://issues.apache.org/jira/browse/WW-4987
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Tags
>    Affects Versions: 2.5.17
>            Reporter: Muhammad Salman
>            Assignee: Aleksandr Mashchenko
>            Priority: Major
>             Fix For: 2.6, 2.5.19
>
>         Attachments: optgroup.ftl, select.ftl, struts.log
>
>
> Hi
> I am working on an application that is built on struts 2.5.17. I have {{<s:select>}}
tag with <optgroup> and <option>. I am trying to add cssClass to <options>
under <optgroup>. I am trying to add css class to <option> using listCssClass
attribute of {{<s:select>}} but it is not adding class to the <option>. Any help
would be much appreciated.
> Here is code from my JSP:
> {code:xml}
> <s:select list="#\{'none':'-Select Template-'}" id="export-data" cssStyle="width:250px;"
title="templateDesc" cssClass="templateType" onchange="adjustReportText()" name="templateID"
listCssClass="templateType"> 
> <s:iterator value="\{SOME MAP WITH KEY AND LIST OF VALUES}" var="TG" status="stat">

> <s:optgroup label="%\{key}" list="%\{value}" listKey="templateId" listValue="templateName"
></s:optgroup> 
> </s:iterator> 
> </s:select>
> {code}
>  Initially we were working on struts 2.2.3 version and in that version, cssClass attribute
populates the CSS Class for <option>, but in 2.5.17 neither cssClass is populated class
to <option> nor listCssClass.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message