I am creating a simple page with Strut2 + jquery + spring + hibernate with oracle DB. Database table is having two columns and those are primary keys. When I am trying to map its corresponding JSON data with struts2 select component, it is showing "undefined" options in the drop down. Some other select component with simple json data(no primary key in DB tables)is working smoothly. Please help to rectify this case.
Here is my Code for Struts.xml, class is injected using spring DI
<action name="selectCountries" class="individualUserRegAction" method="selectAllCountries">
<result name="input">pages/personalInfo.jsp</result>
<result name="success" type="json"></result>
</action>
My Jsp Page
<sj:select cssClass="textField" href="%{countries}"
name="nationality" headerKey="ALL"
headerValue="%{getText('user.acc.info.nationality.plzselect')}"
list="countryList" listKey="id.countryCode"
listValue="id.countryDesc" />
My Action Class
public class IndividualUserRegAction extends ActionSupport
{
private CountriesBO countriesBO;
private List<Countries> countryList;
private
String firstName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public List<Countries> getCountryList() {
return countryList;
}
public void setCountryList(List<Countries> countryList) {
this.countryList = countryList;
}
public void setCountriesBO(CountriesBO countriesBO) {
this.countriesBO = countriesBO;
}
public String registerUser()throws Exception{
return SUCCESS;
}
public String personalInfo()throws Exception{
try{
return SUCCESS;
}catch(Exception ex){
throw ex;
}
}
public String selectAllCountries()throws Exception{
try{
countryList = countriesBO.getAllCountries();
return SUCCESS;
}catch(Exception ex){
ex.printStackTrace();
throw ex;
}
}
public String residenceInfo()throws Exception{
return SUCCESS;
}
public String execute()throws Exception{
return SUCCESS;
}
}
Action class is accessing data from Countries table using hibernate and its entity structure is as below,
public class Countries implements java.io.Serializable {
// Fields
private CountriesId id;
// Constructors
/** default constructor */
public Countries() {
}
/** full constructor */
public Countries(CountriesId id) {
this.id = id;
}
// Property accessors
public CountriesId getId() {
return this.id;
}
public void setId(CountriesId id) {
this.id = id;
}
}
Composite primary key class structure
public class CountriesId implements java.io.Serializable {
// Fields
private String countryCode;
private String countryDesc;
// Constructors
/** default constructor */
public CountriesId() {
}
/** full constructor */
public CountriesId(String countryCode, String countryDesc) {
this.countryCode = countryCode;
this.countryDesc = countryDesc;
}
// Property accessors
public String getCountryCode() {
return this.countryCode;
}
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
public String getCountryDesc() {
return this.countryDesc;
}
public void setCountryDesc(String countryDesc) {
this.countryDesc = countryDesc;
}
public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof CountriesId))
return false;
CountriesId castOther = (CountriesId) other;
return ((this.getCountryCode() == castOther.getCountryCode()) || (this
.getCountryCode() != null && castOther.getCountryCode() != null && this
.getCountryCode().equals(castOther.getCountryCode())))
&& ((this.getCountryDesc() == castOther.getCountryDesc()) || (this
.getCountryDesc() != null
&& castOther.getCountryDesc() != null && this
.getCountryDesc().equals(castOther.getCountryDesc())));
}
public int hashCode() {
int result = 17;
result = 37
* result
+ (getCountryCode() == null ? 0 : this.getCountryCode()
.hashCode());
result = 37
* result
+ (getCountryDesc() == null ? 0 : this.getCountryDesc()
.hashCode());
return result;
}
}
Json Data received after DB Calls is below
{"countryList":
[
{"id":{"countryCode":"AD","countryDesc":"Andorra"}},
{"id":{"countryCode":"AE","countryDesc":"United Arab Emirates"}},
{"id":{"countryCode":"AF","countryDesc":"Afghanistan"}},
{"id":{"countryCode":"AG","countryDesc":"Antigua and Barbuda"}},
{"id":{"countryCode":"AI","countryDesc":"Anguilla"}},
{"id":{"countryCode":"AL","countryDesc":"Albania"}},
{"id":{"countryCode":"AM","countryDesc":"Armenia"}},
{"id":{"countryCode":"AN","countryDesc":"Netherlands Antilles"}},
{"id":{"countryCode":"AO","countryDesc":"Angola"}},
{"id":{"countryCode":"AQ","countryDesc":"Antarctica"}},
{"id":{"countryCode":"ZW","countryDesc":"Zimbabwe"}}
]
,"firstName":""}
I am totally stuck here, since I want to rectify it ASAP, any help/suggestions will be much appretiated.