You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Mark <ma...@xeric.net> on 2011/07/07 06:25:39 UTC

Constructing a block in java

Is there a better way to construct a block from a string in Java than this?

    Block onShowDialogFromMoreInfo(TicketClass ticketClass) {
        return  new RenderableAsBlock(new StringRenderable(person.getInfo()));
    }

Mark

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


Re: Constructing a block in java

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Thu, 07 Jul 2011 14:15:46 -0300, Mark <ma...@xeric.net> wrote:

>  return new StringRenderable("<b>" + person.getName() + "</b>");

It should implement RenderCommand, not Renderable.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Constructing a block in java

Posted by Mark <ma...@xeric.net>.
On Thu, Jul 7, 2011 at 11:39 AM, Thiago H. de Paula Figueiredo
<th...@gmail.com> wrote:
>> I was thinking that there should be a way to do it with just a string,
>> but I guess that won't work because a string will try to send the
>> browser to a new page instead of just updating the part that needs to
>> be updated.
>
> Just implement a StringRenderCommand. :)


I tried:

 return new StringRenderable("<b>" + person.getName() + "</b>");

But it gives me an error saying:

Ajax failure: Status 500 for
http://localhost:8080/register/register.moreinfo:showdialog/2?t:ac=1:
A component event handler method returned the value Renderable[<b>$50
Ticket</b>]. Return type
org.apache.tapestry5.internal.util.StringRenderable can not be
handled.

Mark

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


Re: Constructing a block in java

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Thu, 07 Jul 2011 15:02:05 -0300, Mark <ma...@xeric.net> wrote:

>> Just implement a StringRenderCommand. :)
>
> Perhaps I misunderstood.  I can't seem to find an interface or class
> called a StringRenderCommand in the JavaDocs anywhere.  Am I looking
> in the wrong place?

I'm suggesting you to write one. ;)

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Constructing a block in java

Posted by Mark <ma...@xeric.net>.
>
>> I was thinking that there should be a way to do it with just a string,
>> but I guess that won't work because a string will try to send the
>> browser to a new page instead of just updating the part that needs to
>> be updated.
>
> Just implement a StringRenderCommand. :)


Perhaps I misunderstood.  I can't seem to find an interface or class
called a StringRenderCommand in the JavaDocs anywhere.  Am I looking
in the wrong place?

Mark

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


Re: Constructing a block in java

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Thu, 07 Jul 2011 13:35:47 -0300, Mark <ma...@xeric.net> wrote:

> Ah ok.  So something along the lines of this?
>
>     Object onShowDialogFromMoreInfo(final Person person) {
>         return new RenderCommand()
>         {
>             public void render(MarkupWriter writer, RenderQueue queue)
>             {
>                 writer.writeRaw("<b>" + person.getName() + "</b>");
>             }
>         };
>     }

Yep!

> I was thinking that there should be a way to do it with just a string,
> but I guess that won't work because a string will try to send the
> browser to a new page instead of just updating the part that needs to
> be updated.

Just implement a StringRenderCommand. :)

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Constructing a block in java

Posted by Josh Canfield <jo...@gmail.com>.
Ah, sorry. I didn't read closely what you were trying to do. For ajax
response you need a RenderCommand, as Thiago said...

