简体   繁体   English

如何操作JSF标记中的String?

[英]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? 我需要操作#{test.WEEK}和替换字符)] ,我该怎么办呢?

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? 如何从JSF获取字符串并将其传递回JSF?

For this particular simple purpose, I'd just use the JSTL functions taglib. 出于这个特殊的目的,我只使用JSTL 函数 taglib。 There's a fn:replace() function. 有一个fn:replace()函数。

Eg 例如

<%@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. 您肯定不会在JSF页面中使用scriptlet <% %>

You could write a custom Converter and parameterize it by search and replace string. 您可以编写自定义Converter并通过搜索和替换字符串对其进行参数化。 See this introduction JSF for nonbelievers: JSF conversion and validation 请参阅此介绍JSF for nonbelievers:JSF转换和验证

好的做法是在bean中而不是facelet中执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM