You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Robert A. Decker" <de...@robdecker.com> on 2007/09/20 05:09:52 UTC

[T5] Tutorial question

I'm teaching myself Tapestry by jumping right into version 5. I'm a  
pretty experienced developer and so I'm not ready to give up and go  
back to version 4, but I am having what is probably a very basic  
problem...

I'm trying to do the Tapestry 5 tutorial and I'm on the section where  
we count the number of guesses on Guess page page:
http://tapestry.apache.org/tapestry5/tutorial1/hilo.html

The tutorial doesn't fully cover what should be in Guess.java

This method:
Object onActionFromLink(int guess) {
     _count++;
     if (guess == _target) {
         _gameOver.setup(_count);
         return _gameOver;
     }

	    if (guess < _target)
	      _message = String.format("%d is too low.", guess);
	    else
	      _message = String.format("%d is too high.", guess);

	    return null;
}

GameOver is another page in the app. Not knowing exactly what I  
should do, I have declared as a variable in Guess.java:
	@InjectPage
	GameOver _gameOver;


However, this is leading to a NullPointerException, which kind of  
makes sense because GameOver isn't persisted. So, I tried:
@InjectPage @Persist
GameOver _gameOver

But that doesn't fix the problem, and documentation I found in  
Tapestry 4 seems to say that you can't declare multiple injection  
tags per variable.

Does anyone have a working Tapestry 5 tutorial? Or can help me with  
this specific problem?

I've also tried something like:
GameOver _gameOver = new GameOver();
_gameOver.setup(_count);
return _gameOver;

(the WebObjects way) but that leads to an even weirder exception...

Thanks,
Robert A. Decker


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] Tutorial question

Posted by Nick Westgate <ni...@key-planning.co.jp>.
See "Instance variables must be private":
http://tapestry.apache.org/tapestry5/tapestry-core/guide/component-classes.html

Cheers,
Nick.


Robert A. Decker wrote:
> Thank you! That was it - declaring it private fixed it:
> private GameOver _gameOver;
> 
> I now just inject the page but don't persist it.
> 
> I'll have to try to read up on what you mean by 'enhance private 
> variables'...
> 
> R
> 
> 
> On Sep 19, 2007, at 8:20 PM, Robert Zeigler wrote:
> 
>> Background: I've never "done" the T5 tutorial.
>> But I do have functional T5 apps.
>>
>> Few things:
>> 1) In T5, multiple annotations/item are supported
>> 2) You don't need to persist the page. You might need to persist 
>> values that each page needs, but you don't need to persist the pages.
>> 3) Tapestry will only enhance private variables. Your declaration:
>> @InjectPage
>> GameOver _gameOver
>>
>> should be:
>>
>> @InjectPage
>> private GameOver _gameOver
>>
>> Check the tapestry logging output; it should warn you that it didn't 
>> enhance the _gameOver field.
>>
>> Cheers,
>>
>> Robert
>>
>> On Sep 19, 2007, at 9/1910:09 PM , Robert A. Decker wrote:
>>
>>> I'm teaching myself Tapestry by jumping right into version 5. I'm a 
>>> pretty experienced developer and so I'm not ready to give up and go 
>>> back to version 4, but I am having what is probably a very basic 
>>> problem...
>>>
>>> I'm trying to do the Tapestry 5 tutorial and I'm on the section where 
>>> we count the number of guesses on Guess page page:
>>> http://tapestry.apache.org/tapestry5/tutorial1/hilo.html
>>>
>>> The tutorial doesn't fully cover what should be in Guess.java
>>>
>>> This method:
>>> Object onActionFromLink(int guess) {
>>>     _count++;
>>>     if (guess == _target) {
>>>         _gameOver.setup(_count);
>>>         return _gameOver;
>>>     }
>>>
>>>         if (guess < _target)
>>>           _message = String.format("%d is too low.", guess);
>>>         else
>>>           _message = String.format("%d is too high.", guess);
>>>
>>>         return null;
>>> }
>>>
>>> GameOver is another page in the app. Not knowing exactly what I 
>>> should do, I have declared as a variable in Guess.java:
>>>     @InjectPage
>>>     GameOver _gameOver;
>>>
>>>
>>> However, this is leading to a NullPointerException, which kind of 
>>> makes sense because GameOver isn't persisted. So, I tried:
>>> @InjectPage @Persist
>>> GameOver _gameOver
>>>
>>> But that doesn't fix the problem, and documentation I found in 
>>> Tapestry 4 seems to say that you can't declare multiple injection 
>>> tags per variable.
>>>
>>> Does anyone have a working Tapestry 5 tutorial? Or can help me with 
>>> this specific problem?
>>>
>>> I've also tried something like:
>>> GameOver _gameOver = new GameOver();
>>> _gameOver.setup(_count);
>>> return _gameOver;
>>>
>>> (the WebObjects way) but that leads to an even weirder exception...
>>>
>>> Thanks,
>>> Robert A. Decker
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] Tutorial question

Posted by "Robert A. Decker" <de...@robdecker.com>.
Thank you! That was it - declaring it private fixed it:
private GameOver _gameOver;