On Thu, Jul 7, 2011 at 10:02 AM, Mark <ma...@xeric.net> wrote:
> Josh,
>
> Thats what I thought originally.  This is for a ModalDialog using
> Taha's addon.  When someone clicks "more info" it pops up with a modal
> dialog box and the contents are determined by this method.  If I
> return a String, Tapestry tries to find a page that matches the String
> and return that instead of just rendering it in the modal dialog box.
>
> Mark
>
>
>
> On Thu, Jul 7, 2011 at 11:43 AM, Josh Canfield <jo...@gmail.com> wrote:
>> Have you tried returning a String? There is a built-in TypeCoercer for
>> String -> Renderable
>>
>> This is implemented using StringRenderable which uses write(text) (not
>> writeRaw) so your html will be escaped.
>>
>> Josh
>>
>> On Thu, Jul 7, 2011 at 9:35 AM, Mark <ma...@xeric.net> wrote:
>>> On Thu, Jul 7, 2011 at 6:34 AM, Thiago H. de Paula Figueiredo
>>> <th...@gmail.com> wrote:
>>>> On Thu, 07 Jul 2011 01:25:39 -0300, Mark <ma...@xeric.net> wrote:
>>>>
>>>>> Is there a better way to construct a block from a string in Java than
>>>>> this?
>>>>>
>>>>>    Block onShowDialogFromMoreInfo(TicketClass ticketClass) {
>>>>>        return  new RenderableAsBlock(new
>>>>> StringRenderable(person.getInfo()));
>>>>>    }
>>>>
>>>> Do you really need it to be a block? To pass it to Delegate? It doesn't need
>>>> to be a block. It can also be a component or any object that implements
>>>> RenderCommand. Why don't you just return a RenderCommand instance? Tapestry
>>>> ultimately renders only RenderCommand's. Anything else which can be rendered
>>>> implements RenderCommand (including BlockImpl) or converted to an instance
>>>> of it.
>>>
>>> Ah ok.  So something along the lines of this?
>>>
>>>    Object onShowDialogFromMoreInfo(final Person person) {
>>>        return new RenderCommand()
>>>        {
>>>            public void render(MarkupWriter writer, RenderQueue queue)
>>>            {
>>>                writer.writeRaw("<b>" + person.getName() + "</b>");
>>>            }
>>>        };
>>>    }
>>>
>>> I was thinking that there should be a way to do it with just a string,
>>> but I guess that won't work because a string will try to send the
>>> browser to a new page instead of just updating the part that needs to
>>> be updated.
>>>
>>> Mark
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

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


Re: Constructing a block in java

Posted by Mark <ma...@xeric.net>.
Josh,

Thats what I thought originally.  This is for a ModalDialog using
Taha's addon.  When someone clicks "more info" it pops up with a modal
dialog box and the contents are determined by this method.  If I
return a String, Tapestry tries to find a page that matches the String
and return that instead of just rendering it in the modal dialog box.

Mark



On Thu, Jul 7, 2011 at 11:43 AM, Josh Canfield <jo...@gmail.com> wrote:
> Have you tried returning a String? There is a built-in TypeCoercer for
> String -> Renderable
>
> This is implemented using StringRenderable which uses write(text) (not
> writeRaw) so your html will be escaped.
>
> Josh
>
> On Thu, Jul 7, 2011 at 9:35 AM, Mark <ma...@xeric.net> wrote:
>> On Thu, Jul 7, 2011 at 6:34 AM, Thiago H. de Paula Figueiredo
>> <th...@gmail.com> wrote:
>>> On Thu, 07 Jul 2011 01:25:39 -0300, Mark <ma...@xeric.net> wrote:
>>>
>>>> Is there a better way to construct a block from a string in Java than
>>>> this?
>>>>
>>>>    Block onShowDialogFromMoreInfo(TicketClass ticketClass) {
>>>>        return  new RenderableAsBlock(new
>>>> StringRenderable(person.getInfo()));
>>>>    }
>>>
>>> Do you really need it to be a block? To pass it to Delegate? It doesn't need
>>> to be a block. It can also be a component or any object that implements
>>> RenderCommand. Why don't you just return a RenderCommand instance? Tapestry
>>> ultimately renders only RenderCommand's. Anything else which can be rendered
>>> implements RenderCommand (including BlockImpl) or converted to an instance
>>> of it.
>>
>> Ah ok.  So something along the lines of this?
>>
>>    Object onShowDialogFromMoreInfo(final Person person) {
>>        return new RenderCommand()
>>        {
>>            public void render(MarkupWriter writer, RenderQueue queue)
>>            {
>>                writer.writeRaw("<b>" + person.getName() + "</b>");
>>            }
>>        };
>>    }
>>
>> I was thinking that there should be a way to do it with just a string,
>> but I guess that won't work because a string will try to send the
>> browser to a new page instead of just updating the part that needs to
>> be updated.
>>
>> Mark
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

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


