Link to home
Start Free TrialLog in
Avatar of dkim18
dkim18

asked on

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>  
Avatar of for_yan
for_yan
Flag of United States of America image


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
Avatar of dkim18
dkim18

ASKER

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?

I think this is more likely to work:
<c:out value="${fn:substring.toUppers(reference.citationType,0,1)}${fn:substring(reference.citationType,1)}" /></td>  
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dkim18

ASKER

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


didn't work.
and what happened ?

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
SOLUTION
Avatar of rrz
rrz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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




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


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.



Avatar of dkim18

ASKER

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))}
Avatar of dkim18

ASKER

never mind.

This worked also.
Thanks much.

${fn:toUpperCase(fn:substring(name,0,1))}${fn:substring(name,1,fn:length(name))}