I have a string in a Managed Bean that I am returning to JSF as output. The returned string is set to output each String component that it consists of on a new line. However, when I pass it to JSF the string prints all on one line. Is there a way to get around this without having to create an individual method (and returned string) for each of the strings that I have combined in the String 'output'?
public String welcomeDisplay() {
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
if(true){
em.getTransaction().begin();
String sessionEmail=Util.getEmail();
Query myQuery = em.createQuery("SELECT u FROM BusinessAccount u WHERE u.email=:email");
myQuery.setParameter("email", sessionEmail);
List<BusinessAccount> userList=myQuery.getResultList();
em.getTransaction().commit();
em.close();
String bName=userList.get(0).getBusinessName();
String bAddress1=userList.get(0).getAddress1();
String bAddress2=userList.get(0).getAddress2();
String bTown=userList.get(0).getTown();
String bPhone=userList.get(0).getTelephoneNum();
String bEmail=userList.get(0).getEmail();
String output=(bName+"\n"+bAddress1+"\n"+bAddress2+"\n"+bTown+"\n"+bPhone+"\n"+bEmail);
return output;
}
else {
addMessage(new FacesMessage(FacesMessage.SEVERITY_ERROR,
"User Registration Failed!", null));
return "failure";
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<head>
<title>Greeting Page</title>
</head>
<body>
<h:form id="greetingForm">
<H2>Greeting Page</H2>
<H4>
<h:outputText value="#{registerBean.welcomeDisplay()}"/>
! You have been successfully authenticated.
</H4>
<table>
<tr>
<td><h:outputLabel for="companyDescription">
<h:outputText id="descriptionLabel" value="Company Description" />
</h:outputLabel></td>
<td><h:inputTextarea rows="10" id="companyDescription" value="#{registerBean.businessAccount.description}"
size="20" /></td>
</tr>
<tr>
<td></td>
<td><h:commandButton id="createAccounts"
action="#{registerBean.update}" value="Update Profile">
</h:commandButton></td>
</tr>
<tr>
<td><h:commandButton id="logout" action="#{loginBean.logout}">
<h:outputText value="Logout" />
</h:commandButton></td>
</tr>
</table>
</h:form>
</body>
</html>