Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
110 views
in Technique[技术] by (71.8m points)

java - How can I manipulate a String in a JSF tag?

Given this code,

<rich:dataTable id="list" value="#{testBeen.dataModel}" var="test" rows="#{testBeen.dataModel.pageSize}">
    ...
    <h:outputText value="#{test.WEEK}" />  

I need to manipulate the #{test.WEEK} and replace character ) with ], how can I do this?

I tried the following, but it does not work:

<%String a = test.WEEK; a.replace("a", "b"); %>
<%=a %>

How can I get the string from JSF and pass it back to JSF?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For this particular simple purpose, I'd just use the JSTL functions taglib. There's a fn:replace() function.

E.g.

<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
...
<h:outputText value="#{fn:replace(test.WEEK, ')', ']')}" />  

You should for sure never use scriptlets <% %> in JSF pages.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...