You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Davide Vecchi <dv...@amc.dk> on 2014/03/25 12:26:33 UTC

Updating a zone from a property method

I have a zone to show possible errors that might occur in a get* method called by Tapestry during page rendering to retrieve the value for a property (String myValue in the example below).

So in this getMyValue() method I set the error message into another property (@Property String errorMessage) and I call addRender to update the template zone errorZone, where ${errorMessage} is placed.

My problem is that this call to addRender has no effect: the errorMessage is not shown. But if I just reload the page it is shown.

Below is a testable example. I'm trying to find out what's the right way to update a zone from a get* method called by Tapestry during page rendering.

#####################################
TestRender.tml:
#####################################


<html  xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">

       <t:zone id="errorZone" t:id="errorZone">

              <t:if t:test="isError">

                     <div style="background-color: yellow;">${errorMessage}</div>

              </t:if>

       </t:zone>

       myValue: ${myValue}

</html>


#####################################
TestRender.java:
#####################################

import java.util.Date;

import org.apache.tapestry5.PersistenceConstants;
import org.apache.tapestry5.annotations.InjectComponent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Zone;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.ajax.AjaxResponseRenderer;

public class TestRender
{

       @Persist(PersistenceConstants.FLASH)
       @Property
       private boolean              isError;

       @Persist(PersistenceConstants.FLASH)
       @Property
       private String               errorMessage;

       @InjectComponent
       @Property
       private Zone                 errorZone;

       @Inject
       private AjaxResponseRenderer ajaxResponseRenderer;

       @Persist
       private String               myValue;

       public void setupRender()
       {
              System.out.println(new Date() + " setupRender() was executed. It does nothing at all.");
       }

       public String getMyValue()
       {
              if (this.myValue == null)
              {
                     System.out.println(new Date() + " myValue was null, so getMyValue() is setting it...");

                     this.myValue = "My value at " + new Date();

                     this.isError = true;
                     this.errorMessage = "Let's say there was an error so I want to show this error message.";

                     this.ajaxResponseRenderer.addRender(this.errorZone);

                     /* I expected this addRender to cause the error message to be shown right away
                        without the need to reload the page, but this is not the case. */

                     System.out.println(new Date() + " getMyValue() has just called addRender.");
              }
              else
              {
                     System.out.println(new Date() + " myValue was NOT null, so getMyValue() did nothing at all.");
              }
              return this.myValue;
       }
}


Re: Updating a zone from a property method

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
Hi!

On Tue, 25 Mar 2014 08:26:33 -0300, Davide Vecchi <dv...@amc.dk> wrote:

> I have a zone to show possible errors that might occur in a get* method  
> called by Tapestry during page rendering to retrieve the value for a  
> property (String myValue in the example below).

Why do you want for that to happen inside a getter? It does look like a  
wrong thing for me. Getters are mostly expected to not have side-effects.

> So in this getMyValue() method I set the error message into another  
> property (@Property String errorMessage) and I call addRender to update  
> the template zone errorZone, where ${errorMessage} is placed.

You're trying to use AjaxResponseRenderer during the initial render of the  
zone, which is a normal, full-page, non-AJAX request, not when the zone is  
being updated during an AJAX request. In addition, your getter, which is  
the method that sets the error message, is only invoked *after* the zone  
is rendered. There's nothing in your page that triggers the AJAX update so  
you can show the error.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


RE: Updating a zone from a property method

Posted by Davide Vecchi <dv...@amc.dk>.
 > That's not a workaround, it's a matter of what is called first.

In theory it could be both things, however I realized that you're right that it's not a workaround when I compare it to the structure outlined by Geoff, which sounds like the proper structure. It was sounding to me like a workaround because I believed that the proper structure was to retrieve the values only from the getter when Tapestry calls it, and not from setupRender, and this turned out to be wrong, so I no longer consider it a workaround.

Thanks Geoff for the thorough explanation, much appreciated. I actually had ended up doing basically that, except that from setupRender I explicitly call the getter to set up the value instead of calling a setupValue method, but the need to explicitly call the getter was actually the part that perplexed me. I think having a setupValue method called from setupRender that calculates the value and having the getter to simply return that value as in your example is much cleaner, I will go for that.

