You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by John Tangney <jt...@knowledgeplanet.com> on 2001/03/08 02:02:55 UTC

Indexed and nested references

Hi

I have been away from this list for a while, so please forgive me if this is
a known problem. I was not able to find a reference...

I am using a JSP with a form bean that has the following properties:
    Vector questions;
    String foo;

There are the usual accessors:
    public QuestionBean getQuestion(int no);
    public String getFoo();
    ...

Each element in the vector is a QuestionBean, and each QuestionBean has:
    Vector answers;
    String userText;

and the usual accessors:
    public AnswerBean getAnswer(int no);
    public String getUserText();

Each element in *this* vector is an AnswerBean, with only scalar properties
and accessors.

My jsp then uses constructs that result in this HTML:
    <input type="text" name="question[0].userText" value="Blue">
    
The JSP is properly populated before it's displayed. (Note the value "Blue"
above.) All the values are correctly pulled from the form bean and its
nested beans. When I submit the form, the next action uses the same form
bean class, and this is where things fall apart. The only request parameter
that gets pulled into the form bean is foo. The indexed "question" is not
recognized.

I reuse the QuestioBean as a form in another place (It extends ActionForm)
and the generated HTML does not use any indexed or nested references. It
works perfectly.

So what's happening? Is the indexed/nested stuff broken? Is the problem
caused by the fact that question[0] yields another bean? (The docs say you
can combine index/nested/simple references.) And why does the formBean -->
JSP populating work, but request --> formBean not?

Any and all hints gratefully accepted.

--johnt


Re: Indexed and nested references

Posted by John Tangney <jt...@knowledgeplanet.com>.
Thanks to all those who responded!

I have figured it out. The problem, as usual, was in my form bean. The
getQuestion(int index) accessor needed to *create* a new QuestionForm if
none existed for the given index. That was it. The succession of exceptions
that were throw were horrifyingly misleading...

Regards
--johnt


on 3/7/01 5:02 PM, John Tangney at jtangney@knowledgeplanet.com wrote:

> Hi
> 
> I have been away from this list for a while, so please forgive me if this is
> a known problem. I was not able to find a reference...
> 
> I am using a JSP with a form bean that has the following properties:
> Vector questions;
> String foo;
> 
> There are the usual accessors:
> public QuestionBean getQuestion(int no);
> public String getFoo();
> ...
> 
> Each element in the vector is a QuestionBean, and each QuestionBean has:
> Vector answers;
> String userText;
> 
> and the usual accessors:
> public AnswerBean getAnswer(int no);
> public String getUserText();
> 
> Each element in *this* vector is an AnswerBean, with only scalar properties
> and accessors.
> 
> My jsp then uses constructs that result in this HTML:
> <input type="text" name="question[0].userText" value="Blue">
> 
> The JSP is properly populated before it's displayed. (Note the value "Blue"
> above.) All the values are correctly pulled from the form bean and its
> nested beans. When I submit the form, the next action uses the same form
> bean class, and this is where things fall apart. The only request parameter
> that gets pulled into the form bean is foo. The indexed "question" is not
> recognized.
> 
> I reuse the QuestioBean as a form in another place (It extends ActionForm)
> and the generated HTML does not use any indexed or nested references. It
> works perfectly.
> 
> So what's happening? Is the indexed/nested stuff broken? Is the problem
> caused by the fact that question[0] yields another bean? (The docs say you
> can combine index/nested/simple references.) And why does the formBean -->
> JSP populating work, but request --> formBean not?
> 
> Any and all hints gratefully accepted.
> 
> --johnt