From issues-return-31955-apmail-struts-issues-archive=struts.apache.org@struts.apache.org Fri Mar 16 13:14:11 2018 Return-Path: X-Original-To: apmail-struts-issues-archive@minotaur.apache.org Delivered-To: apmail-struts-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 35B6818517 for ; Fri, 16 Mar 2018 13:14:11 +0000 (UTC) Received: (qmail 30485 invoked by uid 500); 16 Mar 2018 13:14:06 -0000 Delivered-To: apmail-struts-issues-archive@struts.apache.org Received: (qmail 30453 invoked by uid 500); 16 Mar 2018 13:14:06 -0000 Mailing-List: contact issues-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list issues@struts.apache.org Received: (qmail 30443 invoked by uid 99); 16 Mar 2018 13:14:06 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Mar 2018 13:14:06 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 97D531A023B for ; Fri, 16 Mar 2018 13:14:05 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -101.511 X-Spam-Level: X-Spam-Status: No, score=-101.511 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id LPFjmd5CdyPw for ; Fri, 16 Mar 2018 13:14:03 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 2C95C5F576 for ; Fri, 16 Mar 2018 13:14:02 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 1D766E02C9 for ; Fri, 16 Mar 2018 13:14:01 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 7FDAF2127F for ; Fri, 16 Mar 2018 13:14:00 +0000 (UTC) Date: Fri, 16 Mar 2018 13:14:00 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@struts.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (WW-4910) Align OptGroup with Select MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/WW-4910?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16401854#comment-16401854 ] ASF GitHub Bot commented on WW-4910: ------------------------------------ lukaszlenart closed pull request #204: WW-4910 Align OptGroup with Select URL: https://github.com/apache/struts/pull/204 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/ListUIBean.java b/core/src/main/java/org/apache/struts2/components/ListUIBean.java index 6e24e822e..ed5094198 100644 --- a/core/src/main/java/org/apache/struts2/components/ListUIBean.java +++ b/core/src/main/java/org/apache/struts2/components/ListUIBean.java @@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletResponse; import java.lang.reflect.Array; import java.util.Collection; +import java.util.Collections; import java.util.Map; /** @@ -70,28 +71,28 @@ public void evaluateExtraParams() { if (list instanceof String) { value = findValue((String) list); - } else if (list instanceof Collection) { - value = list; - } else if (MakeIterator.isIterable(list)) { - value = MakeIterator.convert(list); - } - if (value == null) { - if (throwExceptionOnNullValueAttribute) { - // will throw an exception if not found - value = findValue((list == null) ? (String) list : list.toString(), "list", - "The requested list key '" + list + "' could not be resolved as a collection/array/map/enumeration/iterator type. " + - "Example: people or people.{name}"); - } else { - // ww-1010, allows value with null value to be compatible with ww - // 2.1.7 behaviour - value = findValue((list == null) ? (String) list : list.toString()); + if (value == null) { + if (throwExceptionOnNullValueAttribute) { + // will throw an exception if not found + value = findValue((list == null) ? (String) list : list.toString(), "list", + "The requested list key '" + list + "' could not be resolved as a collection/array/map/enumeration/iterator type. " + + "Example: people or people.{name}"); + } else { + // ww-1010, allows value with null value to be compatible with ww + // 2.1.7 behaviour + value = findValue((list == null) ? (String) list : list.toString()); + } } + } else { + value = list; } - if (value instanceof Collection) { + if (value == null || value instanceof Iterable) { addParameter("list", value); - } else { + } else if (MakeIterator.isIterable(value)) { addParameter("list", MakeIterator.convert(value)); + } else { + addParameter("list", Collections.singletonList(value)); } if (value instanceof Collection) { @@ -107,6 +108,8 @@ public void evaluateExtraParams() { addParameter("listKey", listKey); } else if (value instanceof Map) { addParameter("listKey", "key"); + } else { + addParameter("listKey", "top"); } if (listValueKey != null) { @@ -119,6 +122,8 @@ public void evaluateExtraParams() { addParameter("listValue", listValue); } else if (value instanceof Map) { addParameter("listValue", "value"); + } else { + addParameter("listValue", "top"); } if (listLabelKey != null) { 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 58d0b9a72..95d94d26e 100644 --- a/core/src/main/java/org/apache/struts2/components/OptGroup.java +++ b/core/src/main/java/org/apache/struts2/components/OptGroup.java @@ -127,7 +127,7 @@ public void setDisabled(String disabled) { } @StrutsTagAttribute(description="Set the list attribute.") - public void setList(String list) { + public void setList(Object list) { internalUiBean.setList(list); } diff --git a/core/src/main/resources/template/simple/optgroup.ftl b/core/src/main/resources/template/simple/optgroup.ftl index f1f8a3e9e..765591cca 100644 --- a/core/src/main/resources/template/simple/optgroup.ftl +++ b/core/src/main/resources/template/simple/optgroup.ftl @@ -21,27 +21,26 @@ <#if parameters.optGroupInternalListUiBeanList??> <#assign optGroupInternalListUiBeans=parameters.optGroupInternalListUiBeanList /> <#list optGroupInternalListUiBeans as optGroupInternalListUiBean> - <#if optGroupInternalListUiBean.parameters.label?has_content> - label="${optGroupInternalListUiBean.parameters.label}" + label="${optGroupInternalListUiBean.parameters.label}"<#rt> <#if optGroupInternalListUiBean.parameters.disabled!false> - disabled="disabled" + disabled="disabled"<#rt> <#include "/${parameters.templateDir}/${parameters.expandTheme}/dynamic-attributes.ftl" /> > - <#list optGroupInternalListUiBean.parameters.list as optGroupBean> <#assign trash=stack.push(optGroupBean) /> <#assign tmpKey=stack.findValue(optGroupInternalListUiBean.parameters.listKey) /> <#assign tmpValue=stack.findValue(optGroupInternalListUiBean.parameters.listValue) /> <#assign tmpKeyStr = tmpKey.toString() /> - + >${tmpValue?html}<#t> + <#lt> <#assign trash=stack.pop() /> diff --git a/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerResultMockedTest.java b/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerResultMockedTest.java index 1067ddd16..d82a6606e 100644 --- a/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerResultMockedTest.java +++ b/core/src/test/java/org/apache/struts2/views/freemarker/FreemarkerResultMockedTest.java @@ -194,6 +194,55 @@ public void testDynamicAttributesInTheme() throws Exception { assertEquals(expected, stringWriter.toString()); } + public void testSequenceForSelect() throws Exception { + File file = new File(FreeMarkerResultTest.class.getResource("select.ftl").toURI()); + EasyMock.expect(servletContext.getRealPath("/tutorial/org/apache/struts2/views/freemarker/select.ftl")).andReturn(file.getAbsolutePath()); + + file = new File(ClassLoaderUtil.getResource("template/simple/select.ftl", getClass()).toURI()); + EasyMock.expect(servletContext.getRealPath("/template/simple/select.ftl")).andReturn(file.getAbsolutePath()); + EasyMock.expect(servletContext.getRealPath("/template/~~~simple/select.ftl")).andReturn(file.getAbsolutePath()); + + file = new File(ClassLoaderUtil.getResource("template/simple/optgroup.ftl", getClass()).toURI()); + EasyMock.expect(servletContext.getRealPath("/template/simple/optgroup.ftl")).andReturn(file.getAbsolutePath()); + EasyMock.expect(servletContext.getRealPath("/template/~~~simple/optgroup.ftl")).andReturn(file.getAbsolutePath()); + + file = new File(ClassLoaderUtil.getResource("template/simple/css.ftl", getClass()).toURI()); + EasyMock.expect(servletContext.getRealPath("/template/simple/css.ftl")).andReturn(file.getAbsolutePath()); + EasyMock.expect(servletContext.getRealPath("/template/~~~simple/css.ftl")).andReturn(file.getAbsolutePath()); + + file = new File(ClassLoaderUtil.getResource("template/simple/scripting-events.ftl", getClass()).toURI()); + EasyMock.expect(servletContext.getRealPath("/template/simple/scripting-events.ftl")).andReturn(file.getAbsolutePath()); + EasyMock.expect(servletContext.getRealPath("/template/~~~simple/scripting-events.ftl")).andReturn(file.getAbsolutePath()); + + file = new File(ClassLoaderUtil.getResource("template/simple/common-attributes.ftl", getClass()).toURI()); + EasyMock.expect(servletContext.getRealPath("/template/simple/common-attributes.ftl")).andReturn(file.getAbsolutePath()); + EasyMock.expect(servletContext.getRealPath("/template/~~~simple/common-attributes.ftl")).andReturn(file.getAbsolutePath()); + + file = new File(ClassLoaderUtil.getResource("template/simple/dynamic-attributes.ftl", getClass()).toURI()); + EasyMock.expect(servletContext.getRealPath("/template/simple/dynamic-attributes.ftl")).andReturn(file.getAbsolutePath()); + EasyMock.expect(servletContext.getRealPath("/template/~~~simple/dynamic-attributes.ftl")).andReturn(file.getAbsolutePath()); + + file = new File(ClassLoaderUtil.getResource("template/simple/empty.ftl", getClass()).toURI()); + EasyMock.expect(servletContext.getRealPath("/template/simple/empty.ftl")).andReturn(file.getAbsolutePath()); + EasyMock.expect(servletContext.getRealPath("/template/~~~simple/empty.ftl")).andReturn(file.getAbsolutePath()); + EasyMock.expect(servletContext.getRealPath("/template/xhtml/empty.ftl")).andReturn(file.getAbsolutePath()); + + EasyMock.replay(servletContext); + + init(); + + request.setRequestURI("/tutorial/test9.action"); + ActionMapping mapping = container.getInstance(ActionMapper.class).getMapping(request, configurationManager); + dispatcher.serviceAction(request, response, mapping); + String result = stringWriter.toString(); + assertTrue(result.contains("")); + assertTrue(result.contains("")); + assertTrue(result.contains("")); + assertTrue(result.contains("")); + assertTrue(result.contains("")); + assertTrue(result.contains("")); + } + private void init() throws MalformedURLException, URISyntaxException { stringWriter = new StringWriter(); writer = new PrintWriter(stringWriter); diff --git a/core/src/test/resources/org/apache/struts2/views/freemarker/select.ftl b/core/src/test/resources/org/apache/struts2/views/freemarker/select.ftl new file mode 100644 index 000000000..91b84db2f --- /dev/null +++ b/core/src/test/resources/org/apache/struts2/views/freemarker/select.ftl @@ -0,0 +1,28 @@ +<#-- +/* + * 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. + */ +--> +<@s.select theme="simple" list=['a','b','c'] /> +<@s.select theme="simple" list=1 /> +<@s.select theme="simple" list={'key':'value'} /> +<@s.select theme="simple"> +<@s.optgroup label="label1" list={'optgroupKey1':'optgroupValue1','optgroupKey2':'optgroupValue2'} /> +<@s.optgroup label="label2" disabled=true list=['optgroupKey3','optgroupKey4'] /> +<@s.optgroup label="label3" disabled=true list=2 /> + \ No newline at end of file diff --git a/core/src/test/resources/struts.xml b/core/src/test/resources/struts.xml index 5b29c1e87..0b370aa3e 100644 --- a/core/src/test/resources/struts.xml +++ b/core/src/test/resources/struts.xml @@ -80,6 +80,12 @@ + + + org/apache/struts2/views/freemarker/select.ftl + + + ---------------------------------------------------------------- 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 > Align OptGroup with Select > -------------------------- > > Key: WW-4910 > URL: https://issues.apache.org/jira/browse/WW-4910 > Project: Struts 2 > Issue Type: Improvement > Components: Core > Reporter: Yanming Zhou > Priority: Major > Fix For: 2.6 > > > 1. allow set freemarker sequence or hash as list > 2. if list is a List, use 'top' as listKey and listValue -- This message was sent by Atlassian JIRA (v7.6.3#76005)