Thanks Kris

The method names need to match I was thinking it would work things out, but i guess that the indexed property name must match the method even when the object is scoped during the iteration.

Cheers Mark

On 7 Jan 2004, at 14:49, Kris Schneider wrote:

Quoting Mark Lowe <[EMAIL PROTECTED]>:

Sure the method names were just an example rather than copy n pasting
my code into a mail.

I'm not using the nested tags lib as I don't mind drilling through to
nested objects. The form renders fine and i can set the values, its
when i submit the form, i don't get the values that the user sets in
the jsp, but rather those that are set in the action before forwarding
to the form.

I've been getting n setting my indexed properties like you say. I've
tried just using arraylist and not casting to an array.

Like i said i've a work around, but I dont like it as i need to match
the name of the object thats scoped during the iteration.

I'm sure it should work because nesting beans is so useful. out of
interest have you been able to do this?

Absolutely. I still tend to favor the nested tags for indexed and nested
properties. Are you sure the HTML for the form is really being rendered
correctly? Since you can access your data explicitly through
request.getParameter, it just seems like there's a mismatch between the rendered
parameter names and the properties exposed by the form.


On 7 Jan 2004, at 14:12, Kris Schneider wrote:

Have you tried the nested tags on this?

<html:form ...>
  <nested:iterate property="beans">
    <nested:text property="foo"/>
  <nested:iterate/>
</html:form>

For the form class, the JavaBeans pattern for an indexed property is
the following:

public void setter(int index, PropertyType value);
public PropertyType getter(int index);
public void setter(PropertyType[] values);
public PropertyType[] getter();

For Struts, since it leverages BeanUtils, you can shorthand it to:

public void setter(List values);
public List getter();

I'm not really sure you're exposing the properties you think you are
because
you're using inconsistent method names (getBeans and getBean) as well
as
property types (Object[], ArrayList, and NestedBean).

Quoting Mark Lowe <[EMAIL PROTECTED]>:

Has anyone else had any problems setting nested bean values

Here's and example of what i mean..

public class DemoForm extends ActionForm {

private ArrayList beanList;

        public DemoForm() {
                this.beanList = new ArrayList();
        }

        public Object[] getBeans() {
                return beanList.toArray()
        }
        
        public void setBeans(ArrayList beanList) {
                this.beanList = beanList;
        }
        
        public NestedBean getBean(int i) {
                NestedBean bean = (NestedBean) beanList.get(i);
                return bean;
        }
//and so on
}

..

public class NestedBean {
        private String foo;

        public String getFoo() {
                return foo;
        }       
        
        public void setFoo(String foo) {
                this.foo = foo;
        }
}

..
<c:forEach var="bean" items="${myForm.beans}">
        <html:text name="bean" property="foo" indexed="true" />
</c:forEach>

The problem comes when i change values in the form element the values
dont change so i guess the jsp and the servlets aren't interacting. I
work around by retrieving form the parameter map


String target = "bean["+ i +"].foo";
String value = request.getParameter(target).toString();


This works okay , but I'd really like to know wether i can do this without this hack.

Cheers Mark

-- Kris Schneider <mailto:[EMAIL PROTECTED]> D.O.Tech <http://www.dotech.com/>

-- Kris Schneider <mailto:[EMAIL PROTECTED]> D.O.Tech <http://www.dotech.com/>

---------------------------------------------------------------------
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