In my opinion it's also remarkable that the order in which the elements appear in the template made the difference. Now that it was mentioned it sounds obvious but I had not realized that earlier. If in the template of my initial example I just move the ${myValue} above the error zone, it works as I had expected, that is the message is shown, because the message is set in the getter which is now called before the error zone is rendered.
However I don't think it's a good idea to rely on the order of the elements in the template, so I will stick to calculating in setupRender the values for the getters to return.

Thanks all for the assistance !



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


Re: Updating a zone from a property method

Posted by Geoff Callender <ge...@gmail.com>.
I think David may need to start from scratch...

First, render a page with no errors. The template can include a zone. Notice that the zone is rendered too. It defines an area that the server can now refresh - but only in response to an AJAX request.

You can set up the fields on before you render it or during render. In your example, you're setting up the fields during render. This happens in the sequence that they're referenced in the template. isError and errorMessage are referenced before myValue, so they are false and empty because getMyValue has not been called yet. A solution is to set them up before render, use setupRender(). For example, you could do this:

    private String myValue;

    void setupRender() {
    	setupMyValue();
    }

    private void setupMyValue() {
        // ... do it and set errors if necessary.
    }

    public String getMyValue() {
        return myValue;
    }

...or in the style I prefer...

    @Property
    private String myValue;

    void setupRender() {
        setupMyValue();
    }

    private void setupMyValue() {
        // ... do it and set errors if necessary.
    }

Now you'll see your errors and your value. You could remove the zone (but not its contents) and the effect will be the same. The zone is only useful if, now that the page has been rendered and returned to the browser, you need to send an AJAX request and have a partial-page response.

HTH,

Geoff

On 27/03/2014, at 5:49 AM, Thiago H de Paula Figueiredo wrote:

> On Wed, 26 Mar 2014 10:44:05 -0300, Davide Vecchi <dv...@amc.dk> wrote:
> 
>>> Anyway, maybe you should rethink the way you handle your exceptions.
>>> Shouldn't they be treated inside the getter methods themselves?
>> 
>> I'm very confused about this suggestion. Am I not doing exactly that ? I mean, treating the exception inside the getter is exactly what I was trying to do in the first place, by showing an error message, which turned out not to be possible,
> 
> It's not possible because the error message is rendered before the getter is called.
> 
>> So I will just call the getters from setupRender(). I'm a bit perplexed going for something that sounds a bit like a workaround for a scenario that in my opinion is quite standard, but maybe I will come up with something more straightforward in future.
> 
> That's not a workaround, it's a matter of what is called first.
> 
> -- 
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
> 
> ---------------------------------------------------------------------
> 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: Updating a zone from a property method

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 26 Mar 2014 10:44:05 -0300, Davide Vecchi <dv...@amc.dk> wrote:

>> Anyway, maybe you should rethink the way you handle your exceptions.
>> Shouldn't they be treated inside the getter methods themselves?
>
> I'm very confused about this suggestion. Am I not doing exactly that ? I  
> mean, treating the exception inside the getter is exactly what I was  
> trying to do in the first place, by showing an error message, which  
> turned out not to be possible,

It's not possible because the error message is rendered before the getter  
is called.

> So I will just call the getters from setupRender(). I'm a bit perplexed  
> going for something that sounds a bit like a workaround for a scenario  
> that in my opinion is quite standard, but maybe I will come up with  
> something more straightforward in future.

That's not a workaround, it's a matter of what is called first.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


RE: Updating a zone from a property method

Posted by Davide Vecchi <dv...@amc.dk>.
Thanks for the pointers about onException and @Cached, I didn't know either.

@Cached would allow me to avoid wrapping the getter body in an "if (this.myValue == null)".

onException would help my case only if it was possible to update a zone from that method even if the exception that triggered its execution had occurred in a getter called during page rendering, which I imagine is not possible, but I will check.

> Anyway, maybe you should rethink the way you handle your exceptions.  
> Shouldn't they be treated inside the getter methods themselves?

