Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WW-5129] Supports dynamic attributes in second control #495

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion core/src/main/resources/template/simple/doubleselect.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* under the License.
*/
-->
<#global dynamic_attributes_ignore = "second-"/>
<#include "/${parameters.templateDir}/simple/select.ftl" />
<#assign startCount = 0/>
<#if parameters.headerKey?? && parameters.headerValue??>
Expand Down Expand Up @@ -60,6 +61,8 @@
<#if parameters.doubleDisabled!false>
disabled="disabled"<#rt/>
</#if>
<#include "/${parameters.templateDir}/${parameters.expandTheme}/prefixed-dynamic-attributes.ftl" />
<@prefixedDynamicAttributes prefix="second-"/>
>
</select>
<#if parameters.doubleMultiple!false>
Expand Down Expand Up @@ -190,4 +193,4 @@
${parameters.id}Temp.options[0].selected = true;
}
}
</script>
</script>
24 changes: 18 additions & 6 deletions core/src/main/resources/template/simple/dynamic-attributes.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,24 @@
<#if (parameters.dynamicAttributes?? && parameters.dynamicAttributes?size > 0)><#rt/>
<#assign aKeys = parameters.dynamicAttributes.keySet()><#rt/>
<#list aKeys as aKey><#rt/>
<#assign keyValue = parameters.dynamicAttributes.get(aKey)/>
lukaszlenart marked this conversation as resolved.
Show resolved Hide resolved
<#if keyValue?is_string>
<#assign value = struts.translateVariables(keyValue)!keyValue/>
<#else>
<#assign value = keyValue?string/>
</#if>
<#if dynamic_attributes_ignore??>
<#if !aKey?starts_with(dynamic_attributes_ignore)>
<#assign keyValue = parameters.dynamicAttributes.get(aKey)/>
<#if keyValue?is_string>
<#assign value = struts.translateVariables(keyValue)!keyValue/>
<#else>
<#assign value = keyValue?string/>
</#if>
${aKey}="${value?html}"<#rt/>
</#if>
<#else>
<#assign keyValue = parameters.dynamicAttributes.get(aKey)/>
<#if keyValue?is_string>
<#assign value = struts.translateVariables(keyValue)!keyValue/>
<#else>
<#assign value = keyValue?string/>
</#if>
${aKey}="${value?html}"<#rt/>
</#if>
</#list><#rt/>
</#if><#rt/>
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
<label for="leftTitle">${parameters.leftTitle}</label><br />
</#if><#t/>


<input type="text"<#rt/>
name="${parameters.name!""?html}_input"<#rt/>
<#if parameters.disabled!false>
Expand All @@ -55,6 +54,8 @@
</#if>
<#include "/${parameters.templateDir}/${parameters.expandTheme}/scripting-events.ftl" />
<#include "/${parameters.templateDir}/${parameters.expandTheme}/common-attributes.ftl" />
<#include "/${parameters.templateDir}/${parameters.expandTheme}/prefixed-dynamic-attributes.ftl" />
<@prefixedDynamicAttributes prefix="input-"/>
/>


