form: тег option указывает на ошибку: свойство Bean недоступно для чтения или имеет недопустимый метод получения - PullRequest
1 голос
/ 09 июля 2010

Я хочу использовать форму: параметры, предоставляемые Spring для предоставления выбора.

My JSP implemented with Spring 2.5 is 
      <td><form:select path="billingType">
         <form:options items="${addAccountCommand.billingTypeChoice}" itemValue="billingType" itemLabel="billingTypeName" />  
      </form:select>
      </td>

Мой AccountCommand.java

private int billingType;
private String billingTypeName;

public int getBillingType() {
    return billingType;
}

public void setBillingType(int billingType) {
    this.billingType = billingType;
}

private Map<String, Integer> billingTypeChoice = new HashMap<String, Integer>() { 
    {
        put("Monthly", 1);
        put("Block", 2);
        put("Per Use", 3);
    }
};  

public Map<String, Integer> getbillingTypeChoice() {
    return billingTypeChoice;
}

public void setbillingTypeChoice(Map<String, Integer> billingTypeChoice) {
    this.billingTypeChoice = billingTypeChoice;
}

public String getBillingTypeName() {
    return billingTypeName;
}

public void setBillingTypeName(String billingTypeName) {
    this.billingTypeName = billingTypeName;
}

Моя консоль Eclipse:

15:55:23,140 ERROR org.springframework.web.servlet.tags.form.OptionsTag:84 - Invalid property 'billingType' of bean class [java.lang.String]: Bean property 'billingType' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
org.springframework.beans.NotReadablePropertyException: Invalid property 'billingType' of bean class [java.lang.String]: Bean property 'billingType' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
    at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:540)
    at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:532)
    at org.springframework.web.servlet.tags.form.OptionWriter.renderFromMap(OptionWriter.java:164)
...

Ответы [ 2 ]

3 голосов
/ 09 июля 2010

Когда вы делаете:

<form:options items="${addAccountCommand.billingTypeChoice}" itemValue="billingType" itemLabel="billingTypeName" />

Вы говорите, перейдите к addAccountCommand.billingTypeChoice, который является Map, и выполните getBillingType () для значения и getBillingTypeName () для метки. Поскольку эти методы не определены на карте, вы получите ошибку. Вы должны использовать getKey () и getValue () на карте. Как вы уже определили, теперь это должно быть:

<form:options items="${addAccountCommand.billingTypeChoice}" itemValue="key" itemLabel="value" />

потому что вы определили карту очень странным образом. Обычно это Map, потому что я предполагаю, что ключ - это Integer, а значение String.

Надеюсь, это поможет.

0 голосов
/ 10 февраля 2011

Я только что попробовал это на весне 2.5. Просто код ниже должен работать.

<form:select path="billingType"> <form:options items="${addAccountCommand.billingTypeChoice}" /><br> </form:select>

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...