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

2014-07-21 Thread Davide Vecchi
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

my text content

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



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:thiag...@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  wrote:

> As usual, thanks a lot for the great assistance, and in particular for 
> pointing me to DOM rewriting.
>
> List 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-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



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

2014-07-10 Thread Thiago H de Paula Figueiredo

On Thu, 10 Jul 2014 11:55:57 -0300, Davide Vecchi  wrote:

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


List 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-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



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

2014-07-10 Thread Davide Vecchi
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 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

2014-07-10 Thread Thiago H de Paula Figueiredo

On Thu, 10 Jul 2014 11:09:05 -0300, Davide Vecchi  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-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



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

2014-07-10 Thread Davide Vecchi
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:

Hello

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

2014-07-07 Thread Barry Books
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 <
thiag...@gmail.com> wrote:

> On Mon, 07 Jul 2014 10:48:48 -0300, Davide Vecchi  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-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>


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

2014-07-07 Thread Thiago H de Paula Figueiredo

On Mon, 07 Jul 2014 10:48:48 -0300, Davide Vecchi  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-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org