Expand Down Expand Up @@ -94,9 +95,10 @@
<#if parameters.rightTitle?has_content><#t/>
<label for="rightTitle">${parameters.rightTitle}</label><br />
</#if><#t/>
<#global dynamic_attributes_ignore = "input-"/>
<#include "/${parameters.templateDir}/simple/select.ftl" />
<#if parameters.allowUpDown!true>
<input type="button"
<input type="button"
<#if parameters.headerKey?has_content>
onclick="moveOptionDown(document.getElementById('${parameters.id}'), 'key', '${parameters.headerKey}');"
<#else>
Expand All @@ -106,7 +108,7 @@
value="${parameters.downLabel?html}"
</#if>
/>
<input type="button"
<input type="button"
<#if parameters.headerKey?has_content>
onclick="moveOptionUp(document.getElementById('${parameters.id}'), 'key', '${parameters.headerKey}');"
<#else>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<#if parameters.leftTitle??><#t/>
<label for="leftTitle">${parameters.leftTitle}</label><br />
</#if><#t/>
<#global dynamic_attributes_ignore = "right-"/>
<#include "/${parameters.templateDir}/simple/select.ftl" />
<#if parameters.allowUpDownOnLeft!true>
<input type="button"
Expand Down Expand Up @@ -247,6 +248,8 @@
<#if parameters.doubleAccesskey??><#t/>
accesskey="${parameters.doubleAccesskey?html}"
</#if>
<#include "/${parameters.templateDir}/${parameters.expandTheme}/prefixed-dynamic-attributes.ftl" />
<@prefixedDynamicAttributes prefix="right-"/>
>
<#if parameters.doubleHeaderKey?? && parameters.doubleHeaderValue??><#t/>
<option value="${parameters.doubleHeaderKey?html}">${parameters.doubleHeaderValue?html}</option>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<#--
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
-->
<#macro prefixedDynamicAttributes prefix>
<#if (parameters.dynamicAttributes?? && parameters.dynamicAttributes?size > 0)><#rt/>
<#assign aKeys = parameters.dynamicAttributes.keySet()><#rt/>
<#list aKeys as aKey><#rt/>
<#if aKey?starts_with(prefix)>
<#assign keyValue = parameters.dynamicAttributes.get(aKey)/>
<#if keyValue?is_string>
<#assign value = struts.translateVariables(keyValue)!keyValue/>
<#else>
<#assign value = keyValue?string/>
</#if>
${aKey}="${value}"<#rt/>
lukaszlenart marked this conversation as resolved.
Show resolved Hide resolved
</#if>
</#list><#rt/>
</#if><#rt/>
</#macro>
4 changes: 2 additions & 2 deletions core/src/main/resources/template/simple/select.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<#assign itemKeyStr = stack.findString('top')>
</#if>
<#if parameters.listValueKey??>
<#-- checks the valueStack for the 'valueKey.' The valueKey is then looked-up in the locale file for it's
<#-- checks the valueStack for the 'valueKey.' The valueKey is then looked-up in the locale file for it's
localized value. This is then used as a label -->
<#assign valueKey = stack.findString(parameters.listValueKey)!'' />
<#if valueKey?has_content>
Expand Down Expand Up @@ -139,7 +139,7 @@
<#if ( !parameters.id?? && !parameters.name??)>
<input type="hidden" id="" name="" value="" <#rt/>
</#if>

<#if parameters.disabled!false>
disabled="disabled"<#rt/>
</#if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ public void testDouble() throws Exception {
tag.setCssStyle("s1");
tag.setDoubleCssClass("c2");
tag.setDoubleCssStyle("s2");

tag.doStartTag();
tag.doEndTag();

verify(SelectTag.class.getResource("DoubleSelect-1.txt"));
}

