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/07/07 14:38:47 UTC

Customizing the grid to alter its own content

Hello everybody,

I would like to customize the Tapestry grid (org.apache.tapestry5.corelib.components.Grid) to make it change the content originally provided in the source parameter, so that the modified content is rendered in the grid instead of the original.

As an example, I could make the grid abbreviate certain strings in a certain way for columns that contain text, so that the abbreviated text is shown instead of the original. This should be independent from the specific data source provided by the specific page that is using the grid: any grid from any page should render its content as abbreviated.

I seem to see in the Grid code several options to try in order to figure out how to implement this functionality, however before starting making changes I'd like to know if there is a recommended, Tapestry-friendly approach. And of course any related comment or suggestion is always welcome.

Thanks in advance

RE: FW: Customizing the grid to alter its own content

Posted by Davide Vecchi <dv...@amc.dk>.
In the example in my last post I'm handling a Node which is a Text: I'm creating a new Text node under the same parent and I'm setting the content of the new node.

Now I would like to do the same for a Node which is an Element instead of a Text, but I can't seem to see a way to set the content of an Element node.

F.ex. I have an Element which is

<div>my text content</div>

I create a new Element with same name and attributes, and the new element ends up being

<div></div>

but I don't know how to set the text content in it. Can it be done ?


-----Original Message-----
From: Thiago H de Paula Figueiredo [mailto:thiagohp@gmail.com] 
Sent: Thursday, July 10, 2014 19:36
To: Tapestry users
Subject: Re: FW: Customizing the grid to alter its own content

On Thu, 10 Jul 2014 11:55:57 -0300, Davide Vecchi <dv...@amc.dk> wrote:

> As usual, thanks a lot for the great assistance, and in particular for 
> pointing me to DOM rewriting.
>
> List<Node> nodes = elementToModify.getChildren();
>
> if (nodes.size() == 1)
> {
> 	if (nodes.get(0) instanceof Text)
> 	{
> 		Text currentNode = (Text) nodes.get(0);
> 		
> 		Text newNode = elementToModify.text("pippo " + 
> currentNode.toString());
> 		
> 		newNode.moveToTop(elementToModify);
> 		
> 		nodes = elementToModify.getChildren();
> 		
> 		nodes.get(1).remove();
> 	}
> }

I think the code is ok, even if it could have some improvements.

--
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: FW: FW: Customizing the grid to alter its own content

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 22 Jul 2014 07:52:45 -0300, Davide Vecchi <dv...@amc.dk> wrote:

> Just for clarity, my concern was only that I'm now replacing the  
> original Element node with a new Text node, while I would have preferred  
> to replace the original Element node with another Element node if it was  
> possible.

It *is* possible, just not with a single method call. Remove the original  
using remove() or removeChildren() and add another with element().

Supposing there's no other element inside the div:

element.removeChildren();
element.element("div").text("text");

> What I get from Tapestry:
>
> <div id="parent"> <div> I'm the OLD child Element </div> </div>
>
> where both div-s are Element instances.
>
> I wondered if it was possible to turn that into
>
> <div id="parent"> <div> I'm the NEW child Element </div> </div>

Supposing "element" is the div with id="parent", this will do exactly what  
you want:

element.removeChildren(); // result: <div id="parent"></div>
Element inner = element.element("div"); // result: <div  
id="parent"><div></div></div>
inner.text("I'm the NEW child Element"); // result: <div  
id="parent"><div>I'm the NEW child Element</div></div>

The last two lines could also be written as just  
element.element("div").text("I'm the NEW child Element"); with the same  
result.

You could also do this:
Element inner = element.find("div"); // returns the first child <div>
inner.removeChildren(); // clears its content
inner.text("I'm the NEW child Element");

Of course, this will only work when the outer <div> has an inner <div>,  
while the solution above this one will work whatever the content inside  
the outer <div>.

> where both div-s are still Element instances,div as an Element instance  
> with different content. But if the new child div is a Text instead,  
> that's no problem, I just wanted to understand.

<div> is an HTML element and will *always* be represented by an Element  
object in Tapestry DOM. <div> will never be a Text instance. You seem to  
be confusing what element and text nodes are in HTML and, by consequence,  
in Tapestry DOM.

-- 
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: FW: FW: Customizing the grid to alter its own content

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

