4

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
MemoryLeak
  • 7,322
  • 23
  • 90
  • 133

3 Answers3

19

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.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 6
    and for xhtml, you can just add it to the html tag like xmlns:fn="http://java.sun.com/jsp/jstl/functions" too. It's a great resource ;-) –  Jan 20 '14 at 17:37
3

You could write a custom Converter and parameterize it by search and replace string. See this introduction JSF for nonbelievers: JSF conversion and validation

stacker
  • 68,052
  • 28
  • 140
  • 210
0

Good practice would be to do this in the bean rather than the facelet.

kgautron
  • 7,915
  • 9
  • 39
  • 60