I'm very confused about this suggestion. Am I not doing exactly that ? I mean, treating the exception inside the getter is exactly what I was trying to do in the first place, by showing an error message, which turned out not to be possible, see my first example (it has no try/catch just because the error doesn't necessarily need to be a Java exception, it might be a call returning a value indicating failure or such).

So I will just call the getters from setupRender(). I'm a bit perplexed going for something that sounds a bit like a workaround for a scenario that in my opinion is quite standard, but maybe I will come up with something more straightforward in future.

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

Re: Updating a zone from a property method

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 26 Mar 2014 08:25:40 -0300, Davide Vecchi <dv...@amc.dk> wrote:

> 1) I have a getter that might cause an error.
>
> 2) This getter gets called for the first time by Tapestry, during page  
> rendering (because its value must already appear in the page, before any  
> possible user action).
>
> 3) If this getter causes an error when called during page rendering, I  
> want a message to be shown in the rendered page.
>
> It looks to me like the "normal" way to do that is to manually call all  
> the getters from setupRender, so that if some of them cause errors, I  
> can set the messages into the corresponding properties while I'm still  
> in the setupRender method, so these properties will appear in the  
> rendered page.

You can try adding an onException(Exception e) method to your class. It'll  
be called when any exception happens.

In addition, you can call the getters from setupRender(), but annotate the  
getters with @Cached, so they'll actually be called just once per request.  
 From the second call on, Tapestry will return the result of the first  
without actually running the body of your method.

Anyway, maybe you should rethink the way you handle your exceptions.  
Shouldn't they be treated inside the getter methods themselves?

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


RE: Updating a zone from a property method

Posted by Davide Vecchi <dv...@amc.dk>.
Nope, it looks like none of the methods executed during the Rendering Phases or the Page Life Cycle can update a zone. Which makes sense considering what I have been explained here about updating zones.

Considering that, I realized that my kind of problem is not that much about zones. I would have the same problem even if the area where I want to show the error message was not a zone, like in the example below.

This kind of problem can be narrowed down to this, and it sounds like a quite normal scenario to me:

1) I have a getter that might cause an error.

2) This getter gets called for the first time by Tapestry, during page rendering (because its value must already appear in the page, before any possible user action).

3) If this getter causes an error when called during page rendering, I want a message to be shown in the rendered page.

It looks to me like the "normal" way to do that is to manually call all the getters from setupRender, so that if some of them cause errors, I can set the messages into the corresponding properties while I'm still in the setupRender method, so these properties will appear in the rendered page.

This is what I did in the below example. Not sure it's the recommended way though.

#####################################
TestRender.tml:
#####################################

<html  xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"> 
	
	<t:if t:test="isError">
	
		<div style="background-color: yellow;">${errorMessage}</div>		
	
	</t:if>	
	
	myValue: ${myValue}
	
</html>

#####################################
TestRender.java:
#####################################

import java.util.Date;

import org.apache.tapestry5.PersistenceConstants;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;

public class TestRender
{	
	@Persist(PersistenceConstants.FLASH)
	@Property
	private boolean              isError;
	
	@Persist(PersistenceConstants.FLASH)
	@Property
	private String               errorMessage;
	
	@Persist
	private String               myValue;
	
	public void setupRender()
	{
		getMyValue(); // : Do now the calculations that might cause an error that needs to be shown.
		
		System.out.println(new Date() + " Exiting setupRender() .");
	}
	
	public String getMyValue()
	{
		if (this.myValue == null)
		{
			System.out.println(new Date() + " myValue was null, so getMyValue() is setting it...");
			
			this.myValue = "My value at " + new Date();
			
			this.isError = true;
			this.errorMessage = "Let's say there was an error so I want to show this error message.";
		}
		else
		{
			System.out.println(new Date() + " myValue was NOT null, so getMyValue() did nothing at all.");
		}
		return this.myValue;
	}	
}



RE: Updating a zone from a property method

Posted by Davide Vecchi <dv...@amc.dk>.
Hi, thanks for the clarifications.