> Thanks, now I get it.

:)

> My mistake was actually that I had misunderstood how XML / HTML is  
> parsed into the Tapestry DOM. Now it makes a lot of sense.

Not just by Tapestry, but by XML parsers and browsers.

> Thanks for your patience in explaining and in spotting my reasoning  
> mistake.

:)

-- 
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: FW: FW: Customizing the grid to alter its own content

Posted by Davide Vecchi <dv...@amc.dk>.
Thanks, now I get it.

My mistake was actually that I had misunderstood how XML / HTML is parsed into the Tapestry DOM. Now it makes a lot of sense.

Although I had already gone for the same solution Thiago mentioned (removing a child and adding a new Text child), for some reason I was convinced that all I had was a parent div Element and a child div Element with a "content", while actually the child Element had a Text child, which was the "content". I had missed that Text child so I thought my new Text was replacing the child Element, instead it was of course replacing its Text child, so it's a Text for a Text.

Thanks for your patience in explaining and in spotting my reasoning mistake.

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

Re: FW: FW: Customizing the grid to alter its own content

Posted by Lance Java <la...@googlemail.com>.
If you consider this case

<div>string1<b>string2</b>string3</div>

The div has 3 children
- string1 - text node
- <b>string2</b> - 'b' element (with a text node child)
- string3 - text node


On 22 July 2014 13:57, Lance Java <la...@googlemail.com> wrote:

> I'm not sure you're getting how XML / HTML is parsed.
> A div is ALWAYS an element, a div can have child nodes (eg other elements
> or text nodes)
>
> Eg:
> <div /> is a div Element with no child nodes
> <div>Foo</div> is a div Element with a Text node as a child.
>
> Elements don't have a text property, but they can have text Nodes as
> children.
>
>
> On 22 July 2014 11:52, Davide Vecchi <dv...@amc.dk> wrote:
>
>> Thanks, I had actually solved by using Element.text() that creates a Text
>> node, which matches your suggestion. I don't have the problem anymore, and
>> thanks for the assistance, despite me not doing a good job in explaining
>> myself.
>>
>> Just for clarity, my concern was only that I'm now replacing the original
>> Element node with a new Text node, while I would have preferred to replace
>> the original Element node with another Element node if it was possible. But
>> it's definitely not a serious limitation so no problem.
>>
>> What I get from Tapestry:
>>
>> <div id="parent"> <div> I'm the OLD child Element </div> </div>
>>
>> where both div-s are Element instances.
>>
>> I wondered if it was possible to turn that into
>>
>> <div id="parent"> <div> I'm the NEW child Element </div> </div>
>>
>> where both div-s are still Element instances, by creating the new child
>> div as an Element instance with different content. But if the new child div
>> is a Text instead, that's no problem, I just wanted to understand.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>
>

Re: FW: FW: Customizing the grid to alter its own content

Posted by Lance Java <la...@googlemail.com>.
I'm not sure you're getting how XML / HTML is parsed.
A div is ALWAYS an element, a div can have child nodes (eg other elements
or text nodes)

Eg:
<div /> is a div Element with no child nodes
<div>Foo</div> is a div Element with a Text node as a child.

Elements don't have a text property, but they can have text Nodes as
children.


On 22 July 2014 11:52, Davide Vecchi <dv...@amc.dk> wrote:

> Thanks, I had actually solved by using Element.text() that creates a Text
> node, which matches your suggestion. I don't have the problem anymore, and
> thanks for the assistance, despite me not doing a good job in explaining
> myself.
>
> Just for clarity, my concern was only that I'm now replacing the original
> Element node with a new Text node, while I would have preferred to replace
> the original Element node with another Element node if it was possible. But
> it's definitely not a serious limitation so no problem.
>
> What I get from Tapestry:
>
> <div id="parent"> <div> I'm the OLD child Element </div> </div>
>
> where both div-s are Element instances.
>
> I wondered if it was possible to turn that into
>
> <div id="parent"> <div> I'm the NEW child Element </div> </div>
>
> where both div-s are still Element instances, by creating the new child
> div as an Element instance with different content. But if the new child div
> is a Text instead, that's no problem, I just wanted to understand.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

RE: FW: FW: Customizing the grid to alter its own content

