开发者

map action with select tag in struts 2

  <s:select name="country" list="countryList" listKey="countryId" 
     listValue="countryName" headerKey="0" headerValue="Country"
     label="Select a country" />

country.java

    package vaannila;

    public class Country {

      private int countryId;

      private String countryName;

      Country(int countryId, String countryName) {
        this.countryId = countryId;
        this.countryName = countryNa开发者_如何学运维me;
      }

      public int getCountryId() {
        return countryId;
      }

      public void setCountryId(int countryId) {
        this.countryId = countryId;
      }

      public String getCountryName() {
        return countryName;
      }

      public void setCountryName(String countryName) {
        this.countryName = countryName;
      }
}

HelloWorld.java

public class HelloWorld {

private String message;

private String userName;
private String gender;
private boolean language;
private ArrayList<Country> countryList;

public HelloWorld(){
countryList = new ArrayList<Country>();
    countryList.add(new Country(1, "India"));
    countryList.add(new Country(2, "USA"));
    countryList.add(new Country(3, "France"));

}   

public boolean isLanguage() {
    return language;
}

public void setLanguage(boolean language) {
    this.language = language;
}

public String getGender() {
    return gender;
}

public void setGender(String gender) {
    this.gender = gender;
}

public ArrayList<Country> getCountryList() {
    return countryList;
}

public void setCountryList(ArrayList<Country> countryList) {
    this.countryList = countryList;
}

public String execute()  {
    setMessage("Hello " + getUserName());
    return "SUCCESS";
}

public String getMessage() {
    return message;
}

public void setMessage(String message) {
    this.message = message;
}

public String getUserName() {
    return userName;
}

public void setUserName(String userName) {
    this.userName = userName;
}
}

struts.xml

<struts>
  <!-- Configuration for the default package. -->
  <package name="default"  extends="struts-default">
     <action name="HelloWorld" class="vaannila.HelloWorld">
        <result name="SUCCESS">/success.jsp</result>
     </action>
  </package>
</struts>

Http status 500

org.apache.jasper.JasperException: tag 'select', field 'list', name 'country': The requested list key 'countryList' could not be resolved as a collection/array

this is the error comming. can anyone help me


You are missing country instance variable and appropriate getter/setters in your HelloWorld action class...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