Fill selectOneMenu on page load.
grdzeli_kaci Feb 19, 2007 1:13 AMhi all, i'm newbie in seam.
i've one simple question. (i've seam documentation : seam_refference.pdf but could't resolv the problem)
ok, i have login page and there are some selectOneMenu - components. for example applications or languages. i need fill them on page sturtup from database. is there any doc or example which can help me ? or could anybody help me how to do it?
1.here is my login.xhtml file :
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
template="layout/template.xhtml">
<ui:define name="body">
<h:form id="loginForm">
<table width="400" cellpadding="5" cellspacing="0" style="border: 1px solid #9e2629">
<tr>
<td class="LogonText" colspan="2" align="center">Login to System</td>
</tr>
<tr>
<td class="td_new">
<table width="100%" cellpadding="5" cellspacing="0" border="0">
<tr>
<td class="td_new" rowspan="5"><h:graphicImage value="/images/login_pic.gif"/></td>
<td class="td_new">UserName</td>
<td class="td_new">
<h:inputText styleClass="font_style" value="" />
</td>
</tr>
<tr>
<td class="td_new">Password</td>
<td class="td_new">
<h:inputSecret styleClass="font_style" value="" />
</td>
</tr>
<tr>
<td class="td_new">Application</td>
<td class="td_new">
<h:selectOneMenu styleClass="font_style" value="">
<!-- how i could write to fill this component? -->
</h:selectOneMenu>
</td>
</tr>
<tr>
<td class="td_new">Language</td>
<td class="td_new">
<h:selectOneMenu styleClass="font_style" required="true" value="">
<f:selectItems value="#{loginBean.langItems}" />
<f:convertNumber type="number" />
</h:selectOneMenu>
</td>
</tr>
<tr>
<td class="td_right" colspan="2">
<h:commandButton id="LoginBtn"
name="LoginBtn" class="Btn2"
value="Login"
onblur="return this.myonblur();"
onfocus="return this.myonfocus();"
onmouseout="return this.myonmouseout();"
onmouseover="return this.myonmouseover();"/>
<script type="text/javascript"><!--
sjwuic_assign_button('loginForm:LoginBtn', defaultButtonStrings, true, false, false);
//--></script>
</td>
<!--actionListener="" -->
</tr>
</table>
</td>
</tr>
<tr>
<td class="td_new" colspan="2"></td>
</tr>
<tr>
<td class="td_new" colspan="2"></td>
</tr>
</table>
</h:form>
</ui:define>
</ui:composition>
2. and here is my entity bean for application :
@Entity
@Table(name = "LANGUAGE")
@Name("user")
@Scope(ScopeType.SESSION)
public class Language implements Serializable {
@Id()
@GeneratedValue(generator="LangIdGenerator")
@SequenceGenerator(name = "LangIdGenerator", sequenceName = "SEQ_LANGUAGE_ID")
@Column(name="LANGUAGE_ID", unique=true, nullable=false, precision=22)
private Long languageId;
@Column(name = "NAME")
private String name;
@Column(name = "SHORTNAME")
private String shortname;
@Lob
@Column(name = "IMAGE")
private byte [] image;
@Lob
@Column(name = "LOCALE")
private byte [] locale;
@Column(name = "REMARK")
private String remark;
@Column(name = "USER_ID")
private BigInteger userId;
@Column(name = "REC_STATUS")
private BigInteger recStatus;
@Column(name = "REG_DATE")
@Temporal(TemporalType.DATE)
private Date regDate;
@Column(name = "UPD_DATE")
@Temporal(TemporalType.DATE)
private Date updDate;
@OneToMany(mappedBy = "languageId")
private Collection<LanguageProperty> languagePropertyCollection;
transient private List<SelectItem> applications;
/** Creates a new instance of Language */
public Language() {
}
/**
* Creates a new instance of Language with the specified values.
* @param languageId the languageId of the Language
*/
public Language(Long languageId) {
this.languageId = languageId;
}
/**
* Gets the languageId of this Language.
* @return the languageId
*/
public Long getLanguageId() {
return this.languageId;
}
/**
* Sets the languageId of this Language to the specified value.
* @param languageId the new languageId
*/
public void setLanguageId(Long languageId) {
this.languageId = languageId;
}
/**
* Gets the name of this Language.
* @return the name
*/
public String getName() {
return this.name;
}
/**
* Sets the name of this Language to the specified value.
* @param name the new name
*/
public void setName(String name) {
this.name = name;
}
/**
* Gets the shortname of this Language.
* @return the shortname
*/
public String getShortname() {
return this.shortname;
}
/**
* Sets the shortname of this Language to the specified value.
* @param shortname the new shortname
*/
public void setShortname(String shortname) {
this.shortname = shortname;
}
/**
* Gets the image of this Language.
* @return the image
*/
public byte [] getImage() {
return this.image;
}
/**
* Sets the image of this Language to the specified value.
* @param image the new image
*/
public void setImage(byte [] image) {
this.image = image;
}
/**
* Gets the locale of this Language.
* @return the locale
*/
public byte [] getLocale() {
return this.locale;
}
/**
* Sets the locale of this Language to the specified value.
* @param locale the new locale
*/
public void setLocale(byte [] locale) {
this.locale = locale;
}
/**
* Gets the remark of this Language.
* @return the remark
*/
public String getRemark() {
return this.remark;
}
/**
* Sets the remark of this Language to the specified value.
* @param remark the new remark
*/
public void setRemark(String remark) {
this.remark = remark;
}
/**
* Gets the userId of this Language.
* @return the userId
*/
public BigInteger getUserId() {
return this.userId;
}
/**
* Sets the userId of this Language to the specified value.
* @param userId the new userId
*/
public void setUserId(BigInteger userId) {
this.userId = userId;
}
/**
* Gets the recStatus of this Language.
* @return the recStatus
*/
public BigInteger getRecStatus() {
return this.recStatus;
}
/**
* Sets the recStatus of this Language to the specified value.
* @param recStatus the new recStatus
*/
public void setRecStatus(BigInteger recStatus) {
this.recStatus = recStatus;
}
/**
* Gets the regDate of this Language.
* @return the regDate
*/
public Date getRegDate() {
return this.regDate;
}
/**
* Sets the regDate of this Language to the specified value.
* @param regDate the new regDate
*/
public void setRegDate(Date regDate) {
this.regDate = regDate;
}
/**
* Gets the updDate of this Language.
* @return the updDate
*/
public Date getUpdDate() {
return this.updDate;
}
/**
* Sets the updDate of this Language to the specified value.
* @param updDate the new updDate
*/
public void setUpdDate(Date updDate) {
this.updDate = updDate;
}
/**
* Gets the languagePropertyCollection of this Language.
* @return the languagePropertyCollection
*/
public Collection<LanguageProperty> getLanguagePropertyCollection() {
return this.languagePropertyCollection;
}
/**
* Sets the languagePropertyCollection of this Language to the specified value.
* @param languagePropertyCollection the new languagePropertyCollection
*/
public void setLanguagePropertyCollection(Collection<LanguageProperty> languagePropertyCollection) {
this.languagePropertyCollection = languagePropertyCollection;
}
/**
* Returns a hash code value for the object. This implementation computes
* a hash code value based on the id fields in this object.
* @return a hash code value for this object.
*/
@Override
public int hashCode() {
int hash = 0;
hash += (this.languageId != null ? this.languageId.hashCode() : 0);
return hash;
}
/**
* Determines whether another object is equal to this Language. The result is
* <code>true</code> if and only if the argument is not null and is a Language object that
* has the same id field values as this object.
* @param object the reference object with which to compare
* @return <code>true</code> if this object is the same as the argument;
* <code>false</code> otherwise.
*/
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Language)) {
return false;
}
Language other = (Language)object;
if (this.languageId != other.languageId && (this.languageId == null || !this.languageId.equals(other.languageId))) return false;
return true;
}
/**
* Returns a string representation of the object. This implementation constructs
* that representation based on the id fields.
* @return a string representation of the object.
*/
@Override
public String toString() {
return "com.magti.seam.beans.billAdmin.Language[languageId=" + languageId + "]";
}
}
3. and also i have Local Stateless session bean
@Local(BillAdminManagement.class)
@Stateless
@Name("billAdmin")
public class BillAdminManagementBean implements BillAdminManagement{
@PersistenceContext
private EntityManager entManager;
@Logger
private Log log;
public List<Language> getLanguages() throws Exception {
try {
List<Language> list = entManager.createNamedQuery("Language.getAllLanguages").getResultList();
log.info("List Size = "+list.size());
return null;
} catch (Exception e) {
log.error("Error While Getting Languages",e);
throw e;
}
}
}
how i can fill dropdownbox component from this method on page startup?
Regards,
Paata.