I wanted to use struts2 with weblogic portal 10 for its cool dojo built in, but BEA havent kept pace with struts open source community(only way you can use struts2 in portal , is as uri portlet). So i was trying to figure out a way to do things similar to dojo autocomplete , i luckily found in some blogs about AJAXTAGS which uses scriptaculous and prototype javascripts.

  1. The chosen technologies where Struts1.2 , Spring , JPA , Hibernate , ajaxtags , scriptaculous and prototype.1.Download ajaxtags from http://ajaxtags.sourceforge.net/

  2. Add the jars downloaded to web-inf lib and add the following to your web.xml for ajaxtags to work

<jsp-config>
    <taglib>
        <taglib-uri>http://ajaxtags.org/tags/ajax</taglib-uri>
        <taglib-location>/WEB-INF/ajaxtags.tld</taglib-location>
    </taglib>
</jsp-config>

3.Import all the required libraries for spring jpa and struts to work.

  1. Add these in web.xml
<filter>
    <filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
    <filter-class>
        org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
    </filter-class>
</filter>
<filter-mapping>
    <filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>
  1. Add the bean class in applicationContext.xml
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
  1. Add the entitymanagerfactory in applicationContext.xml
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
    <beanclass="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    <property name="database" value="MYSQL" />
    <property name="showSql" value="true" />
    </bean>
</property>
</bean>
  1. Add the datasource to applicationContext.xml «figure class=”highlight”><pre><bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost/test" /> <property name="username" value="bobsmith" /> <property name="password" value="bobsmith" /> </bean></pre></figure>

8.Add the transactionmanager to applicationContext.xml

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
  1. Write the pojo , service and serviceimpl lets have a Users pojo , UsersService and UsersServiceImpl10.Write the UsersAction class and extend the BaseAjaxAction (SOURCE is included in download code for this tutorial or download the earlier 1.2 version of ajaxtags-src). In the action access user service layer to get list of users and pass it into the method call getXMLContent.11.Wire your action and service in applicationContext.xml as follows
<bean name="/users" class="UsersAction">
	<property name="UsersService">
	    <ref bean="UsersService" />
	</property>
</bean>
  1. Add this in your struts-config.xml
<action-mappings>
    <action path="/users" type="org.springframework.web.struts.DelegatingActionProxy">
    <forward name="success" path="/username.jsp"></forward>
    </action>
</action-mappings>
<plug-inclassName="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />
</plug-in>
  1. Write a autocomplete.jsp and use the ajax:autocomplete tag as follows
<ajax:autocompletesource="username"target="username"baseUrl="${contextPath}/users.do"className="autocomplete"indicator="throbbing"minimumCharacters="1"/>