Reputation: 750
I have my tag ${file.name}
in a jsp file to display a name of file to download
name
containt a full file name,include file extension. for example
testfile.png
a-file.zip
testfile-test505454654.png
a-filenum5468.docx
other_file_with_a_name_very_very_very_larrrrrrrrrrrrrrrrrrrrrge.pdf
Files with very long names, crash my layout.
I think the way to format the file name to shorten it but include the extention. Maybe
testfile.png
a-file.zip
testfile-test505454....png *
a-filenum5468.docx
other_file_with_a_na....pdf *
How I can do?
in href no problem because it is done by id ${file.id}
Upvotes: 1
Views: 404
Reputation: 2582
If file
is a POJO, you may add a getter-method to the POJO (something like String getShortName(){}
) that returns a short version of the file name. And then use the method in your EL expression: ${file.shortName}
.
Upvotes: 2
Reputation: 9645
Since the requirements can be used many times so You should go with CUSTOM Tag solution like @Sotirios Delimanolis suggested.
JSTL function ( Like c:fn ) is another solution. Using jstl function get better performance than Custom tag ( simple / classic model )
Link: http://www.noppanit.com/how-to-create-a-custom-function-for-jstl/
Upvotes: 1
Reputation: 279890
I would write and register a custom tag that would take care of shortening the output to a maximum length
<custom:short value="${file.name}" var="shortFileName" />
The tag would take care of shortening based on defaults or values you specify in the element and putting it the result in a request attribute you can use anywhere after that declaration.
Upvotes: 1