Scott, You are correct, the @Insert I showed would just render the URL string itself. I was mainly trying to illustrate the example, but in reality you would probably want to use an @Any in that case as well, e.g.:
<a jwcid="@Any" href="ognl:yahooUrl">Yahoo</a> Regarding the "possibly cleaner" comment, I wasn't recommending doing any presentation formatting within your java code, but rather only providing the data needed by the page. I don't normally encode any html in my java code unless I'm writing a component which is designed to render html. By "possibly cleaner", I was really talking about avoiding a lot of messy OGNL string concatenations and other formatting, since it may become a problem if you need to (for example) embed single or double quotes in the string, or if your data objects may contain null values, or if you need to conditionally alter the format based on certain object values, etc. I've found it is often better to wrap as much of this sort of logic as possible within my java code. By better, I mean more reliable, more readable, more easily maintained. The java code would typically not provide any html formatting, but would provide as much of the data needed by the page as possible. Keep in mind that the java code backing a particular page is really intended only to serve the needs of that page. This recommendation is especially important if you end up needing similar html rendering in multiple pages. In this case, you might write a single utility class to provide Map URLs, and then you can easily drop them in any page you like (provided the pages have access to your utility class). This is a case where it might in fact justify creating a custom component. However, in some cases it is fine to just format everything with OGNL, so it really depends on your use case. You might also consider defining a .page component of an @Any type, and do your formatting there, so at least your .html page is cleaner. There's an example of this on the Tapestry @Any component reference. Shawn Quoting Scott Sauyet <[EMAIL PROTECTED]>: > Shawn Church wrote: > > ExternalLink is used to provide a URL which may be used outside > the > > context of a Tapestry webapp to link back into the webapp. [ ... > ] > > See, I told you I was a newbie! :-) > > > I think what you are wanting is to provide links to external > > (non-Tapestry) applications from within a Tapestry app. > > Exactly. > > > There are > many > > ways to do this, but two common ways are to either use the @Any > > component to build the URL within your .html (or .page) directly, > or a > > possibly cleaner way is to build the URL strings within your .java > page > > handler. > > > > > Using the @Any solution: > > > > <a jwcid="@Any" href='ognl: > "http://maps.yahoo.com/maps_result?addr=" + > > location.address.line + "&csz=" + location.address.city'> Yahoo Map > </a> > > Thank you. The @Any solution is perhaps what I was looking for. > > > > Using the .java method solution: > > > > public String getYahooUrl() > > { > > String url = "http://maps.yahoo.com/maps_result"; > > url += "?addr=" + getLocation().getAddress().getLine(); > > url += "&csz=" + getLocation().getAddress().getCity(); > > return url; > > } > > > > <span jwcid="@Insert" value="ognl:yahooUrl" raw="ognl:true"/> > > I'm not certain about this Java method. It seems to me that it would > > just output the URL into the document. Is there a way to get this > into > an href attribute? > > The other question about the Java method is whether this is > considered > good practice in Tapestry. It seems to me a matter of moving > presentation data out to the template and back into the Java code, > which > seems counter to most other MVC systems I've seen, especially as I > would > need to add methods for every new URL format needed. > > So when you say that this is "possibly cleaner", is the Tapestry > experience that it's better to keep the templates clean and offload > some > formatting into Java? I'm surprised if this is the case, but would > love > to hear the arguments in favor of it. > > Thank you very much for your helpful response. > > -- Scott > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
