You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Todd O'Bryan <to...@mac.com> on 2004/04/01 06:25:46 UTC
Populating a form
OK, I think I've come up against my (continuing) incomplete
understanding of Tapestry...
I'm writing a couple of pages to allow a teacher to enter multiple
choice questions and have them stored in a database. There's an
EnterQuestion page, with a form that populates the fields of a Question
object. (The Question object is listed as a property-specification in
the .page file.) I was having trouble, getting NullPointerExceptions
until I realized that I needed to initialize the Question object before
I could bind its fields to the form. I had the page implement
PageRenderListener, and in pageBeginRender() I put
if (getQuestion() == null) { setQuestion(new Question()); }
OK. Everything worked.
At the bottom of EnterQuestion, there was a preview button which lets
someone see the question with formatting and such. I created a
PreviewQuestion page which also had a Question as one of its
properties, and in the listener for Preview, I got the PreviewQuestion
page, and did a quick setQuestion(getQuestion()) before
activate("PreviewQuestion") and all the fields ended up in the right
spot.
So far so good.
Now there are two choices. Either submit the question to the database,
or realize there's a problem, go back, and fix it. So I have Submit and
Edit links. In the Edit link, I tried getting EnterQuestion as
nextPage, and nextPage.setQuestion(getQuestion()), but the fields from
the PreviewQuestion page don't make it into the form, which is what I'd
like to happen.
How do I do this?
Todd
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Populating a form
Posted by Harish Krishnaswamy <hk...@comcast.net>.
Couple things, you have to bind the hidden fields in the form to the
attributes of the question property and your link should be a LinkSubmit
or somthing to the effect.
-Harish
Todd O'Bryan wrote:
> Oh, I see...So that's why you suggested a form with empty fields in
> PreviewQuestion. Those fields would re-populate the Question before
> going back to EnterQuestion.
>
> I'll try that...
>
> Todd
>
> On Apr 1, 2004, at 9:24 AM, Harish Krishnaswamy wrote:
>
>>
>>
>> Todd O'Bryan wrote:
>>
>>> Actually, it's that the question I'm looking at in the PreviewPage
>>> (which is not a form, just HTML text to let the user see what
>>> they've entered) doesn't make it into the form on EnterQuestion
>>> when they want to go back and edit it.
>>>
>>> When someone clicks Edit Question on the PreviewPage, I run (using
>>> a listener):
>>>
>>> public void edit(IRequestCycle cycle) {
>>> EnterQuestion nextPage = (EnterQuestion)
>>> cycle.getPage("EnterQuestion");
>>> nextPage.setQuestion(getQuestion());
>>> cycle.activate(nextPage);
>>> }
>>
>>
>> Because there is no form in this page, the question property will
>> not be populated when the edit link is clicked. So in this case you
>> may want to make the "question" property persistent on the
>> EnterQuestion page. And then you can simply activate the
>> EnterQuestion page when the edit link is clicked. When submit is
>> clicked though you have to do
>> cycle.getEngine().forgetPage("EnterQuestion") so the persistent
>> property is cleared.
>>
>>>
>>> But then when I get to the EnterQuestion page, the form fields are
>>> just blank.
>>>
>>> Todd
>>>
>>> P.S. Thanks for distinguishing between cycle.activate("String") and
>>> cycle.activate(page). To make sure I understand, the first
>>> activates a new instance of the named page while the second
>>> activates the exact instance already referred to by the variable.
>>> Is that right?
>>
>>
>> The first form activates an arbitrary instance from the page pool,
>> while the second form activates the page that you have already
>> retrieved from the pool via cycle.getPage()
>>
>> -Harish
>>
>>>
>>> On Mar 31, 2004, at 11:49 PM, Harish Krishnaswamy wrote:
>>>
>>>> I am not sure I quite follow the question. If you mean the
>>>> PreviewQuestion page is getting populated with the question, then
>>>> one problem, from what I see is, you are setting the question in
>>>> one page and activating another. i.e.
>>>> prevQuestion.setQuestion(getQuestion) and then
>>>> cycle.activate("PreviewQuestion") instead try
>>>> cycle.activate(prevQuestion).
>>>>
>>>> Else if you mean that the question from the preview form doesn't
>>>> make it into the page property that is probably because the form
>>>> fields are either plain text or disabled fields. In this case you
>>>> may want to try the persistent property or you could use hidden
>>>> fields in the preview page if you want to run stateless.
>>>>
>>>> -Harish
>>>>
>>>>
>>>> Todd O'Bryan wrote:
>>>>
>>>>> OK, I think I've come up against my (continuing) incomplete
>>>>> understanding of Tapestry...
>>>>>
>>>>> I'm writing a couple of pages to allow a teacher to enter
>>>>> multiple choice questions and have them stored in a database.
>>>>> There's an EnterQuestion page, with a form that populates the
>>>>> fields of a Question object. (The Question object is listed as a
>>>>> property-specification in the .page file.) I was having trouble,
>>>>> getting NullPointerExceptions until I realized that I needed to
>>>>> initialize the Question object before I could bind its fields to
>>>>> the form. I had the page implement PageRenderListener, and in
>>>>> pageBeginRender() I put
>>>>>
>>>>> if (getQuestion() == null) { setQuestion(new Question()); }
>>>>>
>>>>> OK. Everything worked.
>>>>>
>>>>> At the bottom of EnterQuestion, there was a preview button which
>>>>> lets someone see the question with formatting and such. I created
>>>>> a PreviewQuestion page which also had a Question as one of its
>>>>> properties, and in the listener for Preview, I got the
>>>>> PreviewQuestion page, and did a quick setQuestion(getQuestion())
>>>>> before activate("PreviewQuestion") and all the fields ended up in
>>>>> the right spot.
>>>>>
>>>>> So far so good.
>>>>>
>>>>> Now there are two choices. Either submit the question to the
>>>>> database, or realize there's a problem, go back, and fix it. So I
>>>>> have Submit and Edit links. In the Edit link, I tried getting
>>>>> EnterQuestion as nextPage, and
>>>>> nextPage.setQuestion(getQuestion()), but the fields from the
>>>>> PreviewQuestion page don't make it into the form, which is what
>>>>> I'd like to happen.
>>>>>
>>>>> How do I do this?
>>>>>
>>>>> Todd
>>>>>
>>>>>
>>>>> --------------------------------------------------------------------
>>>>> -
>>>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>>>> For additional commands, e-mail:
>>>>> tapestry-user-help@jakarta.apache.org
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail:
>>>> tapestry-user-help@jakarta.apache.org
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Populating a form
Posted by Todd O'Bryan <to...@mac.com>.
Oh, I see...So that's why you suggested a form with empty fields in
PreviewQuestion. Those fields would re-populate the Question before
going back to EnterQuestion.
I'll try that...
Todd
On Apr 1, 2004, at 9:24 AM, Harish Krishnaswamy wrote:
>
>
> Todd O'Bryan wrote:
>
>> Actually, it's that the question I'm looking at in the PreviewPage
>> (which is not a form, just HTML text to let the user see what they've
>> entered) doesn't make it into the form on EnterQuestion when they
>> want to go back and edit it.
>>
>> When someone clicks Edit Question on the PreviewPage, I run (using a
>> listener):
>>
>> public void edit(IRequestCycle cycle) {
>> EnterQuestion nextPage = (EnterQuestion)
>> cycle.getPage("EnterQuestion");
>> nextPage.setQuestion(getQuestion());
>> cycle.activate(nextPage);
>> }
>
> Because there is no form in this page, the question property will not
> be populated when the edit link is clicked. So in this case you may
> want to make the "question" property persistent on the EnterQuestion
> page. And then you can simply activate the EnterQuestion page when the
> edit link is clicked. When submit is clicked though you have to do
> cycle.getEngine().forgetPage("EnterQuestion") so the persistent
> property is cleared.
>
>>
>> But then when I get to the EnterQuestion page, the form fields are
>> just blank.
>>
>> Todd
>>
>> P.S. Thanks for distinguishing between cycle.activate("String") and
>> cycle.activate(page). To make sure I understand, the first activates
>> a new instance of the named page while the second activates the exact
>> instance already referred to by the variable. Is that right?
>
> The first form activates an arbitrary instance from the page pool,
> while the second form activates the page that you have already
> retrieved from the pool via cycle.getPage()
>
> -Harish
>
>>
>> On Mar 31, 2004, at 11:49 PM, Harish Krishnaswamy wrote:
>>
>>> I am not sure I quite follow the question. If you mean the
>>> PreviewQuestion page is getting populated with the question, then
>>> one problem, from what I see is, you are setting the question in one
>>> page and activating another. i.e.
>>> prevQuestion.setQuestion(getQuestion) and then
>>> cycle.activate("PreviewQuestion") instead try
>>> cycle.activate(prevQuestion).
>>>
>>> Else if you mean that the question from the preview form doesn't
>>> make it into the page property that is probably because the form
>>> fields are either plain text or disabled fields. In this case you
>>> may want to try the persistent property or you could use hidden
>>> fields in the preview page if you want to run stateless.
>>>
>>> -Harish
>>>
>>>
>>> Todd O'Bryan wrote:
>>>
>>>> OK, I think I've come up against my (continuing) incomplete
>>>> understanding of Tapestry...
>>>>
>>>> I'm writing a couple of pages to allow a teacher to enter multiple
>>>> choice questions and have them stored in a database. There's an
>>>> EnterQuestion page, with a form that populates the fields of a
>>>> Question object. (The Question object is listed as a
>>>> property-specification in the .page file.) I was having trouble,
>>>> getting NullPointerExceptions until I realized that I needed to
>>>> initialize the Question object before I could bind its fields to
>>>> the form. I had the page implement PageRenderListener, and in
>>>> pageBeginRender() I put
>>>>
>>>> if (getQuestion() == null) { setQuestion(new Question()); }
>>>>
>>>> OK. Everything worked.
>>>>
>>>> At the bottom of EnterQuestion, there was a preview button which
>>>> lets someone see the question with formatting and such. I created a
>>>> PreviewQuestion page which also had a Question as one of its
>>>> properties, and in the listener for Preview, I got the
>>>> PreviewQuestion page, and did a quick setQuestion(getQuestion())
>>>> before activate("PreviewQuestion") and all the fields ended up in
>>>> the right spot.
>>>>
>>>> So far so good.
>>>>
>>>> Now there are two choices. Either submit the question to the
>>>> database, or realize there's a problem, go back, and fix it. So I
>>>> have Submit and Edit links. In the Edit link, I tried getting
>>>> EnterQuestion as nextPage, and nextPage.setQuestion(getQuestion()),
>>>> but the fields from the PreviewQuestion page don't make it into the
>>>> form, which is what I'd like to happen.
>>>>
>>>> How do I do this?
>>>>
>>>> Todd
>>>>
>>>>
>>>> --------------------------------------------------------------------
>>>> -
>>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail:
>>>> tapestry-user-help@jakarta.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail:
>>> tapestry-user-help@jakarta.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Populating a form
Posted by Harish Krishnaswamy <hk...@comcast.net>.
Todd O'Bryan wrote:
> Actually, it's that the question I'm looking at in the PreviewPage
> (which is not a form, just HTML text to let the user see what they've
> entered) doesn't make it into the form on EnterQuestion when they want
> to go back and edit it.
>
> When someone clicks Edit Question on the PreviewPage, I run (using a
> listener):
>
> public void edit(IRequestCycle cycle) {
> EnterQuestion nextPage = (EnterQuestion)
> cycle.getPage("EnterQuestion");
> nextPage.setQuestion(getQuestion());
> cycle.activate(nextPage);
> }
Because there is no form in this page, the question property will not be
populated when the edit link is clicked. So in this case you may want to
make the "question" property persistent on the EnterQuestion page. And
then you can simply activate the EnterQuestion page when the edit link
is clicked. When submit is clicked though you have to do
cycle.getEngine().forgetPage("EnterQuestion") so the persistent property
is cleared.
>
> But then when I get to the EnterQuestion page, the form fields are
> just blank.
>
> Todd
>
> P.S. Thanks for distinguishing between cycle.activate("String") and
> cycle.activate(page). To make sure I understand, the first activates a
> new instance of the named page while the second activates the exact
> instance already referred to by the variable. Is that right?
The first form activates an arbitrary instance from the page pool, while
the second form activates the page that you have already retrieved from
the pool via cycle.getPage()
-Harish
>
> On Mar 31, 2004, at 11:49 PM, Harish Krishnaswamy wrote:
>
>> I am not sure I quite follow the question. If you mean the
>> PreviewQuestion page is getting populated with the question, then one
>> problem, from what I see is, you are setting the question in one page
>> and activating another. i.e. prevQuestion.setQuestion(getQuestion)
>> and then cycle.activate("PreviewQuestion") instead try
>> cycle.activate(prevQuestion).
>>
>> Else if you mean that the question from the preview form doesn't make
>> it into the page property that is probably because the form fields
>> are either plain text or disabled fields. In this case you may want
>> to try the persistent property or you could use hidden fields in the
>> preview page if you want to run stateless.
>>
>> -Harish
>>
>>
>> Todd O'Bryan wrote:
>>
>>> OK, I think I've come up against my (continuing) incomplete
>>> understanding of Tapestry...
>>>
>>> I'm writing a couple of pages to allow a teacher to enter multiple
>>> choice questions and have them stored in a database. There's an
>>> EnterQuestion page, with a form that populates the fields of a
>>> Question object. (The Question object is listed as a
>>> property-specification in the .page file.) I was having trouble,
>>> getting NullPointerExceptions until I realized that I needed to
>>> initialize the Question object before I could bind its fields to the
>>> form. I had the page implement PageRenderListener, and in
>>> pageBeginRender() I put
>>>
>>> if (getQuestion() == null) { setQuestion(new Question()); }
>>>
>>> OK. Everything worked.
>>>
>>> At the bottom of EnterQuestion, there was a preview button which
>>> lets someone see the question with formatting and such. I created a
>>> PreviewQuestion page which also had a Question as one of its
>>> properties, and in the listener for Preview, I got the
>>> PreviewQuestion page, and did a quick setQuestion(getQuestion())
>>> before activate("PreviewQuestion") and all the fields ended up in
>>> the right spot.
>>>
>>> So far so good.
>>>
>>> Now there are two choices. Either submit the question to the
>>> database, or realize there's a problem, go back, and fix it. So I
>>> have Submit and Edit links. In the Edit link, I tried getting
>>> EnterQuestion as nextPage, and nextPage.setQuestion(getQuestion()),
>>> but the fields from the PreviewQuestion page don't make it into the
>>> form, which is what I'd like to happen.
>>>
>>> How do I do this?
>>>
>>> Todd
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Populating a form
Posted by Todd O'Bryan <to...@mac.com>.
Actually, it's that the question I'm looking at in the PreviewPage
(which is not a form, just HTML text to let the user see what they've
entered) doesn't make it into the form on EnterQuestion when they want
to go back and edit it.
When someone clicks Edit Question on the PreviewPage, I run (using a
listener):
public void edit(IRequestCycle cycle) {
EnterQuestion nextPage = (EnterQuestion)
cycle.getPage("EnterQuestion");
nextPage.setQuestion(getQuestion());
cycle.activate(nextPage);
}
But then when I get to the EnterQuestion page, the form fields are just
blank.
Todd
P.S. Thanks for distinguishing between cycle.activate("String") and
cycle.activate(page). To make sure I understand, the first activates a
new instance of the named page while the second activates the exact
instance already referred to by the variable. Is that right?
On Mar 31, 2004, at 11:49 PM, Harish Krishnaswamy wrote:
> I am not sure I quite follow the question. If you mean the
> PreviewQuestion page is getting populated with the question, then one
> problem, from what I see is, you are setting the question in one page
> and activating another. i.e. prevQuestion.setQuestion(getQuestion) and
> then cycle.activate("PreviewQuestion") instead try
> cycle.activate(prevQuestion).
>
> Else if you mean that the question from the preview form doesn't make
> it into the page property that is probably because the form fields are
> either plain text or disabled fields. In this case you may want to try
> the persistent property or you could use hidden fields in the preview
> page if you want to run stateless.
>
> -Harish
>
>
> Todd O'Bryan wrote:
>
>> OK, I think I've come up against my (continuing) incomplete
>> understanding of Tapestry...
>>
>> I'm writing a couple of pages to allow a teacher to enter multiple
>> choice questions and have them stored in a database. There's an
>> EnterQuestion page, with a form that populates the fields of a
>> Question object. (The Question object is listed as a
>> property-specification in the .page file.) I was having trouble,
>> getting NullPointerExceptions until I realized that I needed to
>> initialize the Question object before I could bind its fields to the
>> form. I had the page implement PageRenderListener, and in
>> pageBeginRender() I put
>>
>> if (getQuestion() == null) { setQuestion(new Question()); }
>>
>> OK. Everything worked.
>>
>> At the bottom of EnterQuestion, there was a preview button which lets
>> someone see the question with formatting and such. I created a
>> PreviewQuestion page which also had a Question as one of its
>> properties, and in the listener for Preview, I got the
>> PreviewQuestion page, and did a quick setQuestion(getQuestion())
>> before activate("PreviewQuestion") and all the fields ended up in the
>> right spot.
>>
>> So far so good.
>>
>> Now there are two choices. Either submit the question to the
>> database, or realize there's a problem, go back, and fix it. So I
>> have Submit and Edit links. In the Edit link, I tried getting
>> EnterQuestion as nextPage, and nextPage.setQuestion(getQuestion()),
>> but the fields from the PreviewQuestion page don't make it into the
>> form, which is what I'd like to happen.
>>
>> How do I do this?
>>
>> Todd
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Populating a form
Posted by Harish Krishnaswamy <hk...@comcast.net>.
I am not sure I quite follow the question. If you mean the
PreviewQuestion page is getting populated with the question, then one
problem, from what I see is, you are setting the question in one page
and activating another. i.e. prevQuestion.setQuestion(getQuestion) and
then cycle.activate("PreviewQuestion") instead try
cycle.activate(prevQuestion).
Else if you mean that the question from the preview form doesn't make it
into the page property that is probably because the form fields are
either plain text or disabled fields. In this case you may want to try
the persistent property or you could use hidden fields in the preview
page if you want to run stateless.
-Harish
Todd O'Bryan wrote:
> OK, I think I've come up against my (continuing) incomplete
> understanding of Tapestry...
>
> I'm writing a couple of pages to allow a teacher to enter multiple
> choice questions and have them stored in a database. There's an
> EnterQuestion page, with a form that populates the fields of a
> Question object. (The Question object is listed as a
> property-specification in the .page file.) I was having trouble,
> getting NullPointerExceptions until I realized that I needed to
> initialize the Question object before I could bind its fields to the
> form. I had the page implement PageRenderListener, and in
> pageBeginRender() I put
>
> if (getQuestion() == null) { setQuestion(new Question()); }
>
> OK. Everything worked.
>
> At the bottom of EnterQuestion, there was a preview button which lets
> someone see the question with formatting and such. I created a
> PreviewQuestion page which also had a Question as one of its
> properties, and in the listener for Preview, I got the PreviewQuestion
> page, and did a quick setQuestion(getQuestion()) before
> activate("PreviewQuestion") and all the fields ended up in the right
> spot.
>
> So far so good.
>
> Now there are two choices. Either submit the question to the database,
> or realize there's a problem, go back, and fix it. So I have Submit
> and Edit links. In the Edit link, I tried getting EnterQuestion as
> nextPage, and nextPage.setQuestion(getQuestion()), but the fields from
> the PreviewQuestion page don't make it into the form, which is what
> I'd like to happen.
>
> How do I do this?
>
> Todd
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org