You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Angelo Chen <an...@yahoo.com.hk> on 2007/10/02 18:22:06 UTC

T5: using servlet

Hi,
I have a servlet used with my T5 app, its job is to return an image from
file system, the url-pattern is:
 <url-pattern>/av</url-pattern>
in the template I have to refer it as:
< img src="http://localhost:8080/av?fid=mypic.jpg" / >
this works, but if I deploy it, i have to update the server name, if I just
use "/av?fid=mypic.jpg", it will not work as it might be appended to other
URLs. any idea how to take care of this? Thanks,
A.C.
-- 
View this message in context: http://www.nabble.com/T5%3A-using-servlet-tf4555798.html#a13001997
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5: using servlet

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Howard,

Thanks, it works, here is my code, one problem is, 

 <t:MyImg path="literal:123456.jpg" />

generates following code without the closing tag, any way to fix this?

< img src="/av?fid=123456.jpg">


public class MyImg {
    @Inject
    @Service("RequestGlobals")
    private RequestGlobals requestGlobals;

    @Parameter(required=true)
    private String _path;

    boolean beginRender(MarkupWriter writer)
    {
        String fullPath = requestGlobals.getRequest().getContextPath() +
"/av?fid=";
        writer.element("img", "src", fullPath + _path);
        writer.end();
        return false; // don't render body
    }
}



Howard Lewis Ship wrote:
> 
> You could write a simple component that dynamically generates the   tag,
> including the URL.  You would inject the Request object, in order to get
> the
> context path.  Something like:
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-using-servlet-tf4555798.html#a13012221
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5: using servlet

Posted by Howard Lewis Ship <hl...@gmail.com>.
Since it starts with a leading slash, it will always be
http://localhost:8080/av.

That assumes your app is deployed as the root web application.

The only time it would break is if your app was not deployed as the root web
application, as might happen if your servlet container is deploying multiple
JARs.

At that point, the URI of your servlet becomes /context/av.

You could write a simple component that dynamically generates the <img> tag,
including the URL.  You would inject the Request object, in order to get the
context path.  Something like:

public class MyImage {
  @Inject
  private Request _request;

  @Parameter(required=true)
  private String _path;

  boolean beginRender(MarkupWriter writer)
  {
     String fullPath = _request.getContextPath() + "/av";

     writer.element("img", "src", fullPath).end();


     return false; // don't render body
  }
}


Usage:

<t:myimage path="literal:mypic.jpg"/>

.... that's from memory and some of the details are probably broken, but
that the gist of it.  Creating components is your primary problem solving
technique in Tapestry, and T5 makes it even easier to create components.

On 10/2/07, Angelo Chen <an...@yahoo.com.hk> wrote:
>
>
> Hi,
> I have a servlet used with my T5 app, its job is to return an image from
> file system, the url-pattern is:
> <url-pattern>/av</url-pattern>
> in the template I have to refer it as:
> < img src="http://localhost:8080/av?fid=mypic.jpg" / >
> this works, but if I deploy it, i have to update the server name, if I
> just
> use "/av?fid=mypic.jpg", it will not work as it might be appended to other
> URLs. any idea how to take care of this? Thanks,
> A.C.
> --
> View this message in context:
> http://www.nabble.com/T5%3A-using-servlet-tf4555798.html#a13001997
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Howard M. Lewis Ship
Partner and Senior Architect at Feature50

Creator Apache Tapestry and Apache HiveMind