Java 在JSF中使用SelectOneMenu创建转换器

Java 在JSF中使用SelectOneMenu创建转换器,java,jsf,jakarta-ee,primefaces,Java,Jsf,Jakarta Ee,Primefaces,我无法从SelectOne菜单中获取所选项目。我为菜单提供了一个集合,希望用户选择其中一个。我将菜单放入一个表单中,因此我有一个commandButton,用于执行选择。此实现给了我以下错误:java.util.LinkedHashSet无法强制转换为com.gestion.projet.domain.projet 我想要一个projet对象,而不是projet列表 那么这就是我的追踪: mai 18, 2014 1:06:54 PM com.sun.faces.lifecycle.Proces

我无法从SelectOne菜单中获取所选项目。我为菜单提供了一个集合,希望用户选择其中一个。我将菜单放入一个表单中,因此我有一个commandButton,用于执行选择。此实现给了我以下错误:java.util.LinkedHashSet无法强制转换为com.gestion.projet.domain.projet 我想要一个projet对象,而不是projet列表 那么这就是我的追踪:

mai 18, 2014 1:06:54 PM com.sun.faces.lifecycle.ProcessValidationsPhase execute
Avertissement: java.util.LinkedHashSet cannot be cast to com.gestion.projet.domain.Projet
java.lang.ClassCastException: java.util.LinkedHashSet cannot be cast to com.gestion.projet.domain.Projet
    at com.gestion.projet.dao.ProjetDAOImpl.findProjetByNom(ProjetDAOImpl.java:124)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy42.findProjetByNom(Unknown Source)
    at com.gestion.projet.web.jsf.PhaseComponentImpl.getAsObject(PhaseComponentImpl.java:298)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
    at $Proxy56.getAsObject(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy9.getAsObject(Unknown Source)
    at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:167)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectOneValue(MenuRenderer.java:198)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:315)
    at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1023)
    at javax.faces.component.UIInput.validate(UIInput.java:953)
    at javax.faces.component.UIInput.executeValidate(UIInput.java:1204)
    at javax.faces.component.UIInput.processValidators(UIInput.java:693)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    at org.primefaces.component.panel.Panel.processValidators(Panel.java:281)
    at javax.faces.component.UIForm.processValidators(UIForm.java:240)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    at org.primefaces.component.layout.Layout.processValidators(Layout.java:233)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1159)
    at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:72)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

mai 18, 2014 1:06:54 PM org.apache.catalina.core.StandardWrapperValve invoke
Grave: Servlet.service() for servlet [Faces Servlet] in context with path [/HCP] threw exception [java.util.LinkedHashSet cannot be cast to com.gestion.projet.domain.Projet] with root cause
java.lang.ClassCastException: java.util.LinkedHashSet cannot be cast to com.gestion.projet.domain.Projet
    at com.gestion.projet.dao.ProjetDAOImpl.findProjetByNom(ProjetDAOImpl.java:124)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy42.findProjetByNom(Unknown Source)
    at com.gestion.projet.web.jsf.PhaseComponentImpl.getAsObject(PhaseComponentImpl.java:298)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
    at $Proxy56.getAsObject(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy9.getAsObject(Unknown Source)
    at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:167)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectOneValue(MenuRenderer.java:198)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:315)
    at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1023)
    at javax.faces.component.UIInput.validate(UIInput.java:953)
    at javax.faces.component.UIInput.executeValidate(UIInput.java:1204)
    at javax.faces.component.UIInput.processValidators(UIInput.java:693)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    at org.primefaces.component.panel.Panel.processValidators(Panel.java:281)
    at javax.faces.component.UIForm.processValidators(UIForm.java:240)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    at org.primefaces.component.layout.Layout.processValidators(Layout.java:233)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1159)
    at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:72)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
这是我的xhtml生成selectOneMenu的部分:

<h:selectOneMenu id="selectProjet" value="#{PhaseComponent.projet}" required="true" converter="#{PhaseComponent}">
                                    <f:selectItem itemLabel="Select One" itemValue=""  />
                                    <f:selectItems value="#{PhaseComponent.findNomProjets()}" var="projet" itemValue="#{projet}" itemLabel="#{ProjetComponent.projet.nomprojet}" />


                              </h:selectOneMenu>

我在添加转换器时出错 这是PhaseComponent类:

@Scope("session")
@Component("PhaseComponent")
public class PhaseComponentImpl implements PhaseComponent ,Converter {

    private Phase phase;

    private Projet projet;

    private Tache taches;

    private Livrable livrables;

    @Autowired
    private LivrableDAO livrableDAO;
    @Autowired
    private PhaseDAO phaseDAO;

    @Autowired
    private ProjetDAO projetDAO;

    @Autowired
    private TacheDAO tacheDAO;

    @Autowired
    private PhaseService phaseService;

    private Set<SelectItem> selected;
    /** 
     */


    /** 
     */
    public Set<SelectItem> getSelectOneItemsProj(){
        this.selected= new LinkedHashSet<SelectItem>();
        Set<Projet> projets=projetDAO.findAllProjets();
        for(Projet proj:projets)
        {
            SelectItem selectItem=new SelectItem(proj.getIdprojet(),proj.getNomprojet());
            this.selected.add(selectItem);      }
        return selected;

    }

    public PhaseComponentImpl() {
    }

    @Transactional
    public String selectPhaseTaches(Integer phase_idphase, Integer related_taches_idtache) {
        taches = tacheDAO.findTacheByPrimaryKey(related_taches_idtache, -1, -1);
        return "/jsf/phase/taches/viewTaches.xhtml";
    }

    @Transactional
    public String editPhaseLivrables(Integer phase_idphase, Integer related_livrables_idlivrable) {
        livrables = livrableDAO.findLivrableByPrimaryKey(related_livrables_idlivrable, -1, -1);
        return "/jsf/phase/livrables/editLivrables.xhtml";
    }

    @Transactional
    public String newPhaseTaches(Integer phase_idphase) {
        taches = new Tache();

        return "/jsf/phase/taches/createTaches.xhtml";
    }

    @Transactional
    public Tache getTaches() {
        return taches;
    }


    @Transactional
    public String savePhaseProjet(Integer phase_idphase, Projet projet) {
        phase = phaseService.savePhaseProjet(phase_idphase, projet);

        return "/jsf/phase/viewPhase.xhtml";
    }

    @Transactional
    public Projet getPhaseProjet(Integer idphaseKey) {
        return phaseDAO.findPhaseByPrimaryKey(idphaseKey).getProjet();
    }

    @Transactional
    public Projet getProjet() {
        return projet;
    }


    @Transactional
    public String confirmDeletePhaseProjet(Integer phase_idphase, Integer related_projet_idprojet) {
        projet = projetDAO.findProjetByPrimaryKey(related_projet_idprojet);

        return "/jsf/phase/projet/deleteProjet.xhtml";
    }

    @Transactional
    public String newPhaseLivrables(Integer phase_idphase) {
        livrables = new Livrable();

        return "/jsf/phase/livrables/createLivrables.xhtml";
    }


    @Transactional
    public String confirmDeletePhaseTaches(Integer phase_idphase, Integer related_taches_idtache) {
        taches = tacheDAO.findTacheByPrimaryKey(related_taches_idtache);

        return "/jsf/phase/taches/deleteTaches.xhtml";
    }

    @Transactional
    public List<Livrable> listPhaseLivrables(Integer idphaseKey) {
        return new java.util.ArrayList<Livrable>(phaseDAO.findPhaseByPrimaryKey(idphaseKey).getLivrables());
    }

    @Transactional
    public String deletePhaseProjet(Integer phase_idphase, Integer related_projet_idprojet) {
        phase = phaseService.deletePhaseProjet(phase_idphase, related_projet_idprojet);

        return "/jsf/phase/viewPhase.xhtml";
    }

    @Transactional
    public String confirmDeletePhaseLivrables(Integer phase_idphase, Integer related_livrables_idlivrable) {
        livrables = livrableDAO.findLivrableByPrimaryKey(related_livrables_idlivrable);

        return "/jsf/phase/livrables/deleteLivrables.xhtml";
    }

    @Transactional
    public List<Phase> listPhases() {
        return new java.util.ArrayList<Phase>(phaseService.loadPhases());
    }


