DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23467>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23467

Indexed check-box HTML tags fail because attempts are made to find the check-box beans 
without their indices.

           Summary: Indexed check-box HTML tags fail because attempts are
                    made to find the check-box beans without their indices.
           Product: Struts
           Version: 1.1RC2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Major
          Priority: Other
         Component: Custom Tags
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


Hi.

I have been unable to use an indexed collection of check-box HTML tags without 
making a small change to the source code of 
org.apache.struts.taglib.html.CheckboxTag.

Here is an excerpt from my HTML:
  <logic:iterate
    id="serviceRequestStatus"
    name="serviceRequestStatusMaintenanceForm"
    property="allExistingServiceRequestStatusParameterContainers"
    
type="aquatron.ejb.serviceRequestStatus.ServiceRequestStatusParameterContainer"
    scope="session"
  >
    <tr>
      <td>
        <html:checkbox name="serviceRequestStatusMaintenanceForm" 
property="canFollowServiceRequestsInWhichStatuses" indexed="true"/>
      </td>
      <td>
        <bean:write name="serviceRequestStatus" property="description"/>
      </td>
    </tr>
  </logic:iterate>

And here are some pertinent excerpts from my Struts configuration:

  <form-beans>
     <form-bean
        name="serviceRequestStatusMaintenanceForm"
        type="aquatron.struts.StrutsFormServiceRequestStatusMaintenance"
     >
     </form-bean>
  </form-beans>
...
And among the action mappings:
    <action
        path="/serviceRequestStatusCreation"
        input="/JSPs/ServiceRequestStatusCreation.jsp"
        name="serviceRequestStatusMaintenanceForm"
        scope="session"
        type="aquatron.struts.StrutsActionServiceRequestStatusCreation"
        validate="false"
    >
        <forward name="serviceRequestStatusCreation" 
path="/JSPs/ServiceRequestStatusCreation.jsp"/>
        <forward name="initializeServiceRequestStatusMaintenance" 
path="/serviceRequestStatusMaintenance.struts"/>
    </action>

The Struts form class aquatron.struts.StrutsFormServiceRequestStatusMaintenance 
uses a java.util.List (concrete implementation Vector) as the container for the 
collection of check-box values. The accessor for the individual check-box 
values has the signature public final boolean 
getCanFollowServiceRequestsInWhichStatuses(int theIndex) and this retrieves the 
appropriate check-box value from the collection. The mutator has the signature 
public final void setCanFollowServiceRequestsInWhichStatuses(int theIndex, 
boolean theAnswer).

I had to make a change to the doStartTag() method of 
org.apache.struts.taglib.html.CheckboxTag to get the HTML to be successfully 
rendered. This was because the existing code generates a tag starting with 
something like <input type="checkbox" name="<Struts form name>[0].<property 
name>"... in the string buffer that it later uses for generating the tag, then, 
in order to determine whether or not the check-box is checked, it calls the 
org.apache.struts.util.ResponseUtils method lookup(PageContext, String, String, 
String) passing as the second parameter the Struts form and the third parameter 
the name of the indexed check-box property but without including 
the "[<index>]" suffix. Of course, the reflection attempt cannot find the 
correct method because it is looking for a simple bean rather than an indexed 
bean.

The CheckboxTag doStartTag() method looked like this before I changed it:

    /**
     * Generate the required input tag.
     * <p>
     * Support for indexed property since Struts 1.1
     *
     * @exception JspException if a JSP exception has occurred
     */
    public int doStartTag() throws JspException {

        // Create an appropriate "input" element based on our parameters
        StringBuffer results = new StringBuffer("<input type=\"checkbox\"");
        results.append(" name=\"");
        // * @since Struts 1.1
        if( indexed )
                prepareIndex( results, name );
        results.append(this.property);
        results.append("\"");
        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(value)
            || checked.equalsIgnoreCase("true")
            || checked.equalsIgnoreCase("yes")
            || checked.equalsIgnoreCase("on"))
            results.append(" checked=\"checked\"");
        results.append(prepareEventHandlers());
        results.append(prepareStyles());
        results.append(getElementClose());

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

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

    }

When I changed the method like this my application started working:

    /**
     * Generate the required input tag.
     * <p>
     * Support for indexed property since Struts 1.1
     *
     * @exception JspException if a JSP exception has occurred
     */
    public int doStartTag() throws JspException {
        StringBuffer thePropertyIncludingIndexStringBuffer;
        String thePropertyIncludingIndex;

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

        thePropertyIncludingIndex = null;
        if (property != null) {
            // Build up the name of the property including its index if
            // an index is necessary.
            thePropertyIncludingIndexStringBuffer =
                new StringBuffer(getProperty());                        
            if(getIndexed()){
                prepareIndex(thePropertyIncludingIndexStringBuffer, null );
            } // end if()
            thePropertyIncludingIndex =
                thePropertyIncludingIndexStringBuffer
               .toString();
            results.append(" name=\"");
            results.append(thePropertyIncludingIndex);
            results.append("\"");
        }

        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 = null;
        if(getProperty() != null){
            result =
                RequestUtils
                .lookup(pageContext, name, thePropertyIncludingIndex, null);
        } // end if()

        if (result == null)
            result = "";
        if (!(result instanceof String))
            result = result.toString();
        String checked = (String) result;
        if (checked.equalsIgnoreCase(value)
            || checked.equalsIgnoreCase("true")
            || checked.equalsIgnoreCase("yes")
            || checked.equalsIgnoreCase("on"))
            results.append(" checked=\"checked\"");
        results.append(prepareEventHandlers());
        results.append(prepareStyles());
        results.append(getElementClose());

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

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

    }

Regards,
Norman Denton.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to