Announcement Announcement Module
Collapse
No announcement yet.
Page stop loading while [ c:foreach ] loop Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Page stop loading while [ c:foreach ] loop

    Hello there,

    I'm loading a form, the user press insert button, same page reload, all form data loading, but the groups, it load but incompletely... , and the whole page stop, i mean any thing exist after the groups drop down list, wont load too....

    so i cant perform any action...

    My controller:

    Code:
    public class TeachersListController extends SimpleFormController{
        UserAccountFactory userAccountFactory;
        MajorFactory majorFactory;
        GroupFactory groupFactory;
    
        public TeachersListController(){
            setCommandClass(TeacherForm.class);
            setCommandName("teacherForm");
        }
    
        @Override
        protected Object formBackingObject(HttpServletRequest request) throws Exception {
            ...
        }
    
        protected Map referenceData(HttpServletRequest request) throws Exception {
            Map<Object,Object> map = new HashMap<Object, Object>();
            map.put("action","view");
    
            List<UserAccount> teacherList = userAccountFactory.getUserAccountsByRoleid("" ,0 , UserAccountFactory.QueryAction.Or, "2", "3", "6");
            List<Major> majorList = (List<Major>)majorFactory.getMajors();
            List<Group> groupList = (List<Group>)groupFactory.getGroups();
    
            map.put("teacher_list", teacherList);
            map.put("major_list", majorList);
            map.put("group_list",groupList);
            map.put("major_factory",majorFactory);
    
            return map;
        }
    
        @Override
        protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
    
            String action="view";
            String code="-1";
            String error="";
    
            /*
             * Set Actions
             */
            boolean actionPerformed=false;
            Enumeration enumeration = request.getParameterNames();
            while (enumeration.hasMoreElements() && !actionPerformed){
                
                String s = (String)enumeration.nextElement();
                
                if( s.contains("btn_req_insert") ){
                    command = new TeacherForm("","","","","","","","0","",false,"","");
    
                    action="insert";
                    code="-1";
                    actionPerformed=true;
                }
                else if ( s.contains("btn_req_edit_")){
                    try{
                        code=s.substring(13);//take the number after edit : edit_?????
    
                        UserAccount userAccount = userAccountFactory.getUserAccount(Long.valueOf(code));
    
                        ((TeacherForm)command).setActive(userAccount.getEnabled() == 1);
                        ((TeacherForm)command).setEmail(userAccount.getEmail());
                        ((TeacherForm)command).setFirstname(userAccount.getFirstname());
                        ((TeacherForm)command).setGroupCode(String.valueOf(userAccount.getGroup().getGroupcode()));
                        ((TeacherForm)command).setLastname(userAccount.getLastname());
                        ((TeacherForm)command).setMajorCode(userAccount.getMajor().getReshtecode());
                        ((TeacherForm)command).setPassword(userAccount.getPasswordHash());
                        ((TeacherForm)command).setPersonalCode(String.valueOf(userAccount.getStno()));
                        ((TeacherForm)command).setRole(userAccount.getRoleid());
                        ((TeacherForm)command).setSex(userAccount.getSex());
                        ((TeacherForm)command).setTel(userAccount.getPhone());
                        ((TeacherForm)command).setUsername(userAccount.getUsername());
    
                        action="edit";
                        actionPerformed=true;
                    } catch (Exception ex){}
                }
                else if ( s.contains("btn_req_delete_")){
                    ...
                }
                else if(s.contains("btn_yes_delete_")){
                    ...
                }
                else if(s.contains("btn_no_delete_")){
                    ...
                }
                else if(s.contains("btn_do_cancel")){
                    ...
                }
                else if(s.contains("btn_do_edit_")){
                    ...
                }
                else if(s.contains("btn_do_insert_")){
                    ...
                }
            }
    
            // Base
            Map model = errors.getModel();
    
            ModelAndView mav = new ModelAndView(getSuccessView(), getCommandName(), command);
            mav.addAllObjects(errors.getModel());
    
    
            //Definitions
            List<UserAccount> teacherList = userAccountFactory.getUserAccountsByRoleid("" ,0 , UserAccountFactory.QueryAction.Or, "2", "3", "6");
            List<Major> majorList = (List<Major>)majorFactory.getMajors();
            List<Group> groupList = (List<Group>)groupFactory.getGroups();
    
            UserAccountFactory userAccountFactory2 = new UserAccountFactory();
    
            //Mapping
    
            mav.addObject("teacher_list", teacherList);
            mav.addObject("major_list", majorList);
            mav.addObject("group_list", groupList);
            mav.addObject("major_factory", majorFactory);
    
            if(!error.isEmpty()){
                mav.addObject("error_msg", error);
                error="";
            }
    
            //for finding edit/delete object
            if(!code.equals("-1")){
                try{
                    UserAccount userAccount = userAccountFactory.getUserAccount(Long.valueOf(code));
    
                    mav.addObject("teacher", userAccount);
                    mav.addObject("user_account", userAccount);
                    mav.addObject("code", code);
    
                }catch (Exception er){
                    action="view";
                }
            }
    
            mav.addObject("action", action);
            return mav;
        }
    
        public void setUserAccountFactory(UserAccountFactory userAccountFactory) {
            this.userAccountFactory = userAccountFactory;
        }
    
        public void setMajorFactory(MajorFactory majorFactory) {
            this.majorFactory = majorFactory;
        }
    
        public void setGroupFactory(GroupFactory groupFactory) {
            this.groupFactory = groupFactory;
        }
    }
    And the place it crash in my JSP:
    Code:
    <tr>
        <td class="edit_table_caption_even">
            <spring:message code="tch_lst.group_code"/>
        </td>
        <td class="edit_table_input_even">
            <f:select path="groupCode">
                <spring:message code="tch_lst.please_select_one_option" var="p_s_o_o"/>
                <f:option value="" label="${p_s_o_o}"/>
                <c:forEach items="${group_list}" var="group">
                    <f:option value="${group.groupcode}">
                        ${group.groupcode}
                        <c:if test="${! empty group.groupname}">
                            -${group.groupname}
                        </c:if>
                    </f:option>
                </c:forEach>
            </f:select>
        </td>
    </tr>
    Also i should say that all my factroies return complete result list, and the dont lack data...
    Last edited by deadManN; Mar 15th, 2012, 01:32 PM.

  • #2
    i was commented some thing, which used a path to the command...
    it's seem that spring do it's action while parsing the document, so it crash in the middle of foreach before it reach to that command...
    also it seem it parsing all document, and it don't care if you comment some thing or no, so be careful.

    Comment

    Working...
    X