Re: Constructing a block in java

Posted by Josh Canfield <jo...@gmail.com>.
Have you tried returning a String? There is a built-in TypeCoercer for
String -> Renderable

This is implemented using StringRenderable which uses write(text) (not
writeRaw) so your html will be escaped.

Josh

On Thu, Jul 7, 2011 at 9:35 AM, Mark <ma...@xeric.net> wrote:
> On Thu, Jul 7, 2011 at 6:34 AM, Thiago H. de Paula Figueiredo
> <th...@gmail.com> wrote:
>> On Thu, 07 Jul 2011 01:25:39 -0300, Mark <ma...@xeric.net> wrote:
>>
>>> Is there a better way to construct a block from a string in Java than
>>> this?
>>>
>>>    Block onShowDialogFromMoreInfo(TicketClass ticketClass) {
>>>        return  new RenderableAsBlock(new
>>> StringRenderable(person.getInfo()));
>>>    }
>>
>> Do you really need it to be a block? To pass it to Delegate? It doesn't need
>> to be a block. It can also be a component or any object that implements
>> RenderCommand. Why don't you just return a RenderCommand instance? Tapestry
>> ultimately renders only RenderCommand's. Anything else which can be rendered
>> implements RenderCommand (including BlockImpl) or converted to an instance
>> of it.
>
> Ah ok.  So something along the lines of this?
>
>    Object onShowDialogFromMoreInfo(final Person person) {
>        return new RenderCommand()
>        {
>            public void render(MarkupWriter writer, RenderQueue queue)
>            {
>                writer.writeRaw("<b>" + person.getName() + "</b>");
>            }
>        };
>    }
>
> I was thinking that there should be a way to do it with just a string,
> but I guess that won't work because a string will try to send the
> browser to a new page instead of just updating the part that needs to
> be updated.
>
> Mark
>
> ---------------------------------------------------------------------
> 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: Constructing a block in java

Posted by Mark <ma...@xeric.net>.
On Thu, Jul 7, 2011 at 6:34 AM, Thiago H. de Paula Figueiredo
<th...@gmail.com> wrote:
> On Thu, 07 Jul 2011 01:25:39 -0300, Mark <ma...@xeric.net> wrote:
>
>> Is there a better way to construct a block from a string in Java than
>> this?
>>
>>    Block onShowDialogFromMoreInfo(TicketClass ticketClass) {
>>        return  new RenderableAsBlock(new
>> StringRenderable(person.getInfo()));
>>    }
>
> Do you really need it to be a block? To pass it to Delegate? It doesn't need
> to be a block. It can also be a component or any object that implements
> RenderCommand. Why don't you just return a RenderCommand instance? Tapestry
> ultimately renders only RenderCommand's. Anything else which can be rendered
> implements RenderCommand (including BlockImpl) or converted to an instance
> of it.

Ah ok.  So something along the lines of this?

    Object onShowDialogFromMoreInfo(final Person person) {
        return new RenderCommand()
        {
            public void render(MarkupWriter writer, RenderQueue queue)
            {
                writer.writeRaw("<b>" + person.getName() + "</b>");
            }
        };
    }

I was thinking that there should be a way to do it with just a string,
but I guess that won't work because a string will try to send the
browser to a new page instead of just updating the part that needs to
be updated.

Mark

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


Re: Constructing a block in java

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Thu, 07 Jul 2011 01:25:39 -0300, Mark <ma...@xeric.net> wrote:

> Is there a better way to construct a block from a string in Java than  
> this?
>
>     Block onShowDialogFromMoreInfo(TicketClass ticketClass) {
>         return  new RenderableAsBlock(new  
> StringRenderable(person.getInfo()));
>     }

Do you really need it to be a block? To pass it to Delegate? It doesn't  
need to be a block. It can also be a component or any object that  
implements RenderCommand. Why don't you just return a RenderCommand  
instance? Tapestry ultimately renders only RenderCommand's. Anything else  
which can be rendered implements RenderCommand (including BlockImpl) or  
converted to an instance of it.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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