> If these values are used in the initial page rendering, as it's the case here,
> you don't need to @Persist them at all. The values of the fields will be kept
> until the request is finished.

(Just a detail) I was thinking @Persist because if I had to calculate all the values in the setupRender method then I wouldn't want to recalculate them all every time setupRender is called again (for ex. when an event handler in the page returns the page itself).

>>  Plus I don't know if one can update a zone from the setupRender method.

> It makes absolutely no sense to do that, as I already explained above,  
> because zones are not meant to be updated during the page rendering.

Got it, thanks.

>> they show how to update a zone in response to a user's action (clicking  
>> on a link or button) while in my case I need to update a zone in  
>> response to "nothing" - that is, in response to an error occurred during  
>> the initial page loading, before any possible user's action.

> That's the whole point: you don't need AJAX nor zones for that. A zone is  
> meant to be updated after the initial page loading, usually by user  
> action, but also possibly by some timer.

This makes a lot of sense too, however in my real case (not the example) I need to have a zone for the error messages, because I use it to show errors that might occur when the user does something after the page is rendered. So I was trying to update that same zone also for errors that occur during page rendering. So I have to think of a way to update a zone when I detect an error during page rendering. 

I will try setting some flag if I detect an error during page rendering, and then check that flag in some method that Tapestry calls when the rendering is complete and from which it's possible to update a zone.
Based on my understanding of the jumpstart demo "What is Called and When"  (http://jumpstart.doublenegative.com.au/jumpstart/examples/navigation/whatiscalledandwhen), I suppose that such a method might be afterRender() or cleanupRender() or pageDetached() . I'm just not sure I can update a zone from one of those methods, I'll try and see.

Re: Updating a zone from a property method

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 25 Mar 2014 12:33:30 -0300, Davide Vecchi <dv...@amc.dk> wrote:

> Hi,

Hi!

> The jumpstart examples linked by Geoff Callender are also useful but  
> they show how to update a zone in response to a user's action (clicking  
> on a link or button) while in my case I need to update a zone in  
> response to "nothing" - that is, in response to an error occurred during  
> the initial page loading, before any possible user's action.

That's the whole point: you don't need AJAX nor zones for that. A zone is  
meant to be updated after the initial page loading, usually by user  
action, but also possibly by some timer.

>
>>> I have a zone to show possible errors that might occur in a get* method
>>> called by Tapestry during page rendering to retrieve the value for a
>>> property (String myValue in the example below).
>
>> Why do you want for that to happen inside a getter? It does look like a
>> wrong thing for me. Getters are mostly expected to not have  
>> side-effects.
>
> This point is quite unclear to me. I did so because I think that in a  
> web page the getter is the right place to put the code that retrieves a  
> value to show in the page.

Yeah, I agree with you. I'm sorry for posting that paragraph.

> I could calculate in the setupRender method the return values for all  
> the getters, store them in @Persist fields and just return those fields  
> from the getters.

If these values are used in the initial page rendering, as it's the case  
here, you don't need to @Persist them at all. The values of the fields  
will be kept until the request is finished.

>  Plus I don't know if one can update a zone from the setupRender method.

It makes absolutely no sense to do that, as I already explained above,  
because zones are not meant to be updated during the page rendering.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


RE: Updating a zone from a property method

Posted by Davide Vecchi <dv...@amc.dk>.
Hi,

> You're trying to use AjaxResponseRenderer during the initial render of the  
> zone, which is a normal, full-page, non-AJAX request, not when the zone is  
> being updated during an AJAX request. In addition, your getter, which is  
> the method that sets the error message, is only invoked *after* the zone  
> is rendered. There's nothing in your page that triggers the AJAX update so  
> you can show the error.

Thanks to you and Geoff Callender for pointing this out, now I see it. I needed to update the error zone so I copied the use of AjaxResponseRenderer from another page, without checking too much how it was used there. As often is the case in this business, taking shortcuts to save time wastes time.  I will have to read more about how to update zones.

