Search code examples
htmljsfline-breaks

How to show output text in separate lines


I have two String properties in my managed bean along with corresponding getters and setters.

@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";
    }

    // ...
}

I would like to render both strings in separate lines.

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

But they are shown in a single line.

ddhello how are you guys?

How is this caused and how can I solve it?


Solution

  • There are no problem with your program i test your program and i get a result like this :

    enter image description here

    So it show you this because you already change the values in your Constructor :

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

    so it should you ddhello how are you guys?
    ------------------------^-------^

    So if you want to show :

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

    You should not initialize them again in your constructor.

    Note

    Try this to see what happen exactly :

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