Struts don't set the form data onto the Action in the same order in
which the fields appear in the form. For instance, suppose you have a
form like this:

<s:form action="customer!save">
        <s:token/>
        <s:hidden name="id" value="%{id}"/>
        <s:textfield name="customer.name" label="Name" size="30" 
maxlength="200"/>
        <s:textfield name="customer.phoneNumber" label="Phone" size="14"
maxlength="14"/>
        <!-- ... and whatever a zillion fields more -->
</s:form>

And its corresponding Action, which is something like:

public class CustomerAction extends ActionSupport {
        private int id = 0;
        private Customer customer;
        private CustomerDao dao;
        
        public int getId() {
                return id;
        }
        
        public void setId(int id) {
                this.id = id;
        }
        
        public Customer getCustomer() {
                if (customer == null)
                        customer = id != 0 ? dao.get(id) : new Customer();
                
                return customer;
        }
        
        public String input() throws Exception {
                if (getCustomer() == null)
                        return ERROR;
                
                return INPUT;
        }
        
        public String save() throws Exception {
                if (getCustomer() == null)
                        return ERROR;
                
                dao.save(getCustomer());
                
                return SUCCESS;
        }
}

You could expected that Struts, when submitting the form, would first
set the id, then customer.name, then finally custumer.phoneNumber.
However, it does not follow that order; actually, it does set the data
in random order. In this case, the order is important because, if the
user is altering an existing customer, its id must be set before
getCustomer() gets invoked. Otherwise, the action will create a new
customer with zeroed id.

The way I built both the action and the view prevents me from writing
a lot of extra code (like getters and setters for each of the form's
field), and that's why I would like to know whether there's a way to
make Struts follow the fields' ordering when submitting the data into
the action. And if there's not, may the Struts dev team implement
that, if possible.

Regards,

Célio.

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

Reply via email to