Dynamically display a random text from database
mongkeh Sep 9, 2009 8:55 AMHello,
How to dynamically display a random text from database?
I had a page that will be display a wise word quote selected from database with rich:effect, the message now displayed if i put a static message.
this is my home.xhtml:
<div class="billboard-home"> <blockquote id="blockquote" style="display:none" cite="#"><span id="quote">“ <h:outputText value="#{wiseWordHome.instance.quote}" /> .”</span><br /><br /><span id="author">—<h:outputText value="#{wiseWordHome.instance.author}" /></span> </blockquote> <rich:effect name="showDiv" for="blockquote" type="Appear" params="delay:1.8, duration:0.5"></rich:effect> <rich:effect name="hideDiv" for="blockquote" type="Fade" params="delay:8.0, duration:2.0"></rich:effect> <rich:effect for="window" event="onload" type="Appear" params="targetId:'blockquote',delay:1.8, duration:0.5" /> <rich:effect for="window" event="onload" type="Fade" params="targetId:'blockquote',delay:7.0, duration:1.0" /> <a4j:region> <h:form> <a4j:poll id="quotesPoll" interval="10000" enabled="true" oncomplete="hideDiv();showDiv();" ignoreDupResponses="true" eventsQueue="quotesQueue"></a4j:poll> </h:form> </a4j:region> </div>
and this is my bean WiseWord.java
@Entity @Table(name = "wise_word") public class WiseWord implements java.io.Serializable { private Integer id; private String quote; private String author; public WiseWord() { } public WiseWord(String quote, String author) { this.quote = quote; this.author = author; } @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "id", unique = true, nullable = false) public Integer getId() { return this.id; } public void setId(Integer id) { this.id = id; } @Column(name = "quote", length = 65535) @Length(max = 65535) public String getQuote() { return this.quote; } public void setQuote(String quote) { this.quote = quote; } @Column(name = "author", length = 50) @Length(max = 50) public String getAuthor() { return this.author; } public void setAuthor(String author) { this.author = author; }
Please help me. Thanks.