I now just inject the page but don't persist it.

I'll have to try to read up on what you mean by 'enhance private  
variables'...

R


On Sep 19, 2007, at 8:20 PM, Robert Zeigler wrote:

> Background: I've never "done" the T5 tutorial.
> But I do have functional T5 apps.
>
> Few things:
> 1) In T5, multiple annotations/item are supported
> 2) You don't need to persist the page. You might need to persist  
> values that each page needs, but you don't need to persist the pages.
> 3) Tapestry will only enhance private variables. Your declaration:
> @InjectPage
> GameOver _gameOver
>
> should be:
>
> @InjectPage
> private GameOver _gameOver
>
> Check the tapestry logging output; it should warn you that it  
> didn't enhance the _gameOver field.
>
> Cheers,
>
> Robert
>
> On Sep 19, 2007, at 9/1910:09 PM , Robert A. Decker wrote:
>
>> I'm teaching myself Tapestry by jumping right into version 5. I'm  
>> a pretty experienced developer and so I'm not ready to give up and  
>> go back to version 4, but I am having what is probably a very  
>> basic problem...
>>
>> I'm trying to do the Tapestry 5 tutorial and I'm on the section  
>> where we count the number of guesses on Guess page page:
>> http://tapestry.apache.org/tapestry5/tutorial1/hilo.html
>>
>> The tutorial doesn't fully cover what should be in Guess.java
>>
>> This method:
>> Object onActionFromLink(int guess) {
>>     _count++;
>>     if (guess == _target) {
>>         _gameOver.setup(_count);
>>         return _gameOver;
>>     }
>>
>> 	    if (guess < _target)
>> 	      _message = String.format("%d is too low.", guess);
>> 	    else
>> 	      _message = String.format("%d is too high.", guess);
>>
>> 	    return null;
>> }
>>
>> GameOver is another page in the app. Not knowing exactly what I  
>> should do, I have declared as a variable in Guess.java:
>> 	@InjectPage
>> 	GameOver _gameOver;
>>
>>
>> However, this is leading to a NullPointerException, which kind of  
>> makes sense because GameOver isn't persisted. So, I tried:
>> @InjectPage @Persist
>> GameOver _gameOver
>>
>> But that doesn't fix the problem, and documentation I found in  
>> Tapestry 4 seems to say that you can't declare multiple injection  
>> tags per variable.
>>
>> Does anyone have a working Tapestry 5 tutorial? Or can help me  
>> with this specific problem?
>>
>> I've also tried something like:
>> GameOver _gameOver = new GameOver();
>> _gameOver.setup(_count);
>> return _gameOver;
>>
>> (the WebObjects way) but that leads to an even weirder exception...
>>
>> Thanks,
>> Robert A. Decker
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] Tutorial question

Posted by Robert Zeigler <ro...@scazdl.org>.
Background: I've never "done" the T5 tutorial.
But I do have functional T5 apps.

Few things:
1) In T5, multiple annotations/item are supported
2) You don't need to persist the page. You might need to persist  
values that each page needs, but you don't need to persist the pages.
3) Tapestry will only enhance private variables. Your declaration:
@InjectPage
GameOver _gameOver

should be:

@InjectPage
private GameOver _gameOver

Check the tapestry logging output; it should warn you that it didn't  
enhance the _gameOver field.

Cheers,

Robert

On Sep 19, 2007, at 9/1910:09 PM , Robert A. Decker wrote:

> I'm teaching myself Tapestry by jumping right into version 5. I'm a  
> pretty experienced developer and so I'm not ready to give up and go  
> back to version 4, but I am having what is probably a very basic  
> problem...
>
> I'm trying to do the Tapestry 5 tutorial and I'm on the section  
> where we count the number of guesses on Guess page page:
> http://tapestry.apache.org/tapestry5/tutorial1/hilo.html
>
> The tutorial doesn't fully cover what should be in Guess.java
>
> This method:
> Object onActionFromLink(int guess) {
>     _count++;
>     if (guess == _target) {
>         _gameOver.setup(_count);
>         return _gameOver;
>     }
>
> 	    if (guess < _target)
> 	      _message = String.format("%d is too low.", guess);
> 	    else
> 	      _message = String.format("%d is too high.", guess);
>
> 	    return null;
> }
>
> GameOver is another page in the app. Not knowing exactly what I  
> should do, I have declared as a variable in Guess.java:
> 	@InjectPage
> 	GameOver _gameOver;
>
>
> However, this is leading to a NullPointerException, which kind of  
> makes sense because GameOver isn't persisted. So, I tried:
> @InjectPage @Persist
> GameOver _gameOver
>
> But that doesn't fix the problem, and documentation I found in  
> Tapestry 4 seems to say that you can't declare multiple injection  
> tags per variable.
>
> Does anyone have a working Tapestry 5 tutorial? Or can help me with  
> this specific problem?
>
> I've also tried something like:
> GameOver _gameOver = new GameOver();
> _gameOver.setup(_count);
> return _gameOver;
>
> (the WebObjects way) but that leads to an even weirder exception...
>
> Thanks,
> Robert A. Decker
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org