No.

But with further searching, I found:
https://issues.apache.org/struts/browse/WW-2339

Which suggests this is a documented struts bug and is not currently fixed. 

As a result, I've changed my setApproved method to the following:



        // If no checkboxes are checked, we get Boolean[]{false} instead of
null or an empty int[]
        // If some values are selected, we get a String[] of values because
this method takes in Object[] and struts doesn't know what else to do
        // If this were set to take in Integer[], we'd get Integers if
values were selected, but an error if none were
        // If we have setApproved(Integer[]) and setApproved(Boolean[]) then
an error occurs in all situations
        // This is really stupid.
        // https://issues.apache.org/struts/browse/WW-2339
        public void setApproved(Object[] approved){
                if(approved instanceof String[]){
                        this.approved = new int[approved.length];
                        for(int i=0; i<approved.length; i++){
                                int next =
Integer.valueOf(approved[i].toString());
                                this.approved[i] = next;
                        }
                }
                else{
                        this.approved = new int[]{};
                }
        }




This is ... ugly. I think I just shouldn't be using checkboxes at all.
Instead I should use select boxes with true and false values -- those work
as expected

-----Original Message-----
From: news [mailto:[EMAIL PROTECTED] On Behalf Of Laurie Harper
Sent: Tuesday, May 20, 2008 1:03 PM
To: user@struts.apache.org
Subject: Re: Submitting a form without selecting checkboxes yields 'Input'
result

Michael Gagnon wrote:
> My JSP resembles:
> 
> 
> ....
> <s:form namespace="/labs" action="ApproveItems" method="post" >
> ....
>       <s:iterator value="loggedInUser.approvableBillingItems"
> status="stat" id="next">
>               <s:hidden name="itemsPresent" value="%{id}"/>
>               ...
>               <td><s:checkbox name="approved" fieldValue="%{id}"
> required="false"/></td>
>               ...
>       </s:iterator>
> ....
> </s:form>
> ....
> 
> 
> 
> My action resembles:
> 
> ....
> public class ApproveItemsAction extends ActionSupport {
>       private Integer[] approved;
>       private Integer[] itemsPresent;
>       ...
>       public void setApproved(Integer[] approved){ this.approved =
> approved; }
>       public void setItemsPresent(Integer[] itemsPresent){
> this.itemsPresent = itemsPresent; }
> }
> 
> 
> 
> 
> When some number of checkboxes are selected, then I get an array
containing
> the ID values of the checked objects. This is correct. When NO checkboxes
> are selected, I get:
> No result defined for action bpf.labs.action.ApproveItemsAction and result
> input
> 
> Which is not expected. My action never hits the execute method in this
> scenario. It never even hits 'setApproved' (it does if there are values
> checked. It does not if there are none). I expect setApproved be called
with
> an empty array or just null. Either is acceptable -- Null being what I
> expect I'd PROBABLY see and an empty array being what I'd be HAPPY to see.
> Instead this situation just seems to confuse struts and 'input' is
returned
> at what looks like the time the parameter interceptor is probably trying
to
> handle the checkboxes.
> 
> 
> 
> Is there a way to handle this? Having no checkboxes selected needs to be
an
> acceptable form submission state for this action. My itemsPresent array
must
> be null or an empty array.

Forwarding to 'input' usually means a validation error occurred. Do you 
have any validation configured for this action?

L.


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




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

Reply via email to