Ok, found it :)

I made a simple test:

public class image {

    @Parameter(defaultPrefix = "context")
    private Asset url; // <-- Note that it's an Asset, which is what
the Context binding returns.

    void beginRender(MarkupWriter writer) {
        writer.element("img", "src", url);
        writer.end();
    }
}

<t:image url="/layout/images/img01.jpg"/>

This works fine.

When you try to do this:
<t:image url="/layout/images/${'img01.jpg'}"/>

It fails, because this is no longer using the Context binding, it
becomes an AttributeExpansionBinding and thus you get a String. In my
test case I get an exception because there is no coercion from a
String to an Asset. I can't see a way to work around that...

I assume that you want to the asset url
(/assets/1.0-SNAPSHOT/ctx/layout/images/img01.jpg) so here's code that
treats the parameter as a string and grabs the asset url. Of course if
anything is wrong in your database this will result in a
RuntimeException "unable to locate asset"

    @Parameter(defaultPrefix = "literal")
    private String url;

    @Inject
    private AssetSource source;


    void beginRender(MarkupWriter writer) {
        Asset asset = source.getContextAsset(url, Locale.getDefault());

        writer.element("img", "src", asset);
        writer.end();
    }

You may want to just access the file directly. That should work if you
have the path correct since things in webapp are supposed to be
addressable by the url. If you were deploying to the root context you
probably never would have noticed a problem!

Josh

