awaisalvi / struts2-jquery

Automatically exported from code.google.com/p/struts2-jquery
0 stars 0 forks source link

Incorrect option values in select tag #110

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.

JSON response back from server:

{"JSON":"success","channelMap":{},"countryMap":{"35":"TURKEY","36":"UKRAINE","33
":"ROMANIA","34":"TEST
COUNTRY","39":"UK SAT","37":"COLOMBIA","38":"CHILE","43":"MEXICO
CABLE","42":"ARGENTINA CABLE","41":"POLAND CABLE","40":"SPAIN
CABLE","22":"CZECH
REPUBLIC","23":"POLAND","24":"MEXICO","25":"BRAZIL","26":"RUSSIA","27":"AFRICA",
"28":"HUNGARY","29":"ARGENTINA","3":"DENMARK","2":"BELGIUM","1":"AUSTRIA","7":"G
REECE","30":"SOUTH
KOREA","6":"GERMANY","5":"FRANCE","32":"ALBANIA","4":"FINLAND","31":"SOUTH
AFRICA","9":"NETHERLANDS","8":"ITALY","19":"HONG
KONG","17":"AUSTRALIA","18":"JAPAN","15":"SWITZERLAND","16":"UK","13":"SPAIN","1
4":"SWEDEN","11":"PORTUGAL","12":"REPUBLIC
OF IRELAND","21":"CANADA","20":"NEW ZEALAND","49":"CANADA N","48":"CANADA
B","45":"COLOMBIA CABLE","44":"BRAZIL CABLE","47":"VENEZUELA","46":"CHILE
CABLE","10":"NORWAY","50":"CANADA TORONTO"}}

2.

    <s:url id="remoteurl" action="countrySelect" namespace="ui" />
    <sj:select href="%{remoteurl}" 
               name="country" 
               id="country" 
               onChangeTopics="reloadsecondlist" 
               list="countryMap"
               emptyOption="true" 
               headerKey="-1" 
               headerValue="Select a country" />

3.

Generates following select tag:

<option value="-1">Select a country</option><option></option><option
value="35">TURKEY</option><option value="AUSTRIA">AUSTRIA</option><option
value="BELGIUM">BELGIUM</option><option
value="DENMARK">DENMARK</option><option
value="FINLAND">FINLAND</option><option
value="FRANCE">FRANCE</option><option
value="GERMANY">GERMANY</option><option
value="GREECE">GREECE</option><option value="ITALY">ITALY</option><option
value="NETHERLANDS">NETHERLANDS</option><option
value="NORWAY">NORWAY</option><option
value="PORTUGAL">PORTUGAL</option><option value="REPUBLIC OF
IRELAND">REPUBLIC OF IRELAND</option><option
value="SPAIN">SPAIN</option><option value="SWEDEN">SWEDEN</option><option
value="SWITZERLAND">SWITZERLAND</option><option
value="UK">UK</option><option value="AUSTRALIA">AUSTRALIA</option><option
value="JAPAN">JAPAN</option><option value="HONG KONG">HONG
KONG</option><option value="NEW ZEALAND">NEW ZEALAND</option><option
value="CANADA">CANADA</option><option value="CZECH REPUBLIC">CZECH
REPUBLIC</option><option value="POLAND">POLAND</option><option
value="MEXICO">MEXICO</option><option value="BRAZIL">BRAZIL</option><option
value="RUSSIA">RUSSIA</option><option value="AFRICA">AFRICA</option><option
value="HUNGARY">HUNGARY</option><option
value="ARGENTINA">ARGENTINA</option><option value="SOUTH KOREA">SOUTH
KOREA</option><option value="SOUTH AFRICA">SOUTH AFRICA</option><option
value="ALBANIA">ALBANIA</option><option
value="ROMANIA">ROMANIA</option><option value="TEST COUNTRY">TEST
COUNTRY</option><option value="TURKEY">TURKEY</option><option
value="UKRAINE">UKRAINE</option><option
value="COLOMBIA">COLOMBIA</option><option
value="CHILE">CHILE</option><option value="UK SAT">UK SAT</option><option
value="SPAIN CABLE">SPAIN CABLE</option><option value="POLAND CABLE">POLAND
CABLE</option><option value="ARGENTINA CABLE">ARGENTINA
CABLE</option><option value="MEXICO CABLE">MEXICO CABLE</option><option
value="BRAZIL CABLE">BRAZIL CABLE</option><option value="COLOMBIA
CABLE">COLOMBIA CABLE</option><option value="CHILE CABLE">CHILE
CABLE</option><option value="VENEZUELA">VENEZUELA</option><option
value="CANADA B">CANADA B</option><option value="CANADA N">CANADA
N</option></select>

What is the expected output? What do you see instead?

Turkey is the only element with correct option value. It works fine when I
send ids as a string - e.g. 

{"JSON":"success","channelMap":{},"countryMap":{"i35":"TURKEY","i36":"UKRAINE","
i33":"ROMANIA","i34":"TEST
COUNTRY"}}

Which struts2 version?
Which struts2-jquery plugin version?

POM:

<dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>2.1.8.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-convention-plugin</artifactId>
            <version>2.1.8.1</version>
        </dependency>
        <dependency>
            <groupId>com.jgeppert.struts2.jquery</groupId>
            <artifactId>struts2-jquery-plugin</artifactId>
            <version>1.8.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-spring-plugin</artifactId>
            <version>2.1.8.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-json-plugin</artifactId>
            <version>2.1.8.1</version>
        </dependency>

Please provide any additional information below.

Original issue reported on code.google.com by mryan...@gmail.com on 12 Mar 2010 at 12:51

GoogleCodeExporter commented 9 years ago

Original comment by johgep on 12 Mar 2010 at 4:28

GoogleCodeExporter commented 9 years ago
I just try it out, but can't reproduced this problems.

I add following code to the JsonSample Class in the Showcase

    private Map<Integer, String>    countryMap;
    public String execute() {
        countryMap = new HashMap<Integer, String>();

        countryMap.put(35, "TURKEY");
        countryMap.put(36, "UKRAINE");
        countryMap.put(33, "ROMANIA");
        countryMap.put(34, "TEST COUNTRY");
        countryMap.put(39, "UK SAT");
        countryMap.put(37, "COLOMBIA");
        countryMap.put(38, "CHILE");

        return SUCCESS;
    }

    public String getJSON() {
        return execute();
    }
    public Map<Integer, String> getCountryMap() {
        return countryMap;
    }

and this jsp code:

                <s:url id="remoteurl" action="jsonsample"/> 
                <sj:select 
                    href="%{remoteurl}" 
                    id="echo0" 
                    name="echo" 
                    list="countryMap" 
                    emptyOption="true" 
                    headerKey="-1" 
                    headerValue="Please Select a Country"
                />

do you have this problem only in a special browser?

Original comment by johgep on 15 Mar 2010 at 6:53

GoogleCodeExporter commented 9 years ago
did it work with version 2.0.0?

Original comment by johgep on 9 Apr 2010 at 9:29

GoogleCodeExporter commented 9 years ago
No - problem still occurs - exactly as described.

I am working around this problem by using Map<String, String> and prefixing int 
with
i. Not ideal but fine.

Did you receive my email with simpler Action class to reproduce error? (I have
attached to this comment anyway....)

Action class:

  import com.opensymphony.xwork2.ActionSupport;
  import java.util.HashMap;
  import java.util.Map;

  public class CountrySelect extends ActionSupport {

    private Map<Integer, String> countryMap;

    @Override
    public String execute() {
        countryMap = new HashMap<Integer, String>();
        int count = 1;
        do {
            countryMap.put(count++, "hey");
        } while(count!=5);
        return SUCCESS;
    }

    public String getJSON() {
        return execute();
    }

    public Map<Integer, String> getCountryMap() {
        return countryMap;
    }
  }

Produces:

  <select name="country" id="country">
  <option value="-1">Select a country</option><option></option><option
value="1">hey</option><option value="hey">hey</option><option
value="hey">hey</option><option value="hey">hey</option></select>

Original comment by mryan...@gmail.com on 13 Apr 2010 at 2:29

GoogleCodeExporter commented 9 years ago
Just to reconfirm this problem still occurs. Tested again after browser issues 
with
version update. Reference ticket #136

Original comment by mryan...@gmail.com on 14 Apr 2010 at 10:13

GoogleCodeExporter commented 9 years ago

Original comment by johgep on 2 Jun 2010 at 2:58

GoogleCodeExporter commented 9 years ago
I have the same sort of thing happening that really seems identical to this 
whole problem.  My list only contains a few items; however, as you can see from 
the example below, the first 3 options are invalid.  The values should be 
numeric values and not their textual counterpart:

<span id="wwctrl_facilityType" class="wwctrl">
<select name="facilityType" id="facilityType">
  <option value="Unknown">
Unknown
  </option>
  <option value="DOC">
DOC
  </option>
  <option value="Jails">
Jails
  </option>
  <option value="-100">
DOC and Jails
  </option>
  <option value="6">
Courts
  </option>
  <option value="24">
Probation & Parole
  </option>
</select>
</span>

Original comment by dustf...@gmail.com on 28 Jun 2010 at 4:26

GoogleCodeExporter commented 9 years ago
@dustfrog

can you give me please some code examples?
Which version of this plugin do you use?

Original comment by johgep on 6 Jul 2010 at 2:42

GoogleCodeExporter commented 9 years ago
Sure, no problem.  This is the code from my Facility.tag file:

<%@ include file="/WEB-INF/includes/taglibs.jsp" %>

<s:set name="key" value="getText('report.facility.type')" />

<span class="topLabel">
<s:url id="facility_url" action="ajaxFacilityListing" 
namespace="/actions"></s:url>
<sj:select href="%{facility_url}"
           name="facilityType"
           label="%{key}"
           labelposition="left"
           list="facilities"
           value="-100"
           onAlwaysTopics="updateAgencyList"
           onChangeTopics="updateAgencyList"
           />
</span>

The list="facilities" is calling a getFacilities() method from the action which 
returns Map<Integer, String>.  I used HttpFox to verify the JSON content being 
returned, and the data was correct; however, it just was not being displayed 
correctly through sj:select.

I was using 2.1.0, but I found this problem to still exist in 2.2.2.

Hope this helps.

Original comment by dustf...@gmail.com on 8 Jul 2010 at 3:59

GoogleCodeExporter commented 9 years ago
I was able to reproduce this error. It was a wrong detection if value list is a 
map.
This is fixed with next version.

http://code.google.com/p/struts2-jquery/source/detail?r=1125

Original comment by johgep on 13 Jul 2010 at 7:35

GoogleCodeExporter commented 9 years ago
Great!  Thanks for looking into the problem.

Original comment by dustf...@gmail.com on 14 Jul 2010 at 6:24

GoogleCodeExporter commented 9 years ago

Original comment by johgep on 25 Jul 2010 at 6:53