NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Re: Iterating through a list in a database and presenting it on JSF

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
omoz4real



Joined: 26 Jan 2009
Posts: 121
Location: United Kingdom

PostPosted: Fri Apr 09, 2010 6:14 pm    Post subject: Re: Iterating through a list in a database and presenting it on JSF Reply with quote

Hi John,

Thanks very much for your reply . It did work as it displayed the messages from the database but not as I was expecting though. It ddisplayed all the messages on the same line. I was expecting when a user enters a message it displays on a new line with the "\n".as with the servlets example in the tutorial http://netbeans.org/kb/docs/javaee/javaee-gettingstarted.html . when viewing the output on the glassfish output console using the System.out.prinln(), it displays correctly i.e each new text on a new line. I tried creating three output texts on the JSF page and added two additional methods i.e getAllMessage1
() and getAllMessage1() and used it as the value for the corresponding output text but they all just come up on three lines i.e. all the messages appear on one line irrespective of when the text is entered. in the servlets example this was simply achieved by using the

for (Iterator it = news.iterator(); it.hasNext()Wink {
NewsEntity elem = (NewsEntity) it.next();
out.println(" <b>"+elem.getTitle()+" </b><br />");
out.println(elem.getBody()+"<br /> ");
}
and it got the required results

Please do you know how I can go about this? Any way, thanks very much for introducing me to the StringBuffer class as I have never used it before.


--- On Thu, 4/8/10, Futaleufu_John <[i]address-removed>[/i] wrote:

Quote:

From: Futaleufu_John <address-removed>
Subject: [nbj2ee] Re: Iterating through a list in a database and presenting it on JSF
To: address-removed
Date: Thursday, April 8, 2010, 12:07 AM


I don't know if it will work but try this:

public String getAllMessages() {
List news = messageFacade.findAll();
StringBuffer buff = new StringBuffer();
for (Iterator it = news.iterator(); it.hasNext()Wink {
Message elem = (Message) it.next();
buff.append(elem.getMessage() + "\n");
buff.append(elem.getName() + "\n");
}
return buff.toString();
}

If elem.getMessage and elem.getName do not return a String, you will have to
cast them to String.


omoz4real wrote:
Quote:

but i want to display all the messages in the database in a jsf page not
just the number of messages. I have tried using this method

public String getAllMessages() {
List news = messageFacade.findAll();
for (Iterator it = news.iterator(); it.hasNext()Wink {
Message elem = (Message) it.next();
a = elem.getMessage();
bc = elem.getName();
System.out.println(a);
System.out.println(bc);
}
return a + "\n"+ "\n" + bc;
}

but this method only displays the last message entered in the jsf page.


--
View this message in context: http://old.nabble.com/Iterating-through-a-list-in-a-database-and-presenting-it-on-JSF-tp28136076p28171023.html
Sent from the Netbeans - J2EE mailing list archive at Nabble.com.


Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo