You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by le...@gmail.com on 2012/09/11 17:25:39 UTC

how to refresh page zone inside a component

Hi!

I am facing some problems with an own component. This component renders
some eventLinks with the use of componentResources and markupWriter.
I have included this component in a page with a zone near it that must show
some info based on the eventLink of the component clicked.
I want only the zone to be updated in order that the component do not
render again.

Does anybody knows how to update a zone in a page when any eventlink of the
component is clicked?

The eventLink created with markupWriter does not fire an ajax request, so
it refresh the hole page instead of only de zone.

Comments:
I have used markupWriter because i had to make recursive methods in order
to obtains eventLinks in diferent labels (like a Tree)
I am using Tapestry 5.1 and i cannot update this project to the latest one.

Here is some code:

Part of Page.tml:
    <div class="test">
        <h1>test Page</h1>

        <ems:EmsElementTree zoneToUpdate="elementBrowserZone"/>

        <t:zone t:id="elementBrowserZone" id="elementBrowserZone">
            <div class="elementBrowser">
                information here based on the eventlink clicked
            </div>
        </t:zone>
    </div>

Part of Component.java:
            markupWriter.element("div", "class","row");
            markupWriter.element("a", "class", "showElementBrowserLink",
"href", componentResources.createEventLink("testLink",myData));
                    markupWriter.write(baseElement.getRootName());
                    markupWriter.end();
            markupWriter.end();

    public Object onTestLink(String element){
System.out.println("*****ES AJAX: "+request.isXHR());
          return this.zoneToupdate.getBody();
    }



Thanks in advance.

Leandro.

Re: how to refresh page zone inside a component

Posted by Lance Java <la...@googlemail.com>.
NB. RenderQueue.push() adds commands to the front of the queue so you may
need to iterate in reverse to get the desired output.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/how-to-refresh-page-zone-inside-a-component-tp5716201p5716232.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: how to refresh page zone inside a component

Posted by le...@gmail.com.
Thank you Lance.
I will try your solution as soon as possible.
Then i will write to you again telling about the results obtained.


2012/9/11 Lance Java <la...@googlemail.com>

> Lets assume you are writing a LinkTree component which accepts a
> LinkTreeModel parameter. LinkTreeModel has a visitAll method which takes a
> LinkNodeVisitor.
>
> You could do something like this (not tested)
>
> LinkTree.tml
> -----------
> <t:block id="linkBlock">
>    <t:eventlink event="linkEvent">${linkLabel}</t:eventlink>
> </t:block>
>
> LinkTree.java
> -------------
> public class LinkTree {
>         @InjectComponent
>         private RenderCommand linkBlock;
>
>         @Property
>         private String linkEvent;
>
>         @Property
>         private String linkLabel;
>
>         @Parameter
>         private LinkTreeModel model;
>
>         public RenderCommand onBeginRender() {
>                 return new RenderCommand() {
>                         public void render(MarkupWriter writer, final
> RenderQueue queue) {
>                                 model.visitAll(new LinkNodeVisitor() {
>                                         public void visit(final
> LinkTreeNode node) {
>                                                 queue.push(new
> RenderCommand() {
>                                                         public void
> render(MarkupWriter writer, RenderQueue queue2) {
>
> LinkTree.this.linkEvent = node.getEvent();
>
> LinkTree.this.linkLabel = node.getLabel();
>
> queue2.push(linkBlock);
>                                                         }
>                                                 });
>                                         }
>                                 });
>                         }
>                 };
>         }
> }
>
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/how-to-refresh-page-zone-inside-a-component-tp5716201p5716214.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: how to refresh page zone inside a component

Posted by Lance Java <la...@googlemail.com>.
Lets assume you are writing a LinkTree component which accepts a
LinkTreeModel parameter. LinkTreeModel has a visitAll method which takes a
LinkNodeVisitor.

You could do something like this (not tested)

LinkTree.tml
-----------
<t:block id="linkBlock">
   <t:eventlink event="linkEvent">${linkLabel}</t:eventlink>
</t:block>

LinkTree.java
-------------
public class LinkTree {
	@InjectComponent
	private RenderCommand linkBlock;
	
	@Property
	private String linkEvent;
	
	@Property
	private String linkLabel;
	
	@Parameter
	private LinkTreeModel model;
	
	public RenderCommand onBeginRender() {
		return new RenderCommand() {
			public void render(MarkupWriter writer, final RenderQueue queue) {
				model.visitAll(new LinkNodeVisitor() {
					public void visit(final LinkTreeNode node) {
						queue.push(new RenderCommand() {
							public void render(MarkupWriter writer, RenderQueue queue2) {
								LinkTree.this.linkEvent = node.getEvent();
								LinkTree.this.linkLabel = node.getLabel();
								queue2.push(linkBlock);
							}
						});
					}
				});
			}
		};
	}
}




--
View this message in context: http://tapestry.1045711.n5.nabble.com/how-to-refresh-page-zone-inside-a-component-tp5716201p5716214.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: how to refresh page zone inside a component

Posted by le...@gmail.com.
Sorry, but i do not understand how the RenderCommand can help me creating
eventLinks that generates ajax requests to update a zone.

Can you give me an example or more info?

Thank you again,

Leandro

2012/9/11 Lance Java <la...@googlemail.com>

> You don't need to use the markup writer to generate recursive content. You
> can return a RenderCommand from any render phase method. Note also that
> injected Blocks (or Block parameters) can be type coerced to a
> RenderCommand.
>
>
>
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/how-to-refresh-page-zone-inside-a-component-tp5716201p5716204.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: how to refresh page zone inside a component

Posted by Lance Java <la...@googlemail.com>.
You don't need to use the markup writer to generate recursive content. You
can return a RenderCommand from any render phase method. Note also that
injected Blocks (or Block parameters) can be type coerced to a
RenderCommand.






--
View this message in context: http://tapestry.1045711.n5.nabble.com/how-to-refresh-page-zone-inside-a-component-tp5716201p5716204.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: how to refresh page zone inside a component

Posted by le...@gmail.com.
The line  System.out.println("*****ES AJAX: "+request.isXHR()); is always
printing false.

Because the event link rendered with markupWriter does not add the
"Tapestry.init linkzone" to javascript code.



2012/9/11 <le...@gmail.com>

> Hi!
>
> I am facing some problems with an own component. This component renders
> some eventLinks with the use of componentResources and markupWriter.
> I have included this component in a page with a zone near it that must
> show some info based on the eventLink of the component clicked.
> I want only the zone to be updated in order that the component do not
> render again.
>
> Does anybody knows how to update a zone in a page when any eventlink of
> the component is clicked?
>
> The eventLink created with markupWriter does not fire an ajax request, so
> it refresh the hole page instead of only de zone.
>
> Comments:
> I have used markupWriter because i had to make recursive methods in order
> to obtains eventLinks in diferent labels (like a Tree)
> I am using Tapestry 5.1 and i cannot update this project to the latest one.
>
> Here is some code:
>
> Part of Page.tml:
>     <div class="test">
>         <h1>test Page</h1>
>
>         <ems:EmsElementTree zoneToUpdate="elementBrowserZone"/>
>
>         <t:zone t:id="elementBrowserZone" id="elementBrowserZone">
>             <div class="elementBrowser">
>                 information here based on the eventlink clicked
>             </div>
>         </t:zone>
>     </div>
>
> Part of Component.java:
>             markupWriter.element("div", "class","row");
>             markupWriter.element("a", "class", "showElementBrowserLink",
> "href", componentResources.createEventLink("testLink",myData));
>                     markupWriter.write(baseElement.getRootName());
>                     markupWriter.end();
>             markupWriter.end();
>
>     public Object onTestLink(String element){
> System.out.println("*****ES AJAX: "+request.isXHR());
>           return this.zoneToupdate.getBody();
>     }
>
>
>
> Thanks in advance.
>
> Leandro.
>
>
>
>
>
>