Announcement Announcement Module
Collapse
No announcement yet.
Role of DispatcherServlet Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Sorry for the misunderstanding here. Right now I'm only calling the ViewController as the first view(actually this view contains addAttachmentType.jsp and attachmentTypeList.jsp, initially the thought was to have these views different). So right now I'm only using only two beans "View" and "SearchAttachmentType".
    I'll give it a try to
    <prop key="/search.{htm or do}">SearchAttachmentType </prop>
    and let you know how it went.

    Thanks,
    anita

    Comment


    • #17
      Nope it not working either. I try changing to
      <prop key="/search.htm">SearchAttachmentType</prop>
      and
      <property name="successView" value="redirect:search.htm"/>
      If I use redirect:search.htm, the success view does not show up atall, it is not giving me any exception though either. And if I take out the redirect part and just do this
      <property name="successView" value="search"/>
      success view shows up but when I try to submit the form by success view, it does not call the controller attachted to it.

      If you can suggest anything else, I'll really appreciate that.

      Thanks,
      anita

      Comment


      • #18
        Hi Anita,can you please show me the code of ur ViewController.I will see if i can help..

        Comment


        • #19
          View Controller code in my 2nd post for this thread.

          Thanks,
          anita

          Comment


          • #20
            Originally posted by anita View Post
            Nope it not working either. I try changing to

            and

            If I use redirect:search.htm, the success view does not show up atall, it is not giving me any exception though either. And if I take out the redirect part and just do this

            success view shows up but when I try to submit the form by success view, it does not call the controller attachted to it.

            If you can suggest anything else, I'll really appreciate that.

            Thanks,
            anita
            Hi Anita, Can you please post your bean definition file for which the success page of "search.htm" worked for the above mentioned reply ?. I mean the spring-servlet file which shows you the success page using the method I had suggested.Please post the web.xml file also,if possible.

            Comment


            • #21
              Hi Anita,
              Please Check the Action in the success form in the form tag.Because the controller for the success page is associated with that action in the form.And hence the urlmapping in the xml definition file has to match with the action.Does these match?

              Comment


              • #22
                Hello,
                Here are all my codes for AttachmentType-context.xml, web.xml, ViewController and searchcontroller. Now I have little similar question that I'm creating page urls in handleReanderRequestinternal, if I click on any of this this it takes me to related page and formbacking object method for thta page controller runs but again if I try to submit some for by that page onSubmitAction for the ViewController runs.

                Amit,
                I did not quite get what you wanted to say can you please explain it to me.

                AttachmentType-context.xml

                Code:
                <?xml version="1.0" encoding="UTF-8"?>
                <beans xmlns="http://www.springframework.org/schema/beans"
                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       xmlns:context="http://www.springframework.org/schema/context"
                       xmlns:jee="http://www.springframework.org/schema/jee"
                       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
                       http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd">
                    
                    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                        <property name="cache" value="true"/>
                        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
                        <property name="redirectContextRelative" value="true"/>
                        <property name="prefix" value="/WEB-INF/jsp/"/>
                        <property name="suffix" value=".jsp"/>
                    </bean>
                
                    <bean id="parameterMappingInterceptor" class="org.springframework.web.portlet.handler.ParameterMappingInterceptor"/>
                
                    <bean class="org.springframework.web.portlet.handler.PortletModeParameterHandlerMapping">
                        <property name="order" value="10"/>
                        <property name="portletModeParameterMap">
                            <map>
                                <entry key="view">
                                    <map>
                                        <entry key="add" value-ref="AddAttachmentType"></entry>
                                        <entry key="list"  value-ref="AttachmentTypeList"></entry>
                                        <entry key="search" value-ref="SearchAttachmentType"></entry>
                                    </map>
                                </entry>
                            </map>
                        </property>
                    </bean>
                
                    <bean class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
                        <property name="order" value="20"/>
                        <property name="portletModeMap">
                            <map>
                                <entry key="view" value-ref="View"/>
                                <entry key="edit" value-ref="Edit"/>
                                <entry key="help" value-ref="Help"/>
                            </map>
                        </property>
                    </bean>
                
                    <!-- validator -->
                    <bean id="attachmentTypeValidator" class="net.ijus.attachmenttypemanger.AttachmentTypeValidator"/>
                    <bean id="searchFormDataValidator" class="net.ijus.attachmenttypemanger.SearchFormDataValidator"/>
                
                    <bean id="View" class="net.ijus.attachmenttypemanger.ViewController">
                        <property name="commandClass" value="net.ijus.attachmenttypemanger.AttachmentType"/>
                        <property name="commandName" value="attachmenttype"/>
                        <property name="formView" value="View"/>
                        <property name="successView" value="search"/>
                        <property name="bindOnNewForm" value="true"/>
                        <property name="sessionForm" value="true"/>
                        <property name="validator" ref="attachmentTypeValidator/>
                    </bean>
                
                    <bean id="Edit" class="net.ijus.attachmenttypemanger.EditController"/>
                 
                    <bean id="Help" class="net.ijus.attachmenttypemanger.HelpController"/>
                
                    <bean id="AddAttachmentType" class="net.ijus.attachmenttypemanger.AddController">
                        <property name="commandClass" value="net.ijus.attachmenttypemanger.AttachmentType"/>
                        <property name="commandName" value="attachmenttype"/>
                        <property name="formView" value="AddAttachmentType"/>
                        <property name="successView" value="AddAttachmentType"/>
                        <property name="bindOnNewForm" value="true"/>
                        <property name="sessionForm" value="true"/>
                        <property name="validator" ref="attachmentTypeValidator/>
                
                    </bean>
                
                    <bean id="AttachmentTypeList" class="net.ijus.attachmenttypemanger.ListController"/>
                
                    <bean id="SearchAttachmentType" class="net.ijus.attachmenttypemanger.SearchController">
                        <property name="commandClass" value="net.ijus.attachmenttypemanger.SearchFormData"/>
                        <property name="commandName" value="searchFormData"/>
                        <property name="formView" value="search"/>
                        <property name="bindOnNewForm" value="true"/>
                        <property name="sessionForm" value="true"/>
                        <property name="validator" ref="searchFormDataValidator"/>
                    </bean>
                    
                </beans>
                web.xml

                Code:
                <?xml version="1.0" encoding="UTF-8"?>
                <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd">
                    <display-name>AttachmentTypeManager</display-name>
                    <context-param>
                        <param-name>contextConfigLocation</param-name>
                        <param-value>/WEB-INF/context/applicationContext.xml</param-value>
                    </context-param>
                    <context-param>
                        <param-name>contextConfigLocation</param-name>
                        <param-value>/WEB-INF/context/AttachmentType-context.xml</param-value>
                    </context-param>
                    <listener>
                        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
                    </listener>
                    <listener>
                		<listener-class>com.liferay.portal.kernel.servlet.PortletContextListener</listener-class>
                	</listener>
                    
                    <servlet>
                        <servlet-name>ViewRendererServlet</servlet-name>
                        <servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
                        <load-on-startup>1</load-on-startup>
                    </servlet>
                    <servlet>
                        <servlet-name>AttachmentType</servlet-name>
                        <servlet-class>org.apache.pluto.core.PortletServlet</servlet-class>
                        <init-param>
                            <param-name>portlet-guid</param-name>
                            <param-value>attachmenttypemanager.attachmenttype</param-value>
                        </init-param>
                        <init-param>
                            <param-name>portlet-class</param-name>
                            <param-value>org.springframework.web.portlet.DispatcherPortlet</param-value>
                        </init-param>
                        <init-param>
                            <param-name>contextConfigLocation</param-name>
                            <param-value>/WEB-INF/context/AttachmentType-context.xml</param-value>
                        </init-param>
                    </servlet>
                    <servlet-mapping>
                        <servlet-name>AttachmentType</servlet-name>
                        <url-pattern>*.htm</url-pattern>
                    </servlet-mapping>
                    <servlet-mapping>
                        <servlet-name>ViewRendererServlet</servlet-name>
                        <url-pattern>/WEB-INF/servlet/view</url-pattern>
                    </servlet-mapping>
                
                </web-app>

                Thanks,
                Anita
                Last edited by anita; Apr 24th, 2009, 06:56 AM.

                Comment


                • #23
                  Herw is the codes for my controller.
                  ViewController.java

                  Code:
                   public class ViewController extends SimpleFormController {
                  
                      private HibernateAttachmentTypeModel model = new HibernateAttachmentTypeModel();
                      private AttachmentType obj;
                  
                      public ListController() {
                          super();
                      }
                  
                      @Override
                      protected Map referenceData(PortletRequest request) throws Exception {
                      Map tableValue = new HashMap();
                      List<AttachmentType> attachmenttypes = model.getAllAttachmentType();
                      tableValue.put("attachmenttypes", attachmenttypes);
                      return tableValue;
                      }
                  
                      @Override
                      protected void onSubmitAction(ActionRequest request, ActionResponse response, Object command, BindException errors) throws Exception {
                      Map<?, ?> userInfo = (Map<?, ?>) request.getAttribute(
                      PortletRequest.USER_INFO);
                      long addedBy = Long.parseLong(userInfo.get("liferay.user.id").toString());
                      obj = (AttachmentType) command;
                      if (obj.getAttachmentTypeId() == null || obj.getAttachmentTypeId().equals("")) {
                  
                      List<Organization> organizations = new LinkedList<Organization>();
                      try {
                      organizations = OrganizationLocalServiceUtil.getService().getUserOrganizations(addedBy);
                      } catch (Exception e) {
                      }
                      long groupId = organizations.get(0).getOrganizationId();
                      obj.setAddedBy(addedBy);
                      obj.setDateAdded(new Date());
                      obj.setGroupId(groupId);
                      model.addAttachmentType(obj);
                  
                      } else {
                      obj.setModifiedBy(addedBy);
                      obj.setDateModified(new Date());
                      int modifiedCount = convertStringToInteger(request.getParameter("modifiedCount"));
                      modifiedCount++;
                      obj.setModifiedCount(modifiedCount);
                      model.updateAttachmentType(obj);
                      }
                  
                      }
                  
                      @Override
                      protected Object formBackingObject(PortletRequest request) throws Exception {
                  
                          try {
                              if (attachmentTypeId == null) {
                                  obj = new AttachmentType();
                              } else if (attachmentTypeId != null) {
                                  obj = model.getAttachmentTypeByAttachmentTypeId(attachmentTypeId);
                              }
                          } catch (Exception ex) {
                              System.out.println("exception happened. = " + ex);
                          }
                          return obj;
                      }
                  
                      @Override
                      protected void initBinder(PortletRequest request, PortletRequestDataBinder binder) throws Exception {
                          binder.registerCustomEditor(AttachmentType.class, new AttachmentTypeEditor());
                          SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
                          binder.registerCustomEditor(Date.class, new CustomDateEditor(df, true));
                          binder.setRequiredFields(new String[]{"code"});
                          binder.registerCustomEditor(Long.TYPE, new CustomLongEditor());
                          binder.registerCustomEditor(Integer.TYPE, new CustomIntegerEditor());
                  
                      super.initBinder(request, binder);
                      }
                  
                      @Override
                      protected ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response) throws Exception {
                          ModelAndView mav = new ModelAndView("View");
                          PortletURL url = response.createRenderURL();
                          url.setPortletMode(request.getPortletMode());
                          url.setParameter("action", "search" );
                  
                          mav.addObject("searchurl", url);
                  
                          url = response.createRenderURL();
                          url.setPortletMode(request.getPortletMode());
                          url.setParameter("action", "add");
                  
                          mav.addObject("addurl", url);
                  
                          List<AttachmentType> list = model.getAllAttachmentType();
                          mav.addObject("attachmenttypes", list);
                          
                          return mav;
                  
                      }
                  
                      public int convertStringToInteger(String str) {
                          int intStr = 0;
                          try {
                              if (!str.equals("") && str != null && !str.isEmpty()) {
                                  intStr = Integer.parseInt(str);
                              }
                          } catch (Exception ex) {
                              System.out.println("Exception while pasring a string into integer. " + ex);
                          }
                          return intStr;
                      }
                  
                  }
                  SearchController.java

                  Code:
                   public class SearchController extends SimpleFormController{
                  
                      private HibernateAttachmentTypeModel model = new HibernateAttachmentTypeModel();
                      private SearchFormData searchFormData;
                      public SearchController() {
                          System.out.println("inside SeachController.");
                      }
                  
                  
                      @Override
                      protected Object formBackingObject(PortletRequest request) throws Exception {
                          System.out.println("inside formbacking object method for search controller");
                          SearchFormData data = new SearchFormData();
                          return data;
                  
                      }
                  
                      @Override
                      protected void initBinder(PortletRequest request, PortletRequestDataBinder binder) throws Exception {
                          System.out.println("inside initBinder method for search controller");
                          binder.registerCustomEditor(AttachmentType.class, new AttachmentTypeEditor());
                          SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
                          binder.registerCustomEditor(Date.class, new CustomDateEditor(df, true));
                  
                          binder.registerCustomEditor(Long.TYPE, new CustomLongEditor());
                      }
                  
                      @Override
                      protected ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response) throws Exception {
                          ModelAndView mav = super.handleRenderRequestInternal(request, response);
                  
                          PortletURL url = response.createRenderURL();
                          url.setPortletMode(request.getPortletMode());
                          url.setParameter("action", "add");
                          mav.addObject("addurl", url);
                  
                          url = response.createRenderURL();
                          url.setPortletMode(request.getPortletMode());
                          url.setParameter("action", "list");
                          mav.addObject("listurl", url);
                  
                          return mav;
                  
                      }
                  
                      @Override
                      protected ModelAndView onSubmitRender(RenderRequest request, RenderResponse response, Object command, BindException errors) throws Exception {
                          System.out.println("inside onSubmitRender in searchController.");
                          ModelAndView mav = new ModelAndView();
                           searchFormData = (SearchFormData) command;
                  
                          Collection results = filterResult(command);
                          if (results.size() < 1){
                              errors.reject("not found", "AttachmentTypes are not found");
                              return showForm(request, response, errors);
                          }
                          if (results.size() > 1){
                              mav = new ModelAndView("AttachmentTypeList", "attachmenttypes", results);
                          }
                          if (results.size() == 1){
                            AttachmentType attachmentType =  (AttachmentType) results.iterator().next();
                          mav = new ModelAndView("AddAttachmentType", "attachmenttype", attachmentType);
                          }
                          return mav;
                      }
                  
                      public Collection<AttachmentType> filterResult(Object command){
                          System.out.println("inside filterResults in searchController.");
                          Collection<AttachmentType> collection = new ArrayList<AttachmentType>();
                          searchFormData = (SearchFormData) command;
                          System.out.println("code from search form = "+ searchFormData.getCode());
                          System.out.println("attachmentType.getCode() = " + searchFormData.getCode());
                          System.out.println("timeperiod = " + searchFormData.getTimePeriod());
                          System.out.println("startCreateDate = " + searchFormData.getStartCreateDate());
                          if (!searchFormData.getCode().isEmpty()){
                             model.setAttachmentTypeFilters(HibernateAttachmentTypeModel.AttachmentType_Filters.AttachmentTypeCode, searchFormData.getCode());
                          }else{
                              model.setAttachmentTypeFilters(HibernateAttachmentTypeModel.AttachmentType_Filters.AttachmentTypeCode, null);
                          }
                          if (!searchFormData.getDescription().isEmpty()){
                              model.setAttachmentTypeFilters(HibernateAttachmentTypeModel.AttachmentType_Filters.AttachmentTypeDescription, searchFormData.getDescription());
                          }else{
                              model.setAttachmentTypeFilters(HibernateAttachmentTypeModel.AttachmentType_Filters.AttachmentTypeDescription, null);
                          }
                  
                          if (searchFormData.getGroupId() != null && searchFormData.getGroupId() != 0 ){
                          model.setAttachmentTypeFilters(HibernateAttachmentTypeModel.AttachmentType_Filters.GroupId, searchFormData.getGroupId());
                          }else{
                          model.setAttachmentTypeFilters(HibernateAttachmentTypeModel.AttachmentType_Filters.GroupId, null);
                          }
                          if (searchFormData.getAddedBy() != null && searchFormData.getAddedBy()!= 0){
                          model.setAttachmentTypeFilters(HibernateAttachmentTypeModel.AttachmentType_Filters.AddedBy, searchFormData.getAddedBy());
                          }else{
                          model.setAttachmentTypeFilters(HibernateAttachmentTypeModel.AttachmentType_Filters.AddedBy, null);
                          }
                          if(searchFormData.getModifiedBy() != null && searchFormData.getModifiedBy()!= 0){
                          model.setAttachmentTypeFilters(HibernateAttachmentTypeModel.AttachmentType_Filters.ModifiedBy, searchFormData.getModifiedBy());
                          }else{
                          model.setAttachmentTypeFilters(HibernateAttachmentTypeModel.AttachmentType_Filters.ModifiedBy, null);
                          }
                          if (searchFormData.getStartCreateDate() != null && searchFormData.getTimePeriod().equals("Before")){
                              System.out.println("inside startCreateDate filter.");
                              model.setAttachmentTypeFilters(HibernateAttachmentTypeModel.AttachmentType_Filters.AddedDateBefore, searchFormData.getStartCreateDate());
                          }else{
                              model.setAttachmentTypeFilters(HibernateAttachmentTypeModel.AttachmentType_Filters.AddedDateBefore, null);
                          }
                          collection = model.getAttachmentTypesByFilters();
                          System.out.println("collection.size() = " + collection.size());
                  
                          return collection;
                      }
                  }
                  Thanks,
                  Anita

                  Comment


                  • #24
                    Hi Anita,
                    What I am trying to say is that '/search' must come in the url on form submission.If its not coming that means that ur search.jsp file is not invoking that action at all.Your form in the search page if associated with a submit method then the corresponding action is to be referred.
                    Like
                    <form:form id="searchForm" action="search.do"/"search.htm" method="POST" commandName="searchCommand">
                    I might be wrong coz i havent worked with portlet at all.So If doesnt work like it Please ignore.

                    Comment


                    • #25
                      That's the thing the when form submits and go to success view url doesn't change means /search doesn't come in url. I tried doing the following still url does not change, but if I submit the form I get
                      The requested resource was not found.
                      http://localhost:8080/user/ijus-spida/search.htm

                      <form:form id="searchForm" action="search.htm" method="POST">
                      Even though if I go to the page by clicking on link the url says action=search , but if I try to submit form there the ViewController get called.
                      I'm about to giveup on this.

                      thanks,
                      anita

                      Comment


                      • #26
                        In the 12th post of this thread u had a code like this:

                        <bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
                        <property name="mappings">
                        <props>
                        <prop key="/View">View</prop>
                        <prop key="/AddAttachmentType">AddAttachmentType</prop>
                        <prop key="/search">SearchAttachmentType</prop>
                        </props>
                        </property>
                        </bean>

                        Try giving search.htm here.

                        Comment


                        • #27
                          I've tried that, it says search.htm not found.

                          Comment

                          Working...
                          X