The jumpstart examples linked by Geoff Callender are also useful but they show how to update a zone in response to a user's action (clicking on a link or button) while in my case I need to update a zone in response to "nothing" - that is, in response to an error occurred during the initial page loading, before any possible user's action.

>> I have a zone to show possible errors that might occur in a get* method  
>> called by Tapestry during page rendering to retrieve the value for a  
>> property (String myValue in the example below).

>Why do you want for that to happen inside a getter? It does look like a  
>wrong thing for me. Getters are mostly expected to not have side-effects.

This point is quite unclear to me. I did so because I think that in a web page the getter is the right place to put the code that retrieves a value to show in the page.

I could calculate in the setupRender method the return values for all the getters, store them in @Persist fields and just return those fields from the getters. But I would be calculating values that might never be requested by the page because which values are requested by the page can depend on what the user clicks on that page. Plus I don't know if one can update a zone from the setupRender method.
Regardless, I currently believe that the best place to calculate a value to show in the page is the getter for that value.

In my understanding my approach looks exactly like the 

	serverTime1:  ${serverTime1}

and the corresponding

	public Date getServerTime1() {
	        return new Date();
	}

bits from the jumpstart eventlink example mentioned above (http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/eventlink) .
Just like in my case, in that example the getter is first called at page loading time, before the user can click anything, because the value has to be already there as soon as the page is loaded.

I totally agree that these getters should just return a value without changing anything outside their scope, but if they have to calculate or retrieve the value to return, then they can always throw exceptions, which I would like to handle by updating a zone.

So we can stick to the jumpstart example and say that that getServerTime1() method throws an exception when called at page loading time and that we want to handle that situation by updating an "error" zone somewhere else in the page. Can that be done in a Tapestry-friendly way ?

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

Re: Updating a zone from a property method

Posted by Geoff Callender <ge...@gmail.com>.
Not sure if I'm understanding your sequence, but I don't see an AJAX
request there. Tapestry can return zone(s) in response to an AJAX request
(ie. XHR). Do these help?

    http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/eventlink
    http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/form

Geoff


On 25 March 2014 23:41, Davide Vecchi <dv...@amc.dk> wrote:

> Sorry for the double post. After I posted the first one I realized I had
> unsubscribed from the mailing list some time ago, so I subscribed and sent
> the question again. I thought the one I had sent while unsubscribed
> wouldn't show up (it hadn't at that time). My apologies.
>
> -----Original Message-----
> Sent: Tuesday, March 25, 2014 12:27
> To: users@tapestry.apache.org
> Subject: Updating a zone from a property method
>
> I have a zone to show possible errors that might occur in a get* method
> called by Tapestry during page rendering to retrieve the value for a
> property (String myValue in the example below).
>
> So in this getMyValue() method I set the error message into another
> property (@Property String errorMessage) and I call addRender to update the
> template zone errorZone, where ${errorMessage} is placed.
>
> My problem is that this call to addRender has no effect: the errorMessage
> is not shown. But if I just reload the page it is shown.
>
> Below is a testable example. I'm trying to find out what's the right way
> to update a zone from a get* method called by Tapestry during page
> rendering.
>
> #####################################
> TestRender.tml:
> #####################################
>
>
> <html  xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
>
>        <t:zone id="errorZone" t:id="errorZone">
>
>               <t:if t:test="isError">
>
>                      <div style="background-color:
> yellow;">${errorMessage}</div>
>
>               </t:if>
>
>        </t:zone>
>
>        myValue: ${myValue}
>
> </html>
>
>
> #####################################
> TestRender.java:
> #####################################
>
> import java.util.Date;
>
> import org.apache.tapestry5.PersistenceConstants;
> import org.apache.tapestry5.annotations.InjectComponent;
> import org.apache.tapestry5.annotations.Persist;
> import org.apache.tapestry5.annotations.Property;
> import org.apache.tapestry5.corelib.components.Zone;
> import org.apache.tapestry5.ioc.annotations.Inject;
> import org.apache.tapestry5.services.ajax.AjaxResponseRenderer;
>
> public class TestRender
> {
>
>        @Persist(PersistenceConstants.FLASH)
>        @Property
>        private boolean              isError;
>
>        @Persist(PersistenceConstants.FLASH)
>        @Property
>        private String               errorMessage;
>
>        @InjectComponent
>        @Property
>        private Zone                 errorZone;
>
>        @Inject
>        private AjaxResponseRenderer ajaxResponseRenderer;
>
>        @Persist
>        private String               myValue;
>
>        public void setupRender()
>        {
>               System.out.println(new Date() + " setupRender() was
> executed. It does nothing at all.");
>        }
>
>        public String getMyValue()
>        {
>               if (this.myValue == null)
>               {
>                      System.out.println(new Date() + " myValue was null,
> so getMyValue() is setting it...");
>
>                      this.myValue = "My value at " + new Date();
>
>                      this.isError = true;
>                      this.errorMessage = "Let's say there was an error so
> I want to show this error message.";
>
>                      this.ajaxResponseRenderer.addRender(this.errorZone);
>
>                      /* I expected this addRender to cause the error
> message to be shown right away
>                         without the need to reload the page, but this is
> not the case. */
>
>                      System.out.println(new Date() + " getMyValue() has
> just called addRender.");
>               }
>               else
>               {
>                      System.out.println(new Date() + " myValue was NOT
> null, so getMyValue() did nothing at all.");
>               }
>               return this.myValue;
>        }
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

RE: Updating a zone from a property method

Posted by Davide Vecchi <dv...@amc.dk>.
Sorry for the double post. After I posted the first one I realized I had unsubscribed from the mailing list some time ago, so I subscribed and sent the question again. I thought the one I had sent while unsubscribed wouldn't show up (it hadn't at that time). My apologies.

-----Original Message-----
Sent: Tuesday, March 25, 2014 12:27
To: users@tapestry.apache.org
Subject: Updating a zone from a property method

I have a zone to show possible errors that might occur in a get* method called by Tapestry during page rendering to retrieve the value for a property (String myValue in the example below).

So in this getMyValue() method I set the error message into another property (@Property String errorMessage) and I call addRender to update the template zone errorZone, where ${errorMessage} is placed.

My problem is that this call to addRender has no effect: the errorMessage is not shown. But if I just reload the page it is shown.

Below is a testable example. I'm trying to find out what's the right way to update a zone from a get* method called by Tapestry during page rendering.

#####################################
TestRender.tml:
#####################################


<html  xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">

       <t:zone id="errorZone" t:id="errorZone">

              <t:if t:test="isError">

                     <div style="background-color: yellow;">${errorMessage}</div>

              </t:if>

       </t:zone>

       myValue: ${myValue}

</html>


#####################################
TestRender.java:
#####################################

import java.util.Date;

import org.apache.tapestry5.PersistenceConstants;
import org.apache.tapestry5.annotations.InjectComponent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Zone;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.ajax.AjaxResponseRenderer;

public class TestRender
{

       @Persist(PersistenceConstants.FLASH)
       @Property
       private boolean              isError;

       @Persist(PersistenceConstants.FLASH)
       @Property
       private String               errorMessage;

       @InjectComponent
       @Property
       private Zone                 errorZone;

       @Inject
       private AjaxResponseRenderer ajaxResponseRenderer;

       @Persist
       private String               myValue;

       public void setupRender()
       {
              System.out.println(new Date() + " setupRender() was executed. It does nothing at all.");
       }

       public String getMyValue()
       {
              if (this.myValue == null)
              {
                     System.out.println(new Date() + " myValue was null, so getMyValue() is setting it...");

                     this.myValue = "My value at " + new Date();

                     this.isError = true;
                     this.errorMessage = "Let's say there was an error so I want to show this error message.";

                     this.ajaxResponseRenderer.addRender(this.errorZone);

                     /* I expected this addRender to cause the error message to be shown right away
                        without the need to reload the page, but this is not the case. */

                     System.out.println(new Date() + " getMyValue() has just called addRender.");
              }
              else
              {
                     System.out.println(new Date() + " myValue was NOT null, so getMyValue() did nothing at all.");
              }
              return this.myValue;
       }
}


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