    @Transactional
    public String savePhaseTaches(Integer phase_idphase, Tache tache) {
        phase = phaseService.savePhaseTaches(phase_idphase, tache);

        return "/jsf/phase/viewPhase.xhtml";
    }

    @Transactional
    public Livrable getLivrables() {
        return livrables;
    }

    @Transactional
    public String savePhaseLivrables(Integer phase_idphase, Livrable livrable) {
        phase = phaseService.savePhaseLivrables(phase_idphase, livrable);

        return "/jsf/phase/viewPhase.xhtml";
    }

    @Transactional
    public String editPhase(Integer idphaseKey) {
        phase = phaseDAO.findPhaseByPrimaryKey(idphaseKey);

        return "/jsf/phase/editPhase.xhtml";
    }


    @Transactional
    public String editPhaseProjet(Integer phase_idphase, Integer related_projet_idprojet) {
        projet = projetDAO.findProjetByPrimaryKey(related_projet_idprojet, -1, -1);
        return "/jsf/phase/projet/editProjet.xhtml";
    }


    @Transactional
    public String selectPhaseLivrables(Integer phase_idphase, Integer related_livrables_idlivrable) {
        livrables = livrableDAO.findLivrableByPrimaryKey(related_livrables_idlivrable, -1, -1);
        return "/jsf/phase/livrables/viewLivrables.xhtml";
    }

    @Transactional
    public String savePhase(Phase phase) {
        phaseService.savePhase(phase);
        return "/jsf/phase/listPhases.xhtml";
    }

    @Transactional
    public String confirmDeletePhase(Integer idphaseKey) {
        phase = phaseDAO.findPhaseByPrimaryKey(idphaseKey);

        return "/jsf/phase/deletePhase.xhtml";
    }


    @Transactional
    public String editPhaseTaches(Integer phase_idphase, Integer related_taches_idtache) {
        taches = tacheDAO.findTacheByPrimaryKey(related_taches_idtache, -1, -1);
        return "/jsf/phase/taches/editTaches.xhtml";
    }


    @Transactional
    public String selectPhase(Integer idphaseKey) {
        phase = phaseDAO.findPhaseByPrimaryKey(idphaseKey);

        return "/jsf/phase/viewPhase.xhtml";
    }


    @Transactional
    public String selectPhaseProjet(Integer phase_idphase, Integer related_projet_idprojet) {
        projet = projetDAO.findProjetByPrimaryKey(related_projet_idprojet, -1, -1);
        return "/jsf/phase/projet/viewProjet.xhtml";
    }


    @Transactional
    public Phase getPhase() {
        return phase;
    }

    @Transactional
    public String newPhaseProjet(Integer phase_idphase) {
        projet = new Projet();

        return "/jsf/phase/projet/createProjet.xhtml";
    }


    @Transactional
    public String deletePhaseLivrables(Integer phase_idphase, Integer related_livrables_idlivrable) {
        phase = phaseService.deletePhaseLivrables(phase_idphase, related_livrables_idlivrable);

        return "/jsf/phase/viewPhase.xhtml";
    }


    @Transactional
    public List<Tache> listPhaseTaches(Integer idphaseKey) {
        return new java.util.ArrayList<Tache>(phaseDAO.findPhaseByPrimaryKey(idphaseKey).getTaches());
    }


    @Transactional
    public String deletePhase(Integer idphaseKey) {
        Phase phase = phaseDAO.findPhaseByPrimaryKey(idphaseKey);
        phaseService.deletePhase(phase);
        return "/jsf/phase/listPhases.xhtml";
    }


    @Transactional
    public String newPhase() {
        phase = new Phase();

        return "/jsf/phase/createPhase.xhtml";
    }


    @Transactional
    public String deletePhaseTaches(Integer phase_idphase, Integer related_taches_idtache) {
        phase = phaseService.deletePhaseTaches(phase_idphase, related_taches_idtache);

        return "/jsf/phase/viewPhase.xhtml";
    }

    @Transactional
    public void affectPhaseProjet(Integer phase_idphase_3,
            Integer phase_idprojet) {

        projet = projetDAO.findProjetByPrimaryKey(phase_idprojet, -1, -1);
        phase.setProjet(projet);
    }
    @Transactional
    public Projet findNomProjet()
    {
        return (Projet) projetDAO.findNomProjets();
    }