Posted by Davide Vecchi <dv...@amc.dk>.
Thanks, I had actually solved by using Element.text() that creates a Text node, which matches your suggestion. I don't have the problem anymore, and thanks for the assistance, despite me not doing a good job in explaining myself.

Just for clarity, my concern was only that I'm now replacing the original Element node with a new Text node, while I would have preferred to replace the original Element node with another Element node if it was possible. But it's definitely not a serious limitation so no problem.

What I get from Tapestry:

<div id="parent"> <div> I'm the OLD child Element </div> </div>

where both div-s are Element instances.

I wondered if it was possible to turn that into

<div id="parent"> <div> I'm the NEW child Element </div> </div>

where both div-s are still Element instances, by creating the new child div as an Element instance with different content. But if the new child div is a Text instead, that's no problem, I just wanted to understand.

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

Re: FW: FW: Customizing the grid to alter its own content

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Mon, 21 Jul 2014 09:50:01 -0300, Thiago H de Paula Figueiredo
<th...@gmail.com> wrote:

>> F.ex. I have an Element which is<div>my text content</div>I create a  
>> new Element with same name and attributes, and the new element ends up  
>> being<div></div>but I don't know how to set the text content in it. Can  
>> it be done ?
>
> And here's the answer I gave you.
>
> String newText = ...;
> element.removeChildren():
> element.text(newText);

Ooops, I don't think I've understood your paragraph above, so the solution
above isn't good. If your starting point is <div>my text content</div> and
the desired result is <div><div>new content</div></div> and 'element' is a
variable containing the original <div>, here's what you need to do:

element.removeChildren(); // removes everything inside the outer div
Element inner = element.element("div"); // creates a div inside the outer
div
inner.text("new content"); // adds text to it. as the inner div had no
content, adding text is the same as setting the text

There's no setText(String) method in Tapestry's element as similar ones
exist in jQuery and Prototype. On the other hand, if you clear the
elements content and then add text to it, the end result is the same.

-- 
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: FW: FW: Customizing the grid to alter its own content

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Mon, 21 Jul 2014 09:38:54 -0300, Davide Vecchi <dv...@amc.dk> wrote:

>> Have you checked the Element's methods? You would find your answer  
>> there.
>
> I think it could have been inferred that I did check the Element's  
> methods. If the answer is there and I missed it I'm sorry.
>
> Also, sorry but riddles are not that useful.

Which riddles? I've given you the answer already. You've asked, your words:

> F.ex. I have an Element which is<div>my text content</div>I create a new  
> Element with same name and attributes, and the new element ends up being 
> <div></div>but I don't know how to set the text content in it. Can it be  
> done ?

And here's the answer I gave you.

String newText = ...;
element.removeChildren():
element.text(newText);

-- 
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: FW: FW: Customizing the grid to alter its own content

Posted by Davide Vecchi <dv...@amc.dk>.
> Have you checked the Element's methods? You would find your answer there.

I think it could have been inferred that I did check the Element's methods. If the answer is there and I missed it I'm sorry.

Also, sorry but riddles are not that useful. I know there are some people who just ask questions without bothering to read and try first, but I don't feel like I'm one of those and I don't think I need to be educated about that. I think I explained my doubts very clearly and that would have allowed an answer as clear, whether negative or positive.

However I'm going to use Text, and I think it was OK of me to ask about Element.

-----Original Message-----
From: Thiago H de Paula Figueiredo [mailto:thiagohp@gmail.com] 
Sent: Monday, July 21, 2014 14:31
To: Tapestry users
Subject: Re: FW: FW: Customizing the grid to alter its own content

On Mon, 21 Jul 2014 08:42:46 -0300, Davide Vecchi <dv...@amc.dk> wrote:

> I cannot use Element.raw(String) because although it returns an 
> Element, the node it creates is a Raw node, not an Element node; the 
> Element it returns is just the parent of the new Raw.

Have you checked the Element's methods? You would find your answer there.

You can use removeChildren() to remove all the element's content then use
text(String) to add a Text node inside the element. Yeah,
Element.raw(String) isn't recommended at all here. It is basically when you get an HTML snippet from an outside source, such as a rich text editor like CKEditor.

--
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: FW: FW: Customizing the grid to alter its own content

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Mon, 21 Jul 2014 08:42:46 -0300, Davide Vecchi <dv...@amc.dk> wrote:

> I cannot use Element.raw(String) because although it returns an Element,  
> the node it creates is a Raw node, not an Element node; the Element it  
> returns is just the parent of the new Raw.

Have you checked the Element's methods? You would find your answer there.

You can use removeChildren() to remove all the element's content then use  
text(String) to add a Text node inside the element. Yeah,  
Element.raw(String) isn't recommended at all here. It is basically when  
you get an HTML snippet from an outside source, such as a rich text editor  
like CKEditor.

-- 
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


FW: FW: Customizing the grid to alter its own content

Posted by Davide Vecchi <dv...@amc.dk>.
I cannot use Element.raw(String) because although it returns an Element, the node it creates is a Raw node, not an Element node; the Element it returns is just the parent of the new Raw.

My situation is that I have an Element which contains a child Element, and I want to either replace the child Element with a new Element having different text, or just change the text of that child Element.

F.ex., I have these two Elements

<div id="parent"> <div> I'm the OLD child Element </div> </div>

and I want to turn that into

<div id="parent"> <div> I'm the NEW child Element </div> </div>

where the parent div and the child div are both Element-s before and after, instead of being both Element-s before and then becoming an Element containing a Raw.

So I still would like to know if it's possible to set the text of an Element (either an existing Element or one I create).

I have been thinking that maybe Element-s don't let you set the text because they are just not supposed to contain text and if you want a node with text you should use another subclass of Node, like Text or Raw.
But this doesn't seem to be the case, because the nodes I get from Tapestry are definitely two Elements, parent and child, and the child does contain text, exactly like my example above.

FW: FW: Customizing the grid to alter its own content

Posted by Davide Vecchi <dv...@amc.dk>.
Arg, sorry, it looks like 

Element.raw(String)

is what I'm looking for. I had missed it, I'm going to try it right now.


-----Original Message-----
From: Davide Vecchi 
Sent: Monday, July 21, 2014 11:42
To: 'Tapestry users'
Subject: RE: FW: Customizing the grid to alter its own content

In the example in my last post I'm handling a Node which is a Text: I'm creating a new Text node under the same parent and I'm setting the content of the new node.

Now I would like to do the same for a Node which is an Element instead of a Text, but I can't seem to see a way to set the content of an Element node.

F.ex. I have an Element which is

<div>my text content</div>

I create a new Element with same name and attributes, and the new element ends up being

<div></div>

but I don't know how to set the text content in it. Can it be done ?

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

Re: FW: Customizing the grid to alter its own content

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 10 Jul 2014 11:55:57 -0300, Davide Vecchi <dv...@amc.dk> wrote:

> As usual, thanks a lot for the great assistance, and in particular for  
> pointing me to DOM rewriting.
>
> List<Node> nodes = elementToModify.getChildren();
>
> if (nodes.size() == 1)
> {
> 	if (nodes.get(0) instanceof Text)
> 	{
> 		Text currentNode = (Text) nodes.get(0);
> 		
> 		Text newNode = elementToModify.text("pippo " + currentNode.toString());
> 		
> 		newNode.moveToTop(elementToModify);
> 		
> 		nodes = elementToModify.getChildren();
> 		
> 		nodes.get(1).remove();
> 	}
> }

I think the code is ok, even if it could have some improvements.

-- 
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: FW: Customizing the grid to alter its own content

Posted by Davide Vecchi <dv...@amc.dk>.
Right, in my case that Node is a Text. The following is what I'm doing in afterRender method; it seems to work just fine although I don't know if that's the recommended approach in DOM rewriting.

As usual, thanks a lot for the great assistance, and in particular for pointing me to DOM rewriting.

List<Node> nodes = elementToModify.getChildren();

if (nodes.size() == 1)
{
	if (nodes.get(0) instanceof Text)
	{
		Text currentNode = (Text) nodes.get(0);
		
		Text newNode = elementToModify.text("pippo " + currentNode.toString());
		
		newNode.moveToTop(elementToModify);
		
		nodes = elementToModify.getChildren();
		
		nodes.get(1).remove();
	}
}

Re: FW: Customizing the grid to alter its own content

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 10 Jul 2014 11:09:05 -0300, Davide Vecchi <dv...@amc.dk> wrote:


