java - Best way to make StringTemplate limit the length of a string? -


This is the easiest to use an example example. In some scenarios, we have list items that contain a lot of text, but showing more than the first few words is not useful, so we deal with it in JSP:

  & lt; For% (item items: items) {%> & Lt; Li & gt; & Lt;% = StringHelper.shorten (item.getValue (), 30))% & gt; & Lt; / A & gt; & Lt; / Li & gt; & Lt;%}% & gt;   

The filter contains some arguments that it avoids cutting words, and is also included to describe "..." as trivial and so on. I.e.:

  & lt; Li & gt; Some text & lt; / Li & gt; & Lt; Li & gt; Some other text that is longer ... & lt; / Li & gt;   

Is there a clear way to do this with the formatter? I know that I can do something like that, but it seems a little hesitation because we are different in different places - Use different numbers:

  $ items: {i | & Lt; Li & gt; $ I.value; Format = "max 30" $ & lt; / Li & gt;} $    

The simplest way is to customize a tag, such as

  Public category ShortenTag Tagsport {extended fixed final integer MAX_LENGTH = 30; Public Inc doStartTag () {// Small string here}}    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -