Menu

Customizing paging

Help
2005-07-05
2012-10-08
  • Martin Kuhn

    Martin Kuhn - 2005-07-05

    I know I can customize the paging output via displaytag.properties file.

    My question: I want to have images for navigation actions in the paging area. Is it possible to put application relative image references in the property file (like <img src="/img/first.gif" border="0"> instead of <img src="/WebappName/img/neu.gif" border="0">)

    Please help me.

    TIA
    Martin

     
    • Rick Herrick

      Rick Herrick - 2005-07-05

      Quick answer: no.

      A bit longer: the <img src> tag isn't evaluated until it hits the browser. That means that the entire path through the server, including the app name, has to be there or it won't resolve properly.

      Using an <html:image> tag or something similar that would resolve the application context properly won't work because you can't embed a tag inside a tag. Your displaytags are evaluated and generate the HTML for the table. If that HTML contains further tags, when would they be evaluated?

      One possible resolution to your issue, though, is to specify the application context dynamically in your code and use some kind of pass-through to get the server name from the servlet context (or don't use a pass-through and get it directly from the server context!). For example:

      <%
      String appContext = config.getServletName();
      %>

      <img src="/<%= appContext %>/path/to/image.jpg"/>

      I believe that config.getServletName() is what you want, but I'm not sure, haven't messed with that in a while. But give that a try, it should work. The parsing of JSP tags happens before the compilation of the JSP into Java, so the displaytag stuff should be generated before the Java compilation.

       
    • Christopher K Koenigsberg

      Dynamically determing the context root, for URL construction, can be tricky, we have found, inside a web application. e.g. for "http://myserver/myapp/foo" you want to dynamically make server root relative URL's like "/myapp/foo1", where the "myapp" is dynamically determined.

      There are the Struts tools to do it, which have migrated, between Struts version 1.1 and more recent versions (apparently due to fuller integration of "modules"). But to use these, you need to pass in a Struts ActionMapping.

      Then there is ServletContext.getServletContextName(), which you can get to as long as you have an HttpSession or Request. But this "servlet context name" is not necessarily the same as the "context root", in the URL's for the deployed web application on the server!

      We have found, at least in Websphere Application Server (developing and testing in Websphere Studio Application Developer/Rational Application Developer) that the "ServletContext.getServletContextName()" will return the value set in the web.xml for the "display-name" element.

      IF you are careful to always set the web.xml "display-name" the same as the context root, then (at least in Websphere), ServletContext.getServletContextName()" WILL return the value you want, and you can use that, to construct your server-relative URL.

      We've recently started adding a Struts PlugIn (implementing their PlugIn interface, specifying plugin in the struts-config.xml) which, when its "init" is called by the Struts ActionServlet, will get the ServletContext.getServletContextName, use it to determine the context root, and then save that in a static variable, providing a "getUrlRoot()" static method that we can use from that point on, anywhere in our web app.

      But like I said, we have had problems where someone changed the context root, but not the "display-name", or vice versa, and then our "getUrlRoot()" no longer returns the right string for the server root-relative URL root.

      We even use the getUrlRoot for jsp's to dynamically build CSS links, or javascript src links, etc.

       
      • Martin Kuhn

        Martin Kuhn - 2005-07-06

        The html-code for custom paging is in displaytag.properties (paging.banner...) and I think the tag-instance write the content (the html code written in the properties) only to the response. ( ServletContext.getServletContextName() and so on will not evaluated).

        The only way I could imagine is to extend the tag implementation to support images in the paging are.

        Other ideas?

         

Log in to post a comment.