> If I do
>
> 	Node node = element.getChildren().get(0);
>
> I do get a org.apache.tapestry5.dom.Node representing the element's  
> content (its toString() just returns "Hello"), but even this Node object  
> doesn't seem to me to have methods to change its content.

Node is the abstract superclass of Element and Text, so you'll need to  
cast them before doing more useful stuff.

> Or maybe I should create a new Node instance containing the text I want  
> and then use this instance to replace the existing Node instance in the  
> children list, like
>
> 	element.getChildren().set(0, newNode);

That's an option too.

-- 
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: FW: Customizing the grid to alter its own content

Posted by Davide Vecchi <dv...@amc.dk>.
I'm trying to use DOM rewriting for the purpose of modifying the content of some grid cells. I modified GridCell class adding a

	void afterRender(MarkupWriter writer)

method, and in it I can retrieve the Element (org.apache.tapestry5.dom.Element) containing the value I want to modify. For ex. the toString() of one of these Element-s returns:

	<div id="cellId_xyz_123">Hello</div>

But I'm not sure how to change that "Hello" into something else. The Element class doesn't seem to me to have methods for that.

If I do

	Node node = element.getChildren().get(0);

I do get a org.apache.tapestry5.dom.Node representing the element's content (its toString() just returns "Hello"), but even this Node object doesn't seem to me to have methods to change its content.

Or maybe I should create a new Node instance containing the text I want and then use this instance to replace the existing Node instance in the children list, like

	element.getChildren().set(0, newNode);

?

Re: FW: Customizing the grid to alter its own content

Posted by Barry Books <tr...@gmail.com>.
I've done this by adding a mixin to GridCell with a worker. The mixin can
override the behavior of the component in various ways including dom
rewriting.

I would not override the display blocks because there are a lot of them and
a library could install more.


On Mon, Jul 7, 2014 at 9:14 AM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Mon, 07 Jul 2014 10:48:48 -0300, Davide Vecchi <dv...@amc.dk> wrote:
>
>  I forgot to answer your question
>>
>>  Another question: do you want to do this for
>>> every column, regardless of the type of its value (String, Date, boolean,
>>> etc) or not? If yes, then you may use Tapestry DOM rewriting.
>>>
>>
>> The answer is actually yes, so I will look into Tapestry DOM rewriting.
>>
>
> Actually, you can still override the display blocks for all types, but I'm
> not sure that's a good idea. You'd probably need to implement parts of what
> the out-of-the-box display blocks already do.
>
>
> --
> 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: FW: Customizing the grid to alter its own content

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Mon, 07 Jul 2014 10:48:48 -0300, Davide Vecchi <dv...@amc.dk> wrote:

> I forgot to answer your question
>
>> Another question: do you want to do this for
>> every column, regardless of the type of its value (String, Date,  
>> boolean,
>> etc) or not? If yes, then you may use Tapestry DOM rewriting.
>
> The answer is actually yes, so I will look into Tapestry DOM rewriting.

Actually, you can still override the display blocks for all types, but I'm  
not sure that's a good idea. You'd probably need to implement parts of  
what the out-of-the-box display blocks already do.

-- 
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


FW: Customizing the grid to alter its own content

Posted by Davide Vecchi <dv...@amc.dk>.
I forgot to answer your question

> Another question: do you want to do this for  
> every column, regardless of the type of its value (String, Date, boolean,  
> etc) or not? If yes, then you may use Tapestry DOM rewriting.

The answer is actually yes, so I will look into Tapestry DOM rewriting.

RE: Customizing the grid to alter its own content

Posted by Davide Vecchi <dv...@amc.dk>.
Hi, thanks a lot for the info, I don't need a tutorial and your example is a great start for me, actually I did not know about that possibility so it's really good that I asked here. I will post my results here, thanks again !

-----Original Message-----
From: Thiago H de Paula Figueiredo [mailto:thiagohp@gmail.com] 
Sent: Monday, July 7, 2014 15:35
To: Tapestry users
Subject: Re: Customizing the grid to alter its own content

On Mon, 07 Jul 2014 10:00:55 -0300, Davide Vecchi <dv...@amc.dk> wrote:

> Hi,

Hi!

> Thanks for the quick feedback ! Yes, I would like to make this change 
> so that it is used by every grid in my application.

