@link_to with possible null values?

12 views
Skip to first unread message

Gianna Giavelli

unread,
Jan 23, 2015, 5:16:33 AM1/23/15
to acti...@googlegroups.com

I'm trying to walk a List that is passed into my view as a result of a simple query. Off of it I want to build dynamic links. The links use the ID fields from the result set that is passedin. 

When I use the @link_to  as follows it's ok
 <#list subcategories as subcat>
      
 <@link_to controller="main" action="category" query_string="catid=${subcat.id!}&parentcatid=${subcat.parentcategoryid!}" class="alink" style="font-size:70%;font-color:blue;text-decoration:underline">${subcat.name!""}</@>

  </#list>


But I cannot specify protection in case of null value in this case. I think it is rare that it comes up since these are IDs but I'm sure thers a case where its needed.  I was curious if theres a way to do something like:

 <@link_to controller="main" action="category" query_string="catid=${subcat.id!""}&parentcatid=${subcat.parentcategoryid!""}" class="alink" style="font-size:70%;font-color:blue;text-decoration:underline">${subcat.name!""}</@>
     

Obviously it fails because the "" within the ${} is confusing the end of the query_string
    

Igor Polevoy

unread,
Jan 25, 2015, 12:59:20 PM1/25/15
to acti...@googlegroups.com
Use FreeMarker <#assign command before this line, and then use the value in the query string 

Gianna Giavelli

unread,
Feb 10, 2015, 6:38:43 PM2/10/15
to acti...@googlegroups.com
Ahhh. great ok! This is actually something a lot of people will hit so it's good to know how to do it. Most of us or at least me are coming to the framework not being so used to freemarker. It's my second month and my app is coming together and so far I do like not having to mess with the dao side. (the dark side)

Igor Polevoy

unread,
Feb 10, 2015, 6:41:18 PM2/10/15
to acti...@googlegroups.com
cool. WE are actively working on a new templating framework... called Templator: https://github.com/javalite/activeweb/tree/master/javalite-templator
Its syntax is similar to FM, but it will be much faster and more forgiving than FM 


tx
Reply all
Reply to author
Forward
0 new messages