首页 > 解决方案 > 执行 ManagedBean 方法的调用并将其结果放入 fn:replace 函数应该有什么语法?

问题描述

我无法继续执行以下任务,我什至没有在 JSF 中找到任何可以帮助我的表达式语言函数的信息。我有一个任务——

显示以新行开始的行

返回行的 ManagedBean(name = "Bean_0") 方法是

public String task4() {
    String result = "";
    String surname = "Sckoriy";
    int i = 0;
    do {
        result += surname + "\n";
        i++;
    }while(i != 4);
    return result;
} 

这是xhtml代码 -

<div class = "Container">
    <p class = "Task">#{Bean_0.getTask4()}</p>
    <p class = "Result">
    //Difficult is here
    //What's syntax must there be? 
    <h:outputText value = "#{fn:replace(Bean_0.task4(),'\n','&lt;br/&gt;')}" escape="false"/>
    </p>
</div>

我得到了例外 -

SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path 
[/Practice] threw exception [/Page.xhtml @34,78 value="# 
{fn:replace(Bean_0.task4(),'\n','<br/>')}" Failed to parse the expression [# 
{fn:replace(Bean_0.task4(),'\n','<br/>')}]] with root cause
org.apache.el.parser.ParseException: Encountered " <ILLEGAL_CHARACTER> "\' 
"" at line 1, column 29.
Was expecting one of:

"{" ...
<INTEGER_LITERAL> ...
<FLOATING_POINT_LITERAL> ...
<STRING_LITERAL> ...
"true" ...
"false" ...
"null" ...
"(" ...
"[" ...
"!" ...
"not" ...
"empty" ...
"-" ...
<IDENTIFIER> ...
<IDENTIFIER> ...
"(" ...

标签: jsf

解决方案


推荐阅读