【问题标题】:How to show output text in separate lines如何在单独的行中显示输出文本
【发布时间】:2017-06-23 20:35:31
【问题描述】:

我的托管 bean 中有两个 String 属性以及相应的 getter 和 setter。

@ManagedBean
@SessionScoped
public class EditorBean implements Serializable {

    private String value="hello how are you";
    private String message="hello how are you";

    public EditorBean() {
        value="hello how are you guys?";
        message="dd";
    }

    // ...
}

我想在单独的行中渲染两个字符串。

<h:outputText value="#{editorBean.message}" /> 
<h:outputText value="#{editorBean.value}" /> 

但它们显示在一行中。

你好,你们好吗?

这是怎么引起的,我该如何解决?

【问题讨论】:

标签: html jsf line-breaks


【解决方案1】:

你的程序没有问题我测试你的程序,我得到这样的结果:

所以它向您展示了这一点,因为您已经更改了构造函数中的值:

public EditorBean() {
    value="hello how are you guys?";
    message="dd";
}

所以你应该ddhello how are you guys?
------------------------^--------^

所以如果你想展示:

private String value="hello how are you";
private String message="hello how are you";

您不应在构造函数中再次初始化它们。

注意

试试这个看看到底发生了什么:

Message = <h:outputText value="#{editorBean.message}"  /> 
<br/>
Value = <h:outputText value="#{editorBean.value}" /> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-07
    • 2014-10-08
    • 1970-01-01
    • 1970-01-01
    • 2019-10-27
    相关资源
    最近更新 更多