On Wed, Dec 15, 2010 at 2:18 PM, Rich M <rich...@moremagic.com> wrote:
> Resending, I think my local links to the files somehow resolved in there...
>
> On 12/15/2010 05:16 PM, Rich M wrote:
>>
>> Sure,
>>
>> working:
>>
>> <div  class="contentBubble">
>> <div  class="contentImg">
>> [img  src="/app/assets/ctx/1.0/layout/images/products/filename.png "/]
>> </div>
>> <h2> <font  color='green'>  $5 - 250 MP</font></h2>
>> <p>  $5 USD!<br  /><br  />
>> <a  href="index.pagelinker/RedeemTab?t:ac=5 ">  Redeem</a></p>
>> </div>
>>
>> not-working:
>>
>>
>> <div  class="contentBubble first">
>> <div  class="contentImg">
>> [img  src="/layout/images/products/filename.jpg "/]
>> </div>
>> <h2> <font  color='red'>$6 - 300 MP</font></h2>
>> <p>  $6 USD!<br  /><br  />
>> <strong  class="earn">Earn more MP to buy this product!</strong></p>
>> </div>
>>
>>
>> I certainly agree the src attribute doesn't come out right between the
>> two. What your asking for here is probably the best demonstration of what
>> I've been trying to get at so far.
>>
>> I can go even further and say that these same src attributes are already
>> set to those strings in the component. That debug code I have that reads the
>> imgRef is the same as the working and non-working src attributes
>> respectively.
>>
>> What seems to be happening, is that when the call to <t:ContentBubble> is
>> made in the Page TML, the BindingConstants.CONTEXT parameter is not able to
>> resolve "/layout/images/products/${prod.imageLink}" properly into the
>> context path, while it can resolve "/layout/images/products/filename.png".
>> I'm not completely understanding why, buy all evidence suggests as much to
>> me.
>>
>> -Rich
>>
>> On 12/15/2010 05:06 PM, Josh Canfield wrote:
>>>
>>> Can you provide the HTML that is rendered for the image tag using
>>> under the working and non-working scenarios? The only thing that makes
>>> sense to me is that you are not generating the same src attribute
>>> using the two methods.
>>>
>>> On Wed, Dec 15, 2010 at 1:57 PM, Rich M<rich...@moremagic.com>  wrote:
>>>>
>>>> On 12/15/2010 03:29 PM, Thiago H. de Paula Figueiredo wrote:
>>>>>
>>>>> On Wed, 15 Dec 2010 18:25:44 -0200, Rich M<rich...@moremagic.com>
>>>>>  wrote:
>>>>>
>>>>>> That doesn't quite solve it though, how do I get it to know
>>>>>> "yourpicture.jpg"? That's a dynamic String within the system that
>>>>>> changes
>>>>>> throughout the loop. The images themselves are static, but the
>>>>>> filename
>>>>>> string is not.
>>>>>
>>>>> <img src="/yourimagesfolder/${picture}"/>
>>>>>
>>>>> public String getPicture() {
>>>>>    ....
>>>>> }
>>>>>
>>>> Right, that was what I started out trying by several means before, as I
>>>> mentioned in previous e-mails, but I can't get it to resolve correctly.
>>>>
>>>> example:
>>>>
>>>>    xxx.xxx.xx.xx -  -  [15/Dec/2010:21:43:44 +0000] "GET
>>>> /layout/images/products/filename.png        HTTP/1.1" 404 1330
>>>> "http://localhost/app/customer/Overview"; "Mozilla/5.0 Firefox/3.6.12"
>>>>
>>>>
>>>> Comes out as a 404 even though the image certainly exists.
>>>>
>>>> Maybe the code will help? I included both what works and doesn't work.
>>>> In
>>>> the Page TML the first<t:ContentBubble>  is the one that works, using
>>>> hardcoded file name. Meanwhile the second instance does not work, even
>>>> though ${prod.imageLink} resolves to the same exact String as the
>>>> hardcoded
>>>> file name.
>>>>
>>>> Page TML:
>>>>
>>>> <html
>>>>
>>>>      xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";
>>>>
>>>>      xmlns:p="tapestry:parameter">
>>>>
>>>>
>>>> <t:loop source="products" value="prod">
>>>>
>>>>        ${checkIfUseable(prod)}
>>>>
>>>>
>>>> <t:if test="useable">
>>>>
>>>> <t:ContentBubble
>>>>
>>>>            first="${first}"
>>>>
>>>>            title="${startGood} ${prod.name} - ${prod.pointPrice} MP
>>>> ${end}"
>>>>
>>>>            text="${prod.freetext}"
>>>>
>>>>            imgRef="/layout/images/products/topupfnf-android.png"
>>>>
>>>>            linkText="${message:redeem-link}"
>>>>
>>>>            linkRef="index.pagelinker/RedeemTab?t:ac=5"
>>>>
>>>>            displayLink="true"
>>>>
>>>>            />
>>>>
>>>>
>>>> <p:else>
>>>>
>>>> <t:ContentBubble
>>>>
>>>>            first="${first}"
>>>>
>>>>            title="${startBad} ${prod.name} - ${prod.pointPrice} MP
>>>> ${end}"
>>>>
>>>>            text="${prod.freetext}"
>>>>
>>>>            imgRef="/layout/images/products/${prod.imageLink}"
>>>>
>>>>            linkText="${message:earn-points}"
>>>>
>>>>            linkRef="./"
>>>>
>>>>            />
>>>>
>>>> </p:else>
>>>>
>>>> </t:if>
>>>>
>>>>
>>>> </t:loop>
>>>>
>>>>
>>>> </html>
>>>>
>>>> Component Code:
>>>>
>>>> public class ContentBubble {
>>>>
>>>>   �...@inject
>>>>
>>>>    private Logger log;
>>>>
>>>>
>>>>   �...@property
>>>>
>>>>   �...@parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
>>>>
>>>>    private String title;
>>>>
>>>>
>>>>   �...@property
>>>>
>>>>   �...@parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
>>>>
>>>>    private String text;
>>>>
>>>>
>>>>   �...@property
>>>>
>>>>   �...@parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
>>>>
>>>>    private String linkRef;
>>>>
>>>>
>>>>   �...@property
>>>>
>>>>   �...@parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
>>>>
>>>>    private String linkText;
>>>>
>>>>
>>>>   �...@property
>>>>
>>>>   �...@parameter(required = true, defaultPrefix = BindingConstants.CONTEXT)
>>>>
>>>>    private String imgRef;
>>>>
>>>>   �...@property
>>>>
>>>>   �...@parameter(defaultPrefix = BindingConstants.LITERAL)
>>>>
>>>>    private Boolean first;
>>>>
>>>>
>>>>   �...@property
>>>>
>>>>   �...@parameter(defaultPrefix = BindingConstants.LITERAL)
>>>>
>>>>    private Boolean newWindow;
>>>>
>>>>
>>>>   �...@property
>>>>
>>>>   �...@parameter(defaultPrefix = BindingConstants.LITERAL)
>>>>
>>>>    private Boolean displayLink;
>>>>
>>>>
>>>>   �...@beginrender
>>>>
>>>>    public void renderPage(MarkupWriter writer) {
>>>>
>>>>        log.debug("Rendering ContentBubble with: " + "\n" +
>>>>
>>>>                "title: " + title + "\n" +
>>>>
>>>>                "text: " + text + "\n" +
>>>>
>>>>                "linkRef: " + linkRef + "\n" +
>>>>
>>>>                "linkText: " + linkText + "\n" +
>>>>
>>>>                "imgRef: " + imgRef + "\n" +
>>>>
>>>>                "first: " + first + "\n" +
>>>>
>>>>                "newWindow: " + newWindow + "\n" +
>>>>
>>>>                "displayLink: " + displayLink + "\n");
>>>>
>>>>
>>>>
>>>>        if(first){
>>>>
>>>>            writer.writeRaw("<div class=\"contentBubble first\"> <div
>>>> class=\"contentImg\"> <img src=\""+imgRef+"\" /> </div>");
>>>>
>>>>            writer.writeRaw("<h2>    " + title +"</h2>");
>>>>
>>>>            writer.writeRaw("<p>    " + text +"<br /><br />");
>>>>
>>>>
>>>>            if(displayLink != null&&    displayLink){
>>>>
>>>>                if(newWindow != null&&    newWindow)
>>>>
>>>>                    writer.writeRaw("<a href=\""+linkRef+"\"
>>>> target=\"_blank\">    " + linkText +"</a>");
>>>>
>>>>                else
>>>>
>>>>                    writer.writeRaw("<a href=\""+linkRef+"\">    " +
>>>> linkText
>>>> +"</a>");
>>>>
>>>>            }else{
>>>>
>>>>                writer.writeRaw("<strong
>>>> class=\"earn\">"+linkText+"</strong>");
>>>>
>>>>            }
>>>>
>>>>
>>>>            writer.writeRaw("</p></div>");
>>>>
>>>>        }else{
>>>>
>>>>            writer.writeRaw("<div class=\"contentBubble \"> <div
>>>> class=\"contentImg\"> <img src=\""+imgRef+"\" /> </div>");
>>>>
>>>>            writer.writeRaw("<h2>    " + title +"</h2>");
>>>>
>>>>            writer.writeRaw("<p>    " + text +"<br /><br />");
>>>>
>>>>
>>>>            if(displayLink != null&&    displayLink){
>>>>
>>>>                if(newWindow != null&&    newWindow)
>>>>
>>>>                    writer.writeRaw("<a href=\""+linkRef+"\"
>>>> target=\"_blank\">    " + linkText +"</a>");
>>>>
>>>>                else
>>>>
>>>>                    writer.writeRaw("<a href=\""+linkRef+"\">    " +
>>>> linkText
>>>> +"</a>");
>>>>
>>>>            }else{
>>>>
>>>>                writer.writeRaw("<strong
>>>> class=\"earn\">"+linkText+"</strong>");
>>>>
>>>>            }
>>>>
>>>>
>>>>            writer.writeRaw("</p></div>");
>>>>
>>>>        }
>>>>
>>>>    }
>>>>
>>>> }
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>>>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
>>> For additional commands, e-mail: users-h...@tapestry.apache.org
>>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

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

Reply via email to