So what you want is to override the property viewing blocks used by BeanModel-based components (in this case, Grid and BeanDisplay) for some Tapestry types (which are just strings, not having a class representing them. DataTypeConstants provides constants for the types Tapestry recognizes out-of-the-box). Another question: do you want to do this for every column, regardless of the type of its value (String, Date, boolean,
etc) or not? If yes, then you may use Tapestry DOM rewriting. If not, I'll sketch a solution for you, below.

I don't have time to make a tutorial right now, so I'll suggest you to take a look at PropertyDisplayBlocks (the Tapestry page that contains the blocks Grid and BeanDisplay use to render the columns in Grid),

Quick attempt, not tested, specifically for columns of type String, to explain what you need to do:

1) Create a MyPropertyDisplayBlocks (name doesn't matter much) page and its template.

2) This will be the template:

<t:container xml:space="default"  
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
     <t:block id="longtext">
         <!-- render here whatever you want -->
     </t:block>
</t:container>

3) In MyPropertyDisplayBlocks.java, you'll need this:

@Environmental
private PropertyOutputContext context; // this is the way you get the value to be rendered.

context.getPropertyValue() will provide you the value of the column.

4) Override the out-of-the-box configured block. In your AppModule, add
this:

public static void
contributeBeanBlockSource(Configuration<BeanBlockContribution>
configuration) {
   configuration.override(new
DisplayBlockContribution(DataTypeConstants.LONG_TEXT,
"MyPropertyDisplayBlocks", "longtext");
}

--
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: Customizing the grid to alter its own content

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Mon, 07 Jul 2014 10:00:55 -0300, Davide Vecchi <dv...@amc.dk> wrote:

> Hi,

Hi!

> Thanks for the quick feedback ! Yes, I would like to make this change so  
> that it is used by every grid in my application.

So what you want is to override the property viewing blocks used by  
BeanModel-based components (in this case, Grid and BeanDisplay) for some  
Tapestry types (which are just strings, not having a class representing  
them. DataTypeConstants provides constants for the types Tapestry  
recognizes out-of-the-box). Another question: do you want to do this for  
every column, regardless of the type of its value (String, Date, boolean,  
etc) or not? If yes, then you may use Tapestry DOM rewriting. If not, I'll  
sketch a solution for you, below.

I don't have time to make a tutorial right now, so I'll suggest you to  
take a look at PropertyDisplayBlocks (the Tapestry page that contains the  
blocks Grid and BeanDisplay use to render the columns in Grid),

Quick attempt, not tested, specifically for columns of type String, to  
explain what you need to do:

1) Create a MyPropertyDisplayBlocks (name doesn't matter much) page and  
its template.

2) This will be the template:

<t:container xml:space="default"  
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
     <t:block id="longtext">
         <!-- render here whatever you want -->
     </t:block>
</t:container>

3) In MyPropertyDisplayBlocks.java, you'll need this:

@Environmental
private PropertyOutputContext context; // this is the way you get the  
value to be rendered.

context.getPropertyValue() will provide you the value of the column.

4) Override the out-of-the-box configured block. In your AppModule, add  
this:

public static void  
contributeBeanBlockSource(Configuration<BeanBlockContribution>  
configuration) {
   configuration.override(new  
DisplayBlockContribution(DataTypeConstants.LONG_TEXT,  
"MyPropertyDisplayBlocks", "longtext");
}

-- 
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: Customizing the grid to alter its own content

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

Thanks for the quick feedback ! Yes, I would like to make this change so that it is used by every grid in my application.

Re: Customizing the grid to alter its own content

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Mon, 07 Jul 2014 09:38:47 -0300, Davide Vecchi <dv...@amc.dk> wrote:

> Hello everybody,

Hi!

> I would like to customize the Tapestry grid  
> (org.apache.tapestry5.corelib.components.Grid) to make it change the  
> content originally provided in the source parameter, so that the  
> modified content is rendered in the grid instead of the original.
>
> As an example, I could make the grid abbreviate certain strings in a  
> certain way for columns that contain text, so that the abbreviated text  
> is shown instead of the original. This should be independent from the  
> specific data source provided by the specific page that is using the  
> grid: any grid from any page should render its content as abbreviated.

Just do know before I give you an answer: do you want this done in the  
same way for every single Grid in your application? The best solution will  
change depending on that answer.

-- 
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: Customizing the grid to alter its own content

Posted by Lance Java <la...@googlemail.com>.
As you have discovered, Text is a Node and is not an Element.

Elements are
1. Wrapped in < and >
2. Can have attributes
3. Are containers for child elements
On 21 Jul 2014 13:33, "Davide Vecchi" <dv...@amc.dk> wrote:

> > Either Element.raw(...) or Element.text(...)
>
> Both give me the problems I explained.
> In a few words they don't create Element nodes but Raw and Text nodes.
>
> I'm not clear why I see all those Element instances containing text but I
> cannot create one myself (Raw and Text are not Element-s, just Node-s like
> Element itself) or why I cannot change that Element's text without , but
> I'll have to assume I just cannot, period, and I can certainly live with
> that.
>
> When I have an Element node with a child Element node, I will just turn
> that into an Element node with a child Text node instead; I think it will
> work just fine, I was just trying to clarify my understanding of Element.
>
>
>
> -----Original Message-----
> From: Lance Java [mailto:lance.java@googlemail.com]
> Sent: Monday, July 21, 2014 14:14
> To: Tapestry users
> Subject: RE: Customizing the grid to alter its own content
>
> Either Element.raw(...) or Element.text(...)  On 21 Jul 2014 13:09,
> "Davide Vecchi" <dv...@amc.dk> wrote:
>
> > Thanks, that looks like a really good way to use DOM rewriting to
> > alter grids.
> >
> > However if I'm looking at it correctly I think that in
> > GridCellDecorator.decorate I would still need to be able to set an
> > Element's text, which I don't know whether it's possible.
>

RE: Customizing the grid to alter its own content

Posted by Davide Vecchi <dv...@amc.dk>.
> Either Element.raw(...) or Element.text(...)  

Both give me the problems I explained.
In a few words they don't create Element nodes but Raw and Text nodes.

I'm not clear why I see all those Element instances containing text but I cannot create one myself (Raw and Text are not Element-s, just Node-s like Element itself) or why I cannot change that Element's text without , but I'll have to assume I just cannot, period, and I can certainly live with that.

When I have an Element node with a child Element node, I will just turn that into an Element node with a child Text node instead; I think it will work just fine, I was just trying to clarify my understanding of Element.



-----Original Message-----
From: Lance Java [mailto:lance.java@googlemail.com] 
Sent: Monday, July 21, 2014 14:14
To: Tapestry users
Subject: RE: Customizing the grid to alter its own content

Either Element.raw(...) or Element.text(...)  On 21 Jul 2014 13:09, "Davide Vecchi" <dv...@amc.dk> wrote:

> Thanks, that looks like a really good way to use DOM rewriting to 
> alter grids.
>
> However if I'm looking at it correctly I think that in 
> GridCellDecorator.decorate I would still need to be able to set an 
> Element's text, which I don't know whether it's possible.

RE: Customizing the grid to alter its own content

Posted by Lance Java <la...@googlemail.com>.
Either Element.raw(...) or Element.text(...)
 On 21 Jul 2014 13:09, "Davide Vecchi" <dv...@amc.dk> wrote:

> Thanks, that looks like a really good way to use DOM rewriting to alter
> grids.
>
> However if I'm looking at it correctly I think that in
> GridCellDecorator.decorate I would still need to be able to set an
> Element's text, which I don't know whether it's possible.
>
>
> -----Original Message-----
> From: Lance Java [mailto:lance.java@googlemail.com]
> Sent: Monday, July 21, 2014 13:52
> To: Tapestry users
> Subject: Re: Customizing the grid to alter its own content
>
> You might be interested in this mixin
>
>
> https://github.com/uklance/tapestry-stitch/blob/master/src/main/java/org/lazan/t5/stitch/mixins/GridDecorator.java
>
> Unfortunately the demo site is down at the moment.
>
> Sample usage:
>
> https://github.com/uklance/tapestry-stitch-demo/blob/master/src/main/resources/org/lazan/t5/stitch/demo/pages/GridDecoratorDemo.tml
>
>
> https://github.com/uklance/tapestry-stitch-demo/blob/master/src/main/java/org/lazan/t5/stitch/demo/pages/GridDecoratorDemo.java
>  On 7 Jul 2014 13:39, "Davide Vecchi" <dv...@amc.dk> wrote:
>
> > Hello everybody,
> >
> > I would like to customize the Tapestry grid
> > (org.apache.tapestry5.corelib.components.Grid) to make it change the
> > content originally provided in the source parameter, so that the
> > modified content is rendered in the grid instead of the original.
> >
> > As an example, I could make the grid abbreviate certain strings in a
> > certain way for columns that contain text, so that the abbreviated
> > text is shown instead of the original. This should be independent from
> > the specific data source provided by the specific page that is using
> > the grid: any grid from any page should render its content as
> abbreviated.
> >
> > I seem to see in the Grid code several options to try in order to
> > figure out how to implement this functionality, however before
> > starting making changes I'd like to know if there is a recommended,
> > Tapestry-friendly approach. And of course any related comment or
> suggestion is always welcome.
> >
> > Thanks in advance
> >
>

RE: Customizing the grid to alter its own content

Posted by Davide Vecchi <dv...@amc.dk>.
Thanks, that looks like a really good way to use DOM rewriting to alter grids.

However if I'm looking at it correctly I think that in GridCellDecorator.decorate I would still need to be able to set an Element's text, which I don't know whether it's possible.


-----Original Message-----
From: Lance Java [mailto:lance.java@googlemail.com] 
Sent: Monday, July 21, 2014 13:52
To: Tapestry users
Subject: Re: Customizing the grid to alter its own content

You might be interested in this mixin

https://github.com/uklance/tapestry-stitch/blob/master/src/main/java/org/lazan/t5/stitch/mixins/GridDecorator.java

Unfortunately the demo site is down at the moment.

Sample usage:
https://github.com/uklance/tapestry-stitch-demo/blob/master/src/main/resources/org/lazan/t5/stitch/demo/pages/GridDecoratorDemo.tml

https://github.com/uklance/tapestry-stitch-demo/blob/master/src/main/java/org/lazan/t5/stitch/demo/pages/GridDecoratorDemo.java
 On 7 Jul 2014 13:39, "Davide Vecchi" <dv...@amc.dk> wrote:

> Hello everybody,
>
> I would like to customize the Tapestry grid
> (org.apache.tapestry5.corelib.components.Grid) to make it change the 
> content originally provided in the source parameter, so that the 
> modified content is rendered in the grid instead of the original.
>
> As an example, I could make the grid abbreviate certain strings in a 
> certain way for columns that contain text, so that the abbreviated 
> text is shown instead of the original. This should be independent from 
> the specific data source provided by the specific page that is using 
> the grid: any grid from any page should render its content as abbreviated.
>
> I seem to see in the Grid code several options to try in order to 
> figure out how to implement this functionality, however before 
> starting making changes I'd like to know if there is a recommended, 
> Tapestry-friendly approach. And of course any related comment or suggestion is always welcome.
>
> Thanks in advance
>

Re: Customizing the grid to alter its own content

Posted by Lance Java <la...@googlemail.com>.
You might be interested in this mixin

https://github.com/uklance/tapestry-stitch/blob/master/src/main/java/org/lazan/t5/stitch/mixins/GridDecorator.java

Unfortunately the demo site is down at the moment.

Sample usage:
https://github.com/uklance/tapestry-stitch-demo/blob/master/src/main/resources/org/lazan/t5/stitch/demo/pages/GridDecoratorDemo.tml

https://github.com/uklance/tapestry-stitch-demo/blob/master/src/main/java/org/lazan/t5/stitch/demo/pages/GridDecoratorDemo.java
 On 7 Jul 2014 13:39, "Davide Vecchi" <dv...@amc.dk> wrote:

> Hello everybody,
>
> I would like to customize the Tapestry grid
> (org.apache.tapestry5.corelib.components.Grid) to make it change the
> content originally provided in the source parameter, so that the modified
> content is rendered in the grid instead of the original.
>
> As an example, I could make the grid abbreviate certain strings in a
> certain way for columns that contain text, so that the abbreviated text is
> shown instead of the original. This should be independent from the specific
> data source provided by the specific page that is using the grid: any grid
> from any page should render its content as abbreviated.
>
> I seem to see in the Grid code several options to try in order to figure
> out how to implement this functionality, however before starting making
> changes I'd like to know if there is a recommended, Tapestry-friendly
> approach. And of course any related comment or suggestion is always welcome.
>
> Thanks in advance
>