> The atributte of key field is a Long. Then this is a bug because in 
> previously versions worked.

Hi Alexandre,

I believe this is a bug in the current Struts2 code. See 
   https://issues.apache.org/struts/browse/WW-1601
   https://issues.apache.org/struts/browse/WW-1634

Basically, the select tag will only pre-select an item if the listKey is a
String. We have been using Integers as keys for our pulldowns (a simple
Integer-->String ArrayList), so we ran into this as well. 

As a workaround, we added two methods to the business model class. These simply
get and set the Integer attribute of the class by converting between String and
Integer.

As a specific example, below is a snippet from our Address class, which
sometimes is used by a County pulldown in a struts2 form. The form element
itself looks like this:

<s:select name="address.countyIdStr" headerKey="" headerValue="-- Select One--"
    list="counties" listKey="id" listValue="name" required="true" />

Cheers,

 - stuart

private Integer id;
private Integer city;
[...more attributes...]
private Integer countyId;

public Integer getId() { return id; }
public void setId(Integer id) {this.id = id; }

public String getCity() { return city; ]
public void setCity(String city) { this.city = city; }

[... more getters and setters ...]

public Integer getCountyId() { return countyId; }
public void setCountyId(Integer countyId) { this.countyId = countyId; }

/* Helper methods for dealing with preselecting pulldowns in struts2
 * See https://issues.apache.org/struts/browse/WW-1601
 */

public getCountyIdStr() {
   return countyId == null ? null : countyId.toString();
}

public void setCountyIdStr(String countyIdStr) {
   if (NumberUtils.isDigits(countyIdStr)) {
      countyId = new Integer(countyIdStr);
   }
}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to