You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Damon <mi...@gmail.com> on 2015/11/13 01:29:45 UTC

call a function in html with parameter

Hello,

Im trying to call a function from my html file.

<div t:type="Loop" t:source="propertyImages" t:value="propertyImage" class="medium-7 medium-centered columns">
    <img src="${getExternalImageLink(propertyImage.imgId)}" />
    <br/>Prop Descr: ${propertyImage.description} <br/>
</div>

it calls::

public Link getExternalImageLink(String imgId) {
    
        return resources.createEventLink("externalImage", imgId);
    }

public ImageStreamResponse onExternalImage(final String imgid)
{

}

when the function is called all i get is a null value passed into it.  How do i pass the variable to the function?  I have searched net / list and I’m unable to find a solution.


Thanks!


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


Re: call a function in html with parameter

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 12 Nov 2015 22:29:45 -0200, Damon <mi...@gmail.com> wrote:

> Hello,

Hi!

>
> Im trying to call a function from my html file.
>
> <div t:type="Loop" t:source="propertyImages" t:value="propertyImage"  
> class="medium-7 medium-centered columns">
>     <img src="${getExternalImageLink(propertyImage.imgId)}" />
>     <br/>Prop Descr: ${propertyImage.description} <br/>
> </div>
>
> it calls::
>
> public Link getExternalImageLink(String imgId) {
>        return resources.createEventLink("externalImage", imgId);
>     }
>
> public ImageStreamResponse onExternalImage(final String imgid)
> {
>
> }
>
> when the function is called all i get is a null value passed into it.

This means getPropertyImage().getImgId() is returning null. Your syntax is  
correct (getExternalImageLink(propertyImage.imgId)).

I'm not sure why you're using createEventLink() for generating asset URLs,  
by the way. In addition, its handler is returning a StreamResponse to the  
src attribute of <img>, which won't work unless you're returning a data:  
URL, which is definitely not the case here.

-- 
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: call a function in html with parameter

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Fri, 13 Nov 2015 11:00:11 -0200, Bob Harner <bo...@gmail.com> wrote:

> Maybe something like this would work:
>
> <img src="${getExternalImageLink(${propertyImage.imgId})}" />

The inner ${} isn't needed (and I'm not even sure it would work).  
getExternalImageLink(propertyImage.imgId) should work.

> But the right answer is: don't. Instead, create a getter in your  
> component
> class that returns the desired value:
>
> <img src="${imageLink)}" />

There's type there: an extra closing parenthesis. <img src="${imageLink}"  
/>
> ...
> public String getImageLink() {
>     return getExternalImageLink(propertyImage.getImgId());
> }
>
> Keep all complexity in Java, not your template.

Agreed. I cannot recommend this enough.

-- 
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: call a function in html with parameter

Posted by Bob Harner <bo...@gmail.com>.
Maybe something like this would work:

<img src="${getExternalImageLink(${propertyImage.imgId})}" />

But the right answer is: don't. Instead, create a getter in your component
class that returns the desired value:

<img src="${imageLink)}" />
...
public String getImageLink() {
    return getExternalImageLink(propertyImage.getImgId());
}

Keep all complexity in Java, not your template.
On Nov 12, 2015 9:46 PM, "Ido Dovrat" <id...@gmail.com> wrote:

> Try to remove the "t:" prefix from your source and value attributes (leave
> it in only for the type attribute).
>
> On Fri, Nov 13, 2015 at 2:29 AM, Damon <mi...@gmail.com> wrote:
>
> > Hello,
> >
> > Im trying to call a function from my html file.
> >
> > <div t:type="Loop" t:source="propertyImages" t:value="propertyImage"
> > class="medium-7 medium-centered columns">
> >     <img src="${getExternalImageLink(propertyImage.imgId)}" />
> >     <br/>Prop Descr: ${propertyImage.description} <br/>
> > </div>
> >
> > it calls::
> >
> > public Link getExternalImageLink(String imgId) {
> >
> >         return resources.createEventLink("externalImage", imgId);
> >     }
> >
> > public ImageStreamResponse onExternalImage(final String imgid)
> > {
> >
> > }
> >
> > when the function is called all i get is a null value passed into it.
> How
> > do i pass the variable to the function?  I have searched net / list and
> I’m
> > unable to find a solution.
> >
> >
> > Thanks!
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>

Re: call a function in html with parameter

Posted by Ido Dovrat <id...@gmail.com>.
Try to remove the "t:" prefix from your source and value attributes (leave
it in only for the type attribute).

On Fri, Nov 13, 2015 at 2:29 AM, Damon <mi...@gmail.com> wrote:

> Hello,
>
> Im trying to call a function from my html file.
>
> <div t:type="Loop" t:source="propertyImages" t:value="propertyImage"
> class="medium-7 medium-centered columns">
>     <img src="${getExternalImageLink(propertyImage.imgId)}" />
>     <br/>Prop Descr: ${propertyImage.description} <br/>
> </div>
>
> it calls::
>
> public Link getExternalImageLink(String imgId) {
>
>         return resources.createEventLink("externalImage", imgId);
>     }
>
> public ImageStreamResponse onExternalImage(final String imgid)
> {
>
> }
>
> when the function is called all i get is a null value passed into it.  How
> do i pass the variable to the function?  I have searched net / list and I’m
> unable to find a solution.
>
>
> Thanks!
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>