2 Replies Latest reply on May 21, 2009 7:31 AM by Maxim Kuzmik

    Link one to many and combobox

    Maxim Kuzmik Newbie

      Hello
      I have the next beans

      `
      /**
      * Titre : ADPclearing java packages
      * Description : Java packages for ADPclearing web based products
      * Copyright : Copyright (c) 2003-2007
      */
      package com.adpclr.ejb.entity.traduct;

      import java.io.Serializable;

      import javax.persistence.Entity;
      import javax.persistence.Id;
      import javax.persistence.JoinColumn;
      import javax.persistence.ManyToOne;
      import javax.persistence.Table;

      import com.adpclr.ejb.entity.admin.Language;

      /**
      * @author Maxim Kuzmik
      * Date of Create: 14.05.2009
      * @version 1.0
      *
      */

      @Entity
      @Table(name = "traduct.menu_t")
      public class Menu_t implements Serializable{
      private static final long serialVersionUID = "com.adpclr.ejb.entity.traduct.Menu_t".hashCode();

      private String code;
      private String traduct;
      private Language language;

      /**
      * @param code The code to set.
      */
      public void setCode(String code){
      this.code = code;
      }

      /**
      * @return Returns the code.
      */
      @Id
      public String getCode(){
      return code;
      }

      /**
      * @param traduct The traduct to set.
      */
      public void setTraduct(String traduct){
      this.traduct = traduct;
      }

      /**
      * @return Returns the traduct.
      */
      public String getTraduct(){
      return traduct;
      }

      @ManyToOne
      @JoinColumn(name = "languageid")
      public Language getLanguage(){
      return language;
      }

      public void setLanguage(Language language){
      this.language = language;
      }

      }`

      and

      `/**
      * Titre : ADPclearing java packages
      * Description : Java packages for ADPclearing web based products
      * Copyright : Copyright (c) 2003-2007
      */
      package com.adpclr.ejb.entity.admin;

      import java.io.Serializable;
      import java.util.Set;

      import javax.persistence.Entity;
      import javax.persistence.FetchType;
      import javax.persistence.Id;
      import javax.persistence.OneToMany;
      import javax.persistence.Table;

      import com.adpclr.ejb.entity.traduct.Menu_t;

      /**
      * @author Maxim Kuzmik
      * Date of Create: 19.05.2009
      * @version 1.0
      *
      */

      @Entity
      @Table(name = "admin.language")
      public class Language implements Serializable{
      private static final long serialVersionUID = "com.adpclr.ejb.entity.admin.Language".hashCode();

      private Integer languageid;
      private String languagecode;
      private Set<Menu_t> menuTraductList;

      /**
      * @param languageid The languageid to set.
      */
      public void setLanguageid(Integer languageid){
      this.languageid = languageid;
      }

      /**
      * @return Returns the languageid.
      */
      @Id
      public Integer getLanguageid(){
      return languageid;
      }

      /**
      * @param languagecode The languagecode to set.
      */
      public void setLanguagecode(String languagecode){
      this.languagecode = languagecode;
      }

      /**
      * @return Returns the languagecode.
      */
      public String getLanguagecode(){
      return languagecode;
      }

      @OneToMany(mappedBy = "language", fetch = FetchType.LAZY)
      public Set<Menu_t> getMenuTraductList(){
      return menuTraductList;
      }

      public void setMenuTraductList(Set<Menu_t> menuTraductList){
      this.menuTraductList = menuTraductList;
      }

      public String toString(){
      return languagecode;
      }

      }`


      and have Session Bean.
      `
      /**
      * Titre : ADPclearing java packages
      * Description : Java packages for ADPclearing web based products
      * Copyright : Copyright (c) 2003-2007
      */
      package com.adpclr.ejb.session.tables;

      import java.io.Serializable;
      import java.util.List;

      import javax.ejb.Remove;
      import javax.ejb.Stateful;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;

      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.faces.FacesMessages;

      import com.adpclr.ejb.entity.admin.Language;
      import com.adpclr.ejb.entity.traduct.Menu_t;
      import com.adpclr.ejb.session.tables.local.Menu_tManager;

      /**
      * @author Maxim Kuzmik
      * Date of Create: 15.05.2009
      * @version 1.0
      *
      */

      @Stateful
      @Name("tablemanager_traduct_menu_t")
      @Scope(ScopeType.SESSION)
      public class Menu_tManagerBean implements Serializable, Menu_tManager{
      private static final long serialVersionUID = "com.adpclr.ejb.session.tables.Menu_tManagerBean".hashCode();

      @PersistenceContext(type = javax.persistence.PersistenceContextType.EXTENDED)
      private EntityManager em;

      @In
      private FacesMessages facesMessages;

      private List<Menu_t> records;

      private List languages;

      private Menu_t currentRow;

      public void select(){
      }

      public void delete(){
      records.remove(currentRow);
      em.remove(currentRow);
      currentRow = null;
      }

      @Remove
      public void destroy(){
      }

      public void save(){
      em.merge(currentRow);
      currentRow = null;
      }

      /**
      * @param records The records to set.
      */
      public void setRecords(List<Menu_t> records){
      this.records = records;
      }

      /**
      * @return Returns the records.
      */
      @SuppressWarnings("unchecked")
      public List<Menu_t> getRecords(){
      records = em.createQuery("select tbl from Menu_t tbl").getResultList();
      return records;
      }

      /**
      * @param currentRow The currentRow to set.
      */
      public void setCurrentRow(Menu_t currentRow){
      this.currentRow = currentRow;
      }

      /**
      * @return Returns the currentRow.
      */
      public Menu_t getCurrentRow(){
      return currentRow;
      }

      /**
      * @param languages The languages to set.
      */
      public void setLanguages(List languages){
      this.languages = languages;
      }

      /**
      * @return Returns the languages.
      */
      @SuppressWarnings("unchecked")
      public List getLanguages(){
      languages = em.createQuery("select tbl from Language tbl").getResultList();
      return languages;
      }

      }`


      and have next JSP.

      ` <h:form>
      <rich:messages style="color:red;"></rich:messages>
      <h:panelGrid columns="1">
      <a4j:outputPanel ajaxRendered="true">
      <h:panelGrid columns="2">
      <h:outputText value="Code"/>
      <h:inputText value="#{tablemanager_traduct_menu_t.currentRow.code}" id="code" required="true"/>
      <h:outputText value="Language" />
      <rich:comboBox suggestionValues="#{tablemanager_traduct_menu_t.languages}" directInputSuggestions="true" value="#{tablemanager_traduct_menu_t.currentRow.language}"/>
      <h:outputText value="Traduct" />
      <h:inputText value="#{tablemanager_traduct_menu_t.currentRow.traduct}" id="traduct" required="true"/>
      </h:panelGrid>
      </a4j:outputPanel>
      <a4j:commandButton value="#{messages['buttons.save']}"
      action="#{tablemanager_traduct_menu_t.save}"
      reRender="recordsTable"
      oncomplete="if (#{facesContext.maximumSeverity==null}) #{rich:component('editPanel')}.hide();" />
      <a4j:commandButton value="#{messages['buttons.cancel']}" onclick="#{rich:component('editPanel')}.hide();return false;" />

      </h:panelGrid>
      </h:form>
      `

      And then i click Save button a have got the next error. "value could not be converted to the expected type". I think that problem is in Language field. Bu i don't know how to fix it =(