public void testOnchange() throws Exception {
TestAction testAction = (TestAction) action;

Expand Down Expand Up @@ -151,7 +151,7 @@ public void testOnchange() throws Exception {
tag.setCssStyle("s1");
tag.setDoubleCssClass("c2");
tag.setDoubleCssStyle("s2");

tag.doStartTag();
tag.doEndTag();

Expand Down Expand Up @@ -221,7 +221,7 @@ public void testDoubleWithDefaultSelectedValues() throws Exception {


}

public void testDoubleWithDotName() throws Exception {
TestAction testAction = (TestAction) action;

Expand Down Expand Up @@ -285,6 +285,15 @@ public void testGenericSimple() throws Exception {
verifyGenericProperties(tag, "simple", new String[]{"value"});
}

public void testGenericSimpleWithDynamicAttributes() throws Exception {
DoubleSelectTag tag = new DoubleSelectTag();
tag.setDynamicAttribute(null, "first-name", "firstName");
tag.setDynamicAttribute(null, "second-name", "secondName");
prepareTagGeneric(tag);
verifyGenericProperties(tag, "simple", new String[]{"value"});
verify(SelectTag.class.getResource("DoubleSelect-5.txt"));
}

public void testGenericXhtml() throws Exception {
DoubleSelectTag tag = new DoubleSelectTag();
prepareTagGeneric(tag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,16 @@
*/
package org.apache.struts2.views.jsp.ui;

import org.apache.struts2.views.jsp.AbstractUITagTest;
import org.apache.struts2.TestAction;
import org.apache.struts2.views.jsp.AbstractUITagTest;

import java.util.List;
import java.util.ArrayList;
import java.util.List;

/**
*
*/
public class InputTransferSelectTagTest extends AbstractUITagTest {

public void testWithRequired() throws Exception {
List list = new ArrayList();
List<String> list = new ArrayList<>();
list.add("Item One");
list.add("Item Two");

Expand All @@ -46,7 +43,28 @@ public void testWithRequired() throws Exception {
tag.doStartTag();
tag.doEndTag();

//System.out.println(writer.toString());
verify(InputTransferSelectTagTest.class.getResource("inputtransferselect-1.txt"));
}

public void testDynamicAttributes() throws Exception {
List<String> list = new ArrayList<>();
list.add("Item One");
list.add("Item Two");

TestAction testaction = (TestAction) action;
testaction.setCollection(list);

InputTransferSelectTag tag = new InputTransferSelectTag();
tag.setPageContext(pageContext);
tag.setDynamicAttribute(null, "input-name", "inputName");
tag.setDynamicAttribute(null, "collection-name", "collectionName");

tag.setName("collection");
tag.setList("collection");

tag.doStartTag();
tag.doEndTag();

verify(InputTransferSelectTagTest.class.getResource("inputtransferselect-2.txt"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -523,4 +523,36 @@ public void testDisableSomeButtons() throws Exception {
//System.out.println(writer.toString());
verify(OptionTransferSelectTagTest.class.getResource("optiontransferselect-7.txt"));
}

public void testDynamicAttributes() throws Exception {
List left = new ArrayList();
left.add("Left1");
left.add("Left2");

List right = new ArrayList();
right.add("Right1");
right.add("Right2");

TestAction testaction = (TestAction) action;
testaction.setCollection(left);
testaction.setList2(right);

OptionTransferSelectTag tag = new OptionTransferSelectTag();
tag.setPageContext(pageContext);

tag.setName("collection");
tag.setList("collection");

tag.setDoubleName("list2");
tag.setDoubleList("list2");

tag.setDynamicAttribute(null, "left-name", "leftName");
tag.setDynamicAttribute(null, "right-name", "rightName");

tag.doStartTag();
tag.doEndTag();

//System.out.println(writer.toString());
verify(OptionTransferSelectTagTest.class.getResource("optiontransferselect-8.txt"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<select name="someName" disabled="disabled" tabindex="99" id="someId" class="cssClass1" style="cssStyle1"
title="someTitle" onclick="onclick1" ondblclick="ondblclick1" onmousedown="onmousedown1" onmouseup="onmouseup1"
onmouseover="onmouseover1" onmousemove="onmousemove1" onmouseout="onmouseout1" onfocus="onfocus1" onblur="onblur1"
onkeypress="onkeypress1" onkeydown="onkeydown1" onkeyup="onkeyup1" onselect="onchange"
onchange="someIdRedirect(this.selectedIndex)" first-name="firstName">
<option value="BE">Belgium</option>
<option value="FR" selected="selected">France</option>
</select>
<br />
<select name="region" disabled="disabled" id="region" title="someTitle" second-name="secondName"></select>
<script type="text/javascript">
var someIdGroup = newArray(2 + 0);
for (var i = 0; i < (2 + 0); i++) {
someIdGroup[i] = [];
}
someIdGroup[0][0] = newOption("Antwerp", "AN");
someIdGroup[0][1] = newOption("Gent", "GN");
someIdGroup[0][2] = newOption("Brugge", "BRG");
someIdGroup[1][0] = newOption("Paris", "PA");
someIdGroup[1][1] = newOption("Bordeaux", "BOR");
var someIdTemp = document.inputForm.region;
someIdRedirect(1);
function someIdRedirect(x) {
var selected = false;
for (var m = someIdTemp.options.length - 1; m >= 0; m--) {
someIdTemp.remove(m);
}
for (var i = 0; i < someIdGroup[x].length; i++) {
someIdTemp.options[i] = newOption(someIdGroup[x][i].text, someIdGroup[x][i].value);
if (someIdTemp.options[i].value == 'BOR') {
someIdTemp.options[i].selected = true;
selected = true;
}
}
if ((someIdTemp.options.length > 0) && (!selected)) {
someIdTemp.options[0].selected = true;
}
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<tr>
<td class="tdLabel"></td>
<td class="tdInput">
<script type="text/javascript" src="/struts/inputtransferselect.js"></script>
<table>
<tr>
<td><input type="text" name="collection_input" id="collection_input" input-name="inputName"/></td>
<td class="tdTransferSelect">
<input type="button" value="-&gt;"
onclick="addOption(document.getElementById('collection_input'),document.getElementById('collection'))" />
<br /><br />
<input type="button" value="&lt;-" onclick="removeOptions(document.getElementById('collection'))" />
<br /><br />
<input type="button" value="&lt;&lt;--" onclick="removeAllOptions(document.getElementById('collection'))" />
<br />
<br />
</td>
<td>
<select name="collection" size="5" id="collection" multiple="multiple" collection-name="collectionName">
<option value="ItemOne" selected="selected">ItemOne</option>
<option value="ItemTwo" selected="selected">ItemTwo</option>
</select>
<input type="hidden" id="__multiselect_collection" name="__multiselect_collection" value="" />
<input type="button" onclick="moveOptionDown(document.getElementById('collection'),'key','');" value="v" />
<input type="button" onclick="moveOptionUp(document.getElementById('collection'),'key','');" value="^" />
</td>
</tr>
</table>
</td>
</tr>
Loading