You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Karl <ka...@webartjapan.com> on 2003/03/05 06:57:33 UTC

Using a form property as an index into another property

Is it possible to use one form property as an index into another form 
property?

I'm trying to do the following:

<html:form action="do_test.do" name="testForm" type="com.somewhere.TestForm">
    <html:text property="testData[num].data"  maxlength="16" size="16"/>
    <html:submit value="Set"/>
</html:form>


where TestForm has the following:

    private Vector myCollection;

    {
        myCollection = new Vector();
        myCollection.add(new TestData("1"));
        myCollection.add(new TestData("two"));
        myCollection.add(new TestData("III"));
    }

    public Collection getTestData() {
        return myCollection;
    }
    public TestData getTestData(int index) {
        return (TestData)myCollection.get(index);
    }

    private int num = 0;
    public int getNum() {
        return num;
    }
    public void setNum(String num) {
        this.num = Integer.parseInt(num);
    }
    public void setNum(int num) {
        this.num = num;
    }


and TestData is defined as:

public final class TestData {

    private String myData;

    public TestData(String value) {
        myData = value;
    }

    public String getData() {
        return myData;
    }
}



If I use a hardcoded index value, it works as expected:

    <html:text property="testData[0].data"  maxlength="16" size="16"/>


But if I try to use a form property as an index:

    <html:text property="testData[num].data"  maxlength="16" size="16"/>


It fails:

org.apache.jasper.JasperException: Invalid indexed property 'testData[num]'


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Using a form property as an index into another property

Posted by Ray Madigan <ra...@madigans.org>.
Should the tag be:

    <html-el:text property="testData[${testForm.num}].data"  maxlength="16"
size="16"/>

-----Original Message-----
From: Karl [mailto:karl@webartjapan.com]
Sent: Tuesday, March 04, 2003 9:58 PM
To: Struts Users Mailing List
Subject: Using a form property as an index into another property


Is it possible to use one form property as an index into another form
property?

I'm trying to do the following:

<html:form action="do_test.do" name="testForm"
type="com.somewhere.TestForm">
    <html:text property="testData[num].data"  maxlength="16" size="16"/>
    <html:submit value="Set"/>
</html:form>


where TestForm has the following:

    private Vector myCollection;

    {
        myCollection = new Vector();
        myCollection.add(new TestData("1"));
        myCollection.add(new TestData("two"));
        myCollection.add(new TestData("III"));
    }

    public Collection getTestData() {
        return myCollection;
    }
    public TestData getTestData(int index) {
        return (TestData)myCollection.get(index);
    }

    private int num = 0;
    public int getNum() {
        return num;
    }
    public void setNum(String num) {
        this.num = Integer.parseInt(num);
    }
    public void setNum(int num) {
        this.num = num;
    }


and TestData is defined as:

public final class TestData {

    private String myData;

    public TestData(String value) {
        myData = value;
    }

    public String getData() {
        return myData;
    }
}



If I use a hardcoded index value, it works as expected:

    <html:text property="testData[0].data"  maxlength="16" size="16"/>


But if I try to use a form property as an index:

    <html:text property="testData[num].data"  maxlength="16" size="16"/>


It fails:

org.apache.jasper.JasperException: Invalid indexed property 'testData[num]'


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org