can I use multiple jstl string functions in one expression?

can I use multiple jstl string functions in one expression?

I want to capitalize the first letter?
is it possible?

<c:out value="${fn:substring.toUppers(reference.citationType,0,1)fn:substring(reference.citationType,1)}" /></td>  
dkim18Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

for_yanCommented:

Rather use this function from
      

WordUtils.capitalize(str)

from apache coomons-lang
get jar form here:
http://apache.petsads.us//commons/lang/binaries/commons-lang3-3.1-bin.zip
0
dkim18Author Commented:
I am trying to find out if I can do this in jstl.


Do you know how I can use the <fn:> string function in jsp page?
0
for_yanCommented:

I think this is more likely to work:
<c:out value="${fn:substring.toUppers(reference.citationType,0,1)}${fn:substring(reference.citationType,1)}" /></td>  
0
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

for_yanCommented:

 think it should work like this:
<c:set var="string2" value="${fn:substring(reference.citationType,0,1)}" />

<c:out value="${fn:toUpperCase(string2)}${fn:substring(reference.citationType,1)}" /></td>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dkim18Author Commented:
<c:out value="${fn:toUpperCase(string2)}${fn:substring(reference.citationType,1)}" /></td>


didn't work.
0
for_yanCommented:
and what happened ?
0
for_yanCommented:

And can you test if you have a simple thing like that working without first character:
<c:out value="${fn:substring(reference.citationType,1)}" /></td>  

Are you sure that in JSTL there is substring function with one int argument?

I don't see such option in the doc:
http://docs.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/fn/substring.fn.html
0
rrzCommented:
Here is an example page. You don't need the <c:out> tag.     EL  can be put directly into the template text. Also you can use CSS. I have shown one way to do that too.
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<html>
<body>
<table>
<tr>
<td>
<c:set var="name" value="obama" />
Barack <c:out value="${fn:toUpperCase(fn:substring(name,0,1))}${fn:substring(name,1,fn:length(name))}" /> 
</td> 
<td>
President ${fn:toUpperCase(fn:substring(name,0,1))}${fn:substring(name,1,fn:length(name))}
</td>
<td style="text-transform:capitalize">
           john
</td>
</tr>
</table>
</body>
</html>

Open in new window

0
for_yanCommented:
Still your problem was with not having the second argument in the substring function .
This should work:
<c:set var="string2" value="${fn:substring(reference.citationType,0,1)}" />

<c:out value="${fn:toUpperCase(string2)}${fn:substring(reference.citationType,1,fn:length(reference.citationType))}" /></td>

Open in new window


at least this simple page which makes upper case first charcater of the string "this is first String"  works nicely for me

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" 
                                                  prefix="fn" %>
<html>
<head>
<title>Using JSTL Functions</title>
</head>
<body>

<c:set var="string1" value="this is first String."/>
<c:set var="string3" value="${fn:substring(string1, 0, 1)}" />
<c:set var="string4" value="${fn:toUpperCase(string3)}" />
<c:set var="string5" value="${fn:substring(string1,1,fn:length(string1))}" />

<c:out value="${string4}${string5}"/>



</body>
</html>

Open in new window


Output:

This is first String. 

Open in new window




0
rrzCommented:
I posted the JSTL solution.  
for_yan, why did you take my solution and re-post it ?
0
for_yanCommented:


rrz@871311,
I didn't even read what you posted -  I was following my line through postings
37293088 and 37294739 where I explained the author what was the reason for his problem - and all that was long
before you even posted anything.
Then I typed in my example to confirm that my guess that the issue was with lacking argument in substring
was correct and tried to make this example similar to what author was doing, and I was busy doing it when you posted something.
I even didn't look at waht you posted - and frankly I don't see any similarity now.



0
dkim18Author Commented:
For some reason this worked
<c:set var="string2" value="${fn:substring(reference.citationType,0,1)}" />

<c:out value="${fn:toUpperCase(string2)}${fn:substring(reference.citationType,1,fn:length(xxxxxx)}" /></td>

but not this one.
${fn:toUpperCase(fn:substring(name,0,1))}${fn:substring(name,1,fn:length(name))}
0
dkim18Author Commented:
never mind.

This worked also.
Thanks much.

${fn:toUpperCase(fn:substring(name,0,1))}${fn:substring(name,1,fn:length(name))}
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.