    public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {

        projet=(Projet) projetDAO.findProjetByNomprojet(arg2);
        return projet ;
    }

    public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
        // TODO Auto-generated method stub
        return null;
    }

    public List<Projet> findNomProjets() {
        // TODO Auto-generated method stub
        return projetDAO.findNomProjets();
    }

}
@Scope(“会话”)
@组件(“相组件”)
公共类PhaseComponentImpl实现PhaseComponent、转换器{
私有阶段;
私人Projet Projet;
私人环节;
私人可居住的平民;
@自动连线
利夫拉布利多私人酒店;
@自动连线
私人相道相道;
@自动连线
私人工程项目;
@自动连线
私人塔克道塔克道;
@自动连线
私人相位服务相位服务;
选择专用集;
/** 
*/
/** 
*/
公共集getSelectOneItemsProj(){
this.selected=新建LinkedHashSet();
Set projets=projetDAO.findAllProjets();
用于(项目:项目)
{
SelectItem SelectItem=new SelectItem(proj.getIdprojet(),proj.getNomprojet());
this.selected.add(selectItem);}
返回选中的;
}
公共相组件mpl(){
}
@交易的
公共字符串selectPhaseTaches(整数相位、整数相关环节){
taches=tacheDAO.findTacheByPrimaryKey(相关的链接\u id链接,-1,-1);
返回“/jsf/phase/taches/viewTaches.xhtml”;
}
@交易的
公共字符串editPhaseLivrables(整数相位\u idphase,整数相关\u livrables\u idlivrable){
livrables=livrableDAO.findLivrableByPrimaryKey(related_livrables_idlivarable,-1,-1);
返回“/jsf/phase/livrables/editLivrables.xhtml”;
}
@交易的
公共字符串newPhaseTaches(整数相位\u idphase){
taches=新Tache();
返回“/jsf/phase/taches/createTaches.xhtml”;
}
@交易的
公共链接getTaches(){
返回环节;
}
@交易的
公共字符串savePhaseProjet(整数相位\u idphase,Projet-Projet){
阶段=阶段服务。保存阶段项目(阶段,项目);
返回“/jsf/phase/viewPhase.xhtml”;
}
@交易的
公共项目GetPhaseProject(整数idphaseKey){
返回phaseDAO.findPhaseByPrimaryKey(idphaseKey.getProjet();
}
@交易的
公共Projet getProjet(){
返回项目;
}
@交易的
公共字符串confirmDeletePhaseProject(整数相位\u idphase、整数相关\u项目\u idprojet){
projet=projetDAO.findprojectbyprimarykey(相关的projet\idprojet);
返回“/jsf/phase/projet/deleteProjet.xhtml”;
}
@交易的
公共字符串newPhaseLivrables(整数相位\u idphase){
livrables=新的livrables();
返回“/jsf/phase/livrables/createLivrables.xhtml”;
}
@交易的
公共字符串confirmDeletePhaseTaches(整数相位\ idphase、整数相关\环节\ idtache){
taches=tacheDAO.findTacheByPrimaryKey(相关的链接);
返回“/jsf/phase/taches/deletetetaches.xhtml”;
}
@交易的
公共列表listPhaseLivrables(整数idphaseKey){
返回新的java.util.ArrayList(phaseDAO.findPhaseByPrimaryKey(idphaseKey.getLivarables());
}
@交易的
公共字符串deletePhaseProject(整数相位\u idphase、整数相关\u项目\u idprojet){
阶段=阶段服务。删除阶段项目(阶段、相关项目);
返回“/jsf/phase/viewPhase.xhtml”;
}
@交易的
公共字符串confirmDeletePhaseLivrables(整数相位\u idphase,整数相关\u livrables\u idlivrable){
livrables=livrableDAO.findLivrableByPrimaryKey(相关的livrables\u idlivarable);
返回“/jsf/phase/livrables/deleteLivrables.xhtml”;
}
@交易的
公共列表列表阶段(){
返回新的java.util.ArrayList(phaseService.loadPhases());
}
@交易的
公共字符串savePhaseTaches(整数相位\ idphase,Tache-Tache){
相位=相位服务。保存相位表(相位、相位、连接);
返回“/jsf/phase/viewPhase.xhtml”;
}
@交易的
公共可居住区{
返老还童;
}
@交易的
公共字符串savePhaseLivrables(整数相位_idphase,livarable-livarable){
相位=相位服务。保存相位可变参数(相位idphase,可生存);
返回“/jsf/phase/viewPhase.xhtml”;
}
@交易的
公共字符串编辑阶段(整数idphaseKey){
相位=相位AO.findPhaseByPrimaryKey(idphaseKey);
返回“/jsf/phase/editPhase.xhtml”;
}
@交易的
公共字符串EditPhaseProject(整数相位\u idphase、整数相关\u项目\u idprojet){
projet=projetDAO.findprojectbyprimarykey(相关的projet\idprojet,-1,-1);
返回“/jsf/phase/projet/editProjet.xhtml”;
}
@交易的
公共字符串selectPhaseLivrables(整数相位\u idphase,整数相关\u livrables\u idlivrable){
livrables=livrableDAO.findLivrableByPrimaryKey(related_livrables_idlivarable,-1,-1);
返回“/jsf/phase/livrables/viewLivrables.xhtml”;
}
@交易的
公共字符串保存阶段(阶段){
阶段服务。保存阶段(阶段);
返回“/jsf/phase/listphages.xhtml”;
}
@交易的
公共字符串confirmDeletePhase(整数idphaseKey){
相位=相位AO.findPhaseByPrimaryKey(idphaseKey);
返回“/jsf/phase/deletePhase.xhtml”;
}
@交易的
公共字符串editPhaseTaches(整数相位\ idphase、整数相关\环节\ idtach
@Scope("session")
@Component("PhaseComponent")
public class PhaseComponentImpl implements PhaseComponent ,Converter {

    private Phase phase;

    private Projet projet;

    private Tache taches;

    private Livrable livrables;

    @Autowired
    private LivrableDAO livrableDAO;
    @Autowired
    private PhaseDAO phaseDAO;

    @Autowired
    private ProjetDAO projetDAO;

    @Autowired
    private TacheDAO tacheDAO;

    @Autowired
    private PhaseService phaseService;

    private Set<SelectItem> selected;
    /** 
     */


    /** 
     */
    public Set<SelectItem> getSelectOneItemsProj(){
        this.selected= new LinkedHashSet<SelectItem>();
        Set<Projet> projets=projetDAO.findAllProjets();
        for(Projet proj:projets)
        {
            SelectItem selectItem=new SelectItem(proj.getIdprojet(),proj.getNomprojet());
            this.selected.add(selectItem);      }
        return selected;

    }

    public PhaseComponentImpl() {
    }

    @Transactional
    public String selectPhaseTaches(Integer phase_idphase, Integer related_taches_idtache) {
        taches = tacheDAO.findTacheByPrimaryKey(related_taches_idtache, -1, -1);
        return "/jsf/phase/taches/viewTaches.xhtml";
    }

    @Transactional
    public String editPhaseLivrables(Integer phase_idphase, Integer related_livrables_idlivrable) {
        livrables = livrableDAO.findLivrableByPrimaryKey(related_livrables_idlivrable, -1, -1);
        return "/jsf/phase/livrables/editLivrables.xhtml";
    }

    @Transactional
    public String newPhaseTaches(Integer phase_idphase) {
        taches = new Tache();

        return "/jsf/phase/taches/createTaches.xhtml";
    }

    @Transactional
    public Tache getTaches() {
        return taches;
    }


    @Transactional
    public String savePhaseProjet(Integer phase_idphase, Projet projet) {
        phase = phaseService.savePhaseProjet(phase_idphase, projet);

        return "/jsf/phase/viewPhase.xhtml";
    }

    @Transactional
    public Projet getPhaseProjet(Integer idphaseKey) {
        return phaseDAO.findPhaseByPrimaryKey(idphaseKey).getProjet();
    }

    @Transactional
    public Projet getProjet() {
        return projet;
    }


    @Transactional
    public String confirmDeletePhaseProjet(Integer phase_idphase, Integer related_projet_idprojet) {
        projet = projetDAO.findProjetByPrimaryKey(related_projet_idprojet);

        return "/jsf/phase/projet/deleteProjet.xhtml";
    }

    @Transactional
    public String newPhaseLivrables(Integer phase_idphase) {
        livrables = new Livrable();

        return "/jsf/phase/livrables/createLivrables.xhtml";
    }


    @Transactional
    public String confirmDeletePhaseTaches(Integer phase_idphase, Integer related_taches_idtache) {
        taches = tacheDAO.findTacheByPrimaryKey(related_taches_idtache);

        return "/jsf/phase/taches/deleteTaches.xhtml";
    }

    @Transactional
    public List<Livrable> listPhaseLivrables(Integer idphaseKey) {
        return new java.util.ArrayList<Livrable>(phaseDAO.findPhaseByPrimaryKey(idphaseKey).getLivrables());
    }

    @Transactional
    public String deletePhaseProjet(Integer phase_idphase, Integer related_projet_idprojet) {
        phase = phaseService.deletePhaseProjet(phase_idphase, related_projet_idprojet);

        return "/jsf/phase/viewPhase.xhtml";
    }

    @Transactional
    public String confirmDeletePhaseLivrables(Integer phase_idphase, Integer related_livrables_idlivrable) {
        livrables = livrableDAO.findLivrableByPrimaryKey(related_livrables_idlivrable);

        return "/jsf/phase/livrables/deleteLivrables.xhtml";
    }

    @Transactional
    public List<Phase> listPhases() {
        return new java.util.ArrayList<Phase>(phaseService.loadPhases());
    }


    @Transactional
    public String savePhaseTaches(Integer phase_idphase, Tache tache) {
        phase = phaseService.savePhaseTaches(phase_idphase, tache);

        return "/jsf/phase/viewPhase.xhtml";
    }

    @Transactional
    public Livrable getLivrables() {
        return livrables;
    }

    @Transactional
    public String savePhaseLivrables(Integer phase_idphase, Livrable livrable) {
        phase = phaseService.savePhaseLivrables(phase_idphase, livrable);

        return "/jsf/phase/viewPhase.xhtml";
    }

    @Transactional
    public String editPhase(Integer idphaseKey) {
        phase = phaseDAO.findPhaseByPrimaryKey(idphaseKey);

        return "/jsf/phase/editPhase.xhtml";
    }


    @Transactional
    public String editPhaseProjet(Integer phase_idphase, Integer related_projet_idprojet) {
        projet = projetDAO.findProjetByPrimaryKey(related_projet_idprojet, -1, -1);
        return "/jsf/phase/projet/editProjet.xhtml";
    }


    @Transactional
    public String selectPhaseLivrables(Integer phase_idphase, Integer related_livrables_idlivrable) {
        livrables = livrableDAO.findLivrableByPrimaryKey(related_livrables_idlivrable, -1, -1);
        return "/jsf/phase/livrables/viewLivrables.xhtml";
    }

    @Transactional
    public String savePhase(Phase phase) {
        phaseService.savePhase(phase);
        return "/jsf/phase/listPhases.xhtml";
    }

    @Transactional
    public String confirmDeletePhase(Integer idphaseKey) {
        phase = phaseDAO.findPhaseByPrimaryKey(idphaseKey);

        return "/jsf/phase/deletePhase.xhtml";
    }


    @Transactional
    public String editPhaseTaches(Integer phase_idphase, Integer related_taches_idtache) {
        taches = tacheDAO.findTacheByPrimaryKey(related_taches_idtache, -1, -1);
        return "/jsf/phase/taches/editTaches.xhtml";
    }


    @Transactional
    public String selectPhase(Integer idphaseKey) {
        phase = phaseDAO.findPhaseByPrimaryKey(idphaseKey);

        return "/jsf/phase/viewPhase.xhtml";
    }


    @Transactional
    public String selectPhaseProjet(Integer phase_idphase, Integer related_projet_idprojet) {
        projet = projetDAO.findProjetByPrimaryKey(related_projet_idprojet, -1, -1);
        return "/jsf/phase/projet/viewProjet.xhtml";
    }


    @Transactional
    public Phase getPhase() {
        return phase;
    }

    @Transactional
    public String newPhaseProjet(Integer phase_idphase) {
        projet = new Projet();

        return "/jsf/phase/projet/createProjet.xhtml";
    }


    @Transactional
    public String deletePhaseLivrables(Integer phase_idphase, Integer related_livrables_idlivrable) {
        phase = phaseService.deletePhaseLivrables(phase_idphase, related_livrables_idlivrable);

        return "/jsf/phase/viewPhase.xhtml";
    }


    @Transactional
    public List<Tache> listPhaseTaches(Integer idphaseKey) {
        return new java.util.ArrayList<Tache>(phaseDAO.findPhaseByPrimaryKey(idphaseKey).getTaches());
    }


    @Transactional
    public String deletePhase(Integer idphaseKey) {
        Phase phase = phaseDAO.findPhaseByPrimaryKey(idphaseKey);
        phaseService.deletePhase(phase);
        return "/jsf/phase/listPhases.xhtml";
    }


    @Transactional
    public String newPhase() {
        phase = new Phase();

        return "/jsf/phase/createPhase.xhtml";
    }


    @Transactional
    public String deletePhaseTaches(Integer phase_idphase, Integer related_taches_idtache) {
        phase = phaseService.deletePhaseTaches(phase_idphase, related_taches_idtache);

        return "/jsf/phase/viewPhase.xhtml";
    }

    @Transactional
    public void affectPhaseProjet(Integer phase_idphase_3,
            Integer phase_idprojet) {

        projet = projetDAO.findProjetByPrimaryKey(phase_idprojet, -1, -1);
        phase.setProjet(projet);
    }
    @Transactional
    public Projet findNomProjet()
    {
        return (Projet) projetDAO.findNomProjets();
    }

    public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {

        projet=(Projet) projetDAO.findProjetByNomprojet(arg2);
        return projet ;
    }

    public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
        // TODO Auto-generated method stub
        return null;
    }

    public List<Projet> findNomProjets() {
        // TODO Auto-generated method stub
        return projetDAO.findNomProjets();
    }

}
<h:panelGrid id="detail" columns="2" styleClass="grid" columnClasses="label,value">
                        <h:outputText value="#{phasemsgs['phase.datedebut.title']}:" />
                    <p:calendar value="#{PhaseComponent.phase.datedebut}" id="datedebut"  converter="dateConverterForCalendar"/>
                    <h:outputText value="#{phasemsgs['projet.datefineffective.title']}:" />
                            <p:calendar value="#{PhaseComponent.phase.datefin}" id="datefin"  converter="dateConverterForCalendar"/>
                        <h:outputText value="#{phasemsgs['phase.description.title']}:" />
                            <h:inputText id="phase_description" value="#{PhaseComponent.phase.description}" required="false" label="phase_description" />
                         <h:outputLabel  value="Projet: *" />
                             <h:selectOneMenu id="selectProjet" value="#{PhaseComponent.projet}" required="true" converter="#{entityConverter}">
                                    <f:selectItem itemLabel="Select One" itemValue=""  />
                                    <f:selectItems value="#{PhaseComponent.findNomProjets()}" />
                              </h:selectOneMenu>
                    <h:panelGroup>
                        <p:commandButton image="save" ajax="false" style="margin-right:20px;" value="#{phasemsgs['navigation.save']}" action="#{PhaseComponent.savePhase(PhaseComponent.phase)}"/>
                    </h:panelGroup>
                </h:panelGrid>
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.WeakHashMap;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

@FacesConverter(value = "entityConverter")
public class EntityConverter implements Converter {

    private static Map<Object, String> entities = new WeakHashMap<Object, String>();

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object entity) {
        synchronized (entities) {
            if (!entities.containsKey(entity)) {
                String uuid = UUID.randomUUID().toString();
                entities.put(entity, uuid);
                return uuid;
            } else {
                return entities.get(entity);
            }
        }
    }

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String uuid) {
        for (Entry<Object, String> entry : entities.entrySet()) {
            if (entry.getValue().equals(uuid)) {
                return entry.getKey();
            }
        }
        return null;
    }

}