1

以下のような jsp ページがあります (ConfigureRate.jsp):

<s:form action="modifyrate.action" method="post">
                    <s:textfield label="Country" name="selectedCountry" value="%{#session.selectedCallRates.country}" size="20" disabled="true" />
                    <s:textfield label="Country Code" name="countrycode" value="%{#session.selectedCallRates.countrycode}" size="20" disabled="true"/>
                    <s:textfield label="Call Direction" name="selectedCallType" value="%{#session.selectedCallRates.callType}" disabled="true"/>
                    <s:textfield label="Device Type" name="selectedDeviceType" value="%{#session.selectedCallRates.deviceType}" disabled="true"/>
                    <s:textfield name="rate" key="label.rate" size="20" />
                    <s:submit method="modifyRate" key="Update" align="center" />
                </s:form>

また、selectedCallType、selectedDeviceType などのアクション クラスにセッターとゲッターを用意します。

アクションコード:

public class ConfigureRatesAction extends ActionSupport {

private List<CallRates> callRates;
private String selectedCountryRow;
private String selectedCallType;
private String selectedDeviceType;
private String country;
private int countrycode;
private double rate;
private String selectedCountry;
private static final Logger log = Logger.getLogger(ConfigureRatesAction.class);

public String displayModify() {

    Boolean loggedin = (Boolean) ActionContext.getContext().getSession().get("loggedin");
    CallRatesDAO callRatesDAO = new CallRatesDAO();

    if (loggedin == null || !loggedin) {
        addActionError(getText("error.loggedin"));
        return "loggedout";
    }

    if (selectedCountryRow == null) {
        callRates =
                callRatesDAO.getCallRates();
        addActionError("Select a row to modify");
        return ERROR;
    }

    CallRates selectedCallRates = buildCallRates(selectedCountryRow);

    if (selectedCallRates == null) {
        callRates = callRatesDAO.getCallRates();
        addActionError("Select a row to modify");
        return ERROR;
    } else {
        ActionContext.getContext().getSession().put("selectedCallRates", selectedCallRates);
        return SUCCESS;
    }

}

public String modifyRate() {



    Boolean loggedin = (Boolean) ActionContext.getContext().getSession().get("loggedin");

    if (loggedin == null || !loggedin) {
        addActionError(getText("error.loggedin"));
        return "loggedout";
    }

    CallRatesDAO callRatesDAO = new CallRatesDAO();

    log.info("Values :"+selectedCountry+" "+countrycode+" "+selectedCallType
            +" "+selectedDeviceType+" "+rate);


    if (callRatesDAO.updateRate(selectedCountry, rate, Integer.toString(countrycode),
            selectedCallType, selectedDeviceType)) {
        callRates = callRatesDAO.getCallRates();
        addActionMessage(getText("success.modifyrate"));
        return SUCCESS;
    } else {
        addActionError(getText("errors.modifyrate"));
        return ERROR;
    }
}

private CallRates buildCallRates(String selectedCountryRow) {

    StringTokenizer token = new StringTokenizer(selectedCountryRow, "*");
    CallRates cR = new CallRates();
    int i = 1;

    while (token.hasMoreTokens()) {
        if (i == 1) {
            cR.setCountry(token.nextToken());
        } else if (i == 2) {
            cR.setCountrycode(Integer.parseInt(token.nextToken()));
        } else if (i == 3) {
            cR.setCallType(token.nextToken());
        } else if (i == 4) {
            cR.setDeviceType(token.nextToken());
        }
        i++;
    }

    return cR;
}

public List<CallRates> getCallRates() {
    return callRates;
}

public void setCallRates(List<CallRates> callRates) {
    this.callRates = callRates;
}

public String getCountry() {
    return country;
}

public void setCountry(String country) {
    this.country = country;
}

public int getCountrycode() {
    return countrycode;
}

public void setCountrycode(int countrycode) {
    this.countrycode = countrycode;
}

public double getRate() {
    return rate;
}

public void setRate(double rate) {
    this.rate = rate;
}

public String getSelectedCallType() {
    return selectedCallType;
}

public void setSelectedCallType(String selectedCallType) {
    this.selectedCallType = selectedCallType;
}

public String getSelectedCountry() {
    return selectedCountry;
}

public void setSelectedCountry(String selectedCountry) {
    this.selectedCountry = selectedCountry;
}

public String getSelectedCountryRow() {
    return selectedCountryRow;
}

public void setSelectedCountryRow(String selectedCountryRow) {
    this.selectedCountryRow = selectedCountryRow;
}

public String getSelectedDeviceType() {
    return selectedDeviceType;
}

public void setSelectedDeviceType(String selectedDeviceType) {
    this.selectedDeviceType = selectedDeviceType;
}

}

struts.xml :

  <action name="modifyAction"
            class="com.thrupoint.brg.callrates.configurerates.ConfigureRatesAction" method="displayModify">
        <result name="success">jsp/ConfigureRate.jsp</result>
        <result name="error">jsp/modifyrates.jsp</result>
        <result name="loggedout">jsp/Login.jsp</result>
    </action>
    <action name="modifyrate"
            class="com.thrupoint.brg.callrates.configurerates.ConfigureRatesAction" method="modifyRate">
        <result name="success">jsp/modifyrates.jsp</result>
        <result name="input">jsp/ConfigureRate.jsp</result>
        <result name="error">jsp/ConfigureRate.jsp</result>
        <result name="loggedout">jsp/Login.jsp</result>
    </action>

アクション クラスでこれらのプロパティの値を出力すると、上記の jsp 形式で value 属性を持たない rate プロパティを除いて、null が返されます。

他のプロパティが null であるのはなぜですか?

4

1 に答える 1