Hi Alex!

Have you solved your problem yet? I was facing the same situation a cuple of weeks ago.

All values from your formbean are sent in the request as parameters when you
press submit - but checkbox values are only in the request if they have the
value on = they are checked. The reset method works like this:  values are first set 
to false by the reset method and then, if they are present i the request they receive 
value true, otherwise the have the value false. 

Is your problem the following: when you come to your second page the values are 
correct but when you submit this page you go to an action class that forwards to the 
first page - is that correct or do you go via two action classes to reach the first 
page from the second page? 

Anyway, since the formbean values are present as parameters in scope request, they are 
not found the last time the reset method is called. First the reset method sets the 
checkbox values to false, after that no parameters are found in the request and thats 
way the final checkbox value is false, even though it was true on your second page.

I solved this problem by checking the formbean's checkbox values in the first action 
class after my second page and when I forwarded to a second action class before my 
first page was shown again I added parameters to the requset manually if the checkbox 
value was on = true. When the reset method was called these parameters were found and 
the formbean was populated in a correct way.

Good luck / Linnéa

By the way:

A while ago someone sent an alternative version of the doStartTag that should solve 
the checkbox problem: new version for doStartTag() method :


    public int doStartTag() throws JspException {
    // Create an appropriate "hidden" element to put it before the "input" element
    // with value false. This will force to uncheck in the ActionForm if the checkbox 
    // is not checked 
    StringBuffer resultsHidden = new StringBuffer("<input type=\"hidden\"");

    // Create an appropriate "input" element based on our parameters
    StringBuffer results = new StringBuffer("<input type=\"checkbox\"");

    resultsHidden.append(" name=\"");
    results.append(" name=\"");

    // Indexed properties handling
    if (indexed != null) {
        IterateTag iterateTag =
            (IterateTag) findAncestorWithClass(this, IterateTag.class);
        if (iterateTag == null) {
            // this tag should only be nested in iteratetag, if it's not, throw 
exception
            JspException e =
                new JspException(messages.getMessage("indexed.noEnclosingIterate"));
            RequestUtils.saveException(pageContext, e);
            throw e;
        }
        if (name != null) {
            results.append(name);
            resultsHidden.append(name);
        }
        results.append("[");
        results.append(iterateTag.getIndex());
        results.append("]");
        resultsHidden.append("[");
        resultsHidden.append(iterateTag.getIndex());
        resultsHidden.append("]");
        if (name != null) {
            results.append(".");
            resultsHidden.append(".");
        }
    }
    // End of Indexed properties handling

    results.append(this.property);
    results.append("\"");
    resultsHidden.append(this.property);
    resultsHidden.append("\" value=\"false\" />");
    if (accesskey != null) {
        results.append(" accesskey=\"");
        results.append(accesskey);
        results.append("\"");
    }
    if (tabindex != null) {
        results.append(" tabindex=\"");
        results.append(tabindex);
        results.append("\"");
    }
    results.append(" value=\"");
    if (value == null)
        results.append("on");
    else
        results.append(value);
    results.append("\"");
    Object result = RequestUtils.lookup(pageContext, name, property, null);
    if (result == null)
        result = "";
    if (!(result instanceof String))
        result = result.toString();
    String checked = (String) result;
    if (checked.equalsIgnoreCase("true")
        || checked.equalsIgnoreCase("yes")
        || checked.equalsIgnoreCase("on"))
        results.append(" checked=\"checked\"");
    results.append(prepareEventHandlers());
    results.append(prepareStyles());
    results.append(">");

    // Print this field to our output writer
    ResponseUtils.write(pageContext, results.toString() + resultsHidden.toString());

    // Continue processing this page
    this.text = null;
    return (EVAL_BODY_TAG);

}




________________________________________ 
Linnéa Ahlbeck - Software Engineer 
phone +46 40 664 29 70 fax +46 40 30 32 62 
mobile +46 708 96 14 56 

Appium AB - Adelgatan 5, SE-211 22 Malmö, Sweden 
www.appium.com 

Reply via email to