Announcement Announcement Module
Collapse
No announcement yet.
Form submit using spring portlet Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Form submit using spring portlet

    Hi, Greetings!!

    I want to perform the following:

    I have a spring login portlet with just user id and password text fields and a submit button. Upon clicking submit button, i would like to take the entered data in text fields , pass it to back end and verify that whether the entered data exists in DB. If so, allow him to go to home page. Otherwise display a error message.

    How can i do that? Here is my html code:

    Code:
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    <%@ taglib prefix="portlet" uri="http://java.sun.com/portlet" %>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
       
    <portlet:defineObjects/>
    
    <portlet:actionURL var="aURL">
    	<portlet:param name="doThis" value="home"/>
    </portlet:actionURL>
    
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>MoSoNex</title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    </head>
    <body>
    
    <h3>SignUp for ABC</h3>
    <form:form commandName="login" method="post" action="${aURL}">
    	<table cellpadding="4">
    		<tr>
                        <td>ABC Id : </td>
                        <td><input type="text" size="25" maxlength="30"/></td>
    		</tr>
                     <tr>
                        <td>Password : </td>
                        <td><input type="text"  size="25" maxlength="30"/></td>
    		</tr>
    		<tr>
                        <td><input type="submit" name="_login" value="Login"  onclick="window.location.href='${aURL}';"/></td>
                        <!--<td><input type="submit" name="_cancel" value="Cancel"/></td>-->
    		</tr>
    	</table>
    </form:form>
    </body>
    </html>

    Here is my portlet.xml

    Code:
    <?xml version='1.0' encoding='UTF-8' ?>
    <portlet-app xmlns='http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd' version='2.0'>
        
            <portlet>
    		<description>ABCPortlet</description>
    		<portlet-name>ABCPortlet</portlet-name>
    		<display-name>ABCPortlet</display-name>
    		<portlet-class>com.test.ABCPortlet</portlet-class>
    		<expiration-cache>0</expiration-cache>
    		<supports>
    			<mime-type>text/html</mime-type>
    			<portlet-mode>VIEW</portlet-mode>
    			<portlet-mode>EDIT</portlet-mode>
    			<portlet-mode>HELP</portlet-mode>
    		</supports>
    		<portlet-info>
    			<title>ABCPortlet</title>
    			<short-title>ABCPortlet</short-title>
    		</portlet-info>
    	</portlet>
            
     <!--       <portlet>   
                <portlet-name>dispatcher</portlet-name>
                <portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
               
                <supports>
                    <mime-type>text/html</mime-type>
                    <portlet-mode>view</portlet-mode>                                            
                    <portlet-mode>edit</portlet-mode>       
                    <portlet-mode>help</portlet-mode>
                </supports>
                <portlet-info>
                    <title>Sample Portal</title>
                    <short-title>Sample</short-title>                
                </portlet-info>
                
            </portlet>
    -->
            <container-runtime-option>
                <name>javax.portlet.escapeXml</name>
               <value>false</value>
            </container-runtime-option>
            
    </portlet-app>
    My ABCPortlet-portlet.xml looks something like below:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
               
           <bean id="parameterMappingInterceptor"
                class="org.springframework.web.portlet.handler.ParameterMappingInterceptor">
                <property name="parameterName" value="doThis" />
            </bean>
        
               
           <bean id="portletModeParameterHandlerMapping"
                class="org.springframework.web.portlet.handler.PortletModeParameterHandlerMapping">
              <property name="order" value="1" />
    
    
              <property name="interceptors">
                <list>
                  <ref bean="parameterMappingInterceptor"/>
                </list>
              </property>
              <property name="portletModeParameterMap">
                <map>
                  <entry key="view">
                    <map>
                      <entry key="login"
                           value-ref="loginController1"/>
                      <entry key="home"
                           value-ref="homeController"/>
                      <entry key="regsuccess"
                           value-ref="regSuccessController"/>                  
                    </map>
                  </entry>
                  <entry key="edit">
                    <map/>
                  </entry>
                  <entry key="help">
                    <map/>
                  </entry>
                </map>
              </property>
            </bean>
    
              
           <bean id="portletModeHandlerMapping"
                class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
              <property name="order" value="2" />
              <property name="portletModeMap">
                <map>
                  <entry key="view"
                      value-ref="loginController"/>
                  <entry key="help"
                      value-ref="modeNameViewController"/>
                  <entry key="edit"
                      value-ref="regSuccessController"/>
                 </map>
              </property>
         </bean>
     
            
            
           <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="prefix">
    			<value>/WEB-INF/jsp/</value>
    		</property>
    		<property name="suffix">
    			<value>.jsp</value>
    		</property>
    	</bean>
    	
    	<bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
    		<property name="exceptionMappings">
    			<props>
    				<prop key="java.lang.Exception">error</prop>
    			</props>
    		</property>	
    	</bean>
       	
            
            <bean id="modeNameViewController"
                class="org.springframework.web.portlet.mvc.PortletModeNameViewController"/>
    
    
            
    	<bean id="DataCon" class="com.mosonex.portal.services.DataConImpl">
    		<property name="dataSource" ref="dataSource"/>
            </bean>
       
       	<bean id="Registration" class="com.mosonex.portal.services.RegistrationImpl">
       		<property name="dataSource" ref="dataSource"/>
       		<property name="mailSender" ref="mailSender"/>
       		<property name="mailMessage" ref="mailMessage" />
            </bean>
    	
    	<bean name="homeController" class="com.mosonex.portal.controller.HomePageController">
    		<property name="regService" ref="Registration"/>		
    	</bean>
    	
    	<bean name="regSuccessController" class="com.mosonex.portal.controller.RegistrationSuccessController">
    		<property name="regService" ref="Registration"/>		
    	</bean>
    	
    	<bean name="loginController" class="com.mosonex.portal.controller.LoginPageController">
    		<property name="regService" ref="Registration"/>		
    	</bean>
         
            <bean name="loginController1" class="com.mosonex.portal.controller.SampleFormController">
    				
    	</bean>
        
    </beans>
    and the SampleFormController is as below:

    Code:
    package com.mosonex.portal.controller;
    
    import javax.portlet.ActionRequest;
    import javax.portlet.ActionResponse;
    import org.springframework.validation.BindException;
    import org.springframework.web.portlet.mvc.SimpleFormController;
    /**
     *
     * @author root
     */
    public class SampleFormController extends SimpleFormController{
    
    	
        @Override
        protected void onSubmitAction(ActionRequest request, ActionResponse response, 
        Object command, BindException errors) throws Exception {
                        response.setRenderParameter("action", "home");
        }
    }
    Can somebody help me to to achieve what i mentioned in the beginning of this post.?

    IT's very urgent and i spent nearly 2 complete days on it without any success.

    ANy help in this regard is highly appreciated.

    Regards.

  • #2
    Hi,

    I have a spring login portlet with just user id and password text fields and a submit button. Upon clicking submit button, i would like to take the entered data in text fields , pass it to back end and verify that whether the entered data exists in DB. If so, allow him to go to home page. Otherwise display a error message.
    Login is something that is normally handled by your portal. It will have some way of handling authentication, which you can most likely customize. How you customize/integrate with this is a portal specific question and should be directed to the support channels for your portal.

    What problems are you encountering with your Spring portlet? What behaviour are you getting, are there any errors? Looking briefly at your code:

    1) What is com.test.ABCPortlet? You haven't posted any code for this. Is is a subclass of the Spring DispatcherPortlet?

    2) You have mixed use of the parameter name used by the portletModeParameterHandlerMapping - in your JSP and interceptor you call it "doThis", in your SimpleFormController you use "action". Furthermore, you haven't set the parameterName property on the portletModeParameterHandlerMapping so it will default to using "action".

    Chris

    Comment


    • #3
      Thanks for the info.

      ABCPortlet is subclass of GenericPortlet.

      I haven't declared DispatchePortlet anywhere. May be that's causing the error?

      To be honest, i'm new to spring and portlet technology. I just bought book 'SPring In Action' by manning publication and i'm doing the development.

      PLease take time to read the following and answer me whatever you think useful to me.

      We are using jetspeed as the portal server, tomcat 5.5.23 as the application server on linux Fedora 9 platform. I tried using eclipse 3.4 (ganymede) version for developing the portal. BUt even after installing plugins, when i do File -> New Project -> Other, it doesn't show up any portlet project. SO i'm stuck here.

      After little bit of search in the net, i found GlassFIsh with SUn's open portal container and net beans help to develop a portal project. It did. BUt i had trouble deploying it on the jetspeed.

      I spend almost 10 complete days in setting up the workspace with no luck.

      If somebody can help me in setting up my workspace for portal development using spring framework 2.5.5 , i will be grateful to them.

      So, pls help me to develop a spring portal project using eclipse.

      Also, as you mentioned, how can i reuse the default login page of the jetspeed portal for my portal?

      Thank you so much. All your help is highly appreciated.

      Comment

      Working...
      X