users@glassfish.java.net

Re: UISelectMany and "java.util.NoSuchElementException"

From: <glassfish_at_javadesktop.org>
Date: Wed, 01 Aug 2007 10:28:17 PDT

I also encounter a problem like this :i request the page,shou correct,when i submit the page,rase an error.

jsf page:

<h:selectManyListbox id="teams" value="#{UserForm.userTeamIds}" >
<f:selectItems value="#{UserForm.userTeamMap}"/>
</h:selectManyListbox>


backing bean :

public class UserForm {
        private UserService userService;

        private User user;
        

.......

        public List<String> getUserTeamIds(){
                log.debug("getUserTeamIds go here..");
                List<String> li=new java.util.ArrayList<String>();
                if(user!=null){
                        Set<Team> teams=user.getTeams();
                        for (Iterator<Team> itr=teams.iterator();itr.hasNext();){
                                Team r=itr.next();
                                li.add(r.getTeamId().toString());
                        }
                }
                return li;
        }


        /**
         * for select many
         * @return
         */
        public Map<String,String> getUserTeamMap(){
                log.debug("getUserTeamMap here :");
                java.util.Map<String,String> m=new java.util.LinkedHashMap<String, String>();
                if(user!=null){
                        Set<Team> teams=user.getTeams();
                        for (Iterator<Team> itr=teams.iterator();itr.hasNext();){
                                Team t=itr.next();
                                m.put(t.getTeamName(),t.getTeamId().toString());
                        }
                }
                return m;
        }

............
}


run in en error :
-------------------------------------------------
javax.servlet.ServletException
        javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
        org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
        org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)

root cause

java.util.NoSuchElementException
        javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:117)
        javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:164)
        javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:49)
        javax.faces.component.UISelectMany.matchValue(UISelectMany.java:485)
        javax.faces.component.UISelectMany.validateValue(UISelectMany.java:454)
        javax.faces.component.UIInput.validate(UIInput.java:867)
        javax.faces.component.UIInput.executeValidate(UIInput.java:1065)
        javax.faces.component.UIInput.processValidators(UIInput.java:666)
        javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
        javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
        javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
        javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
        javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
        javax.faces.component.UIForm.processValidators(UIForm.java:229)
        javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
        javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:662)
        com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:100)
        com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
        com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
        javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
        org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
        org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)

-------------------------------------------------

i debug in it ,when i post the page,the page invoke the UserForm.getUserTeamMap() method,but return
a empety map,then the server validate the selectmany's available value and selectedItems,then mismath.and throw a exception......is this reson???? who can tell me .
[Message sent by forum member 'songxh2' (songxh2)]

http://forums.java.net/jive/thread.jspa?messageID=229062