Home > Java - J2EE > How can i create a JSF-ComboBox with Seam

How can i create a JSF-ComboBox with Seam

For this we need first a list of all entries in the database have.
Then, in a Stateful-Bean

@SuppressWarnings("unchecked")
public List getKundengruppeList(){
   return entityManager.createQuery("select c from Kundengruppe c")
                       .setHint("org.hibernate.cacheable", true)
                       .getResultList();
}

Now you can use the ComboBox in an XHTML file.

<h:selectOneMenu value="#{artikel.artikelgruppeId}">
   <s:selectItems
      value="#{stammdatenSuggestion.getArtikelgruppeList()}"
      var="item" label="#{item.name}"
      noSelectionLabel="#{messages['general.value.None']}"
      hideNoSelectionLabel="false" />
   <s:convertEntity />
</h:selectOneMenu>

<s:convertEntity /> is hier important.
This converts selected item in ComboBox to EntityObject.
For this to work properly, the methods equals and hashCode must be overridden in Entity.

 

Advertisements
Categories: Java - J2EE Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: