AutoComplete texinput:Struts 2.1.8.1,jsp,ActionClass

时间:2013-01-26 18:56:31

标签: jsp autocomplete struts2

我正在尝试创建自动填充文字输入。

我听说现在最好使用<sj:autocompleter>而不是<sx:autocompleter>,因为dojo已被弃用,但我被卡住了。

我想知道如何在Action类中调用方法并将其显示在JSP上。

我见过其他人在struts.xml中建议从json-default扩展一个包。

我试过,然后我的课不起作用(因为它在不同的包中定义)。

我已将文件剪切为裸露,所以这就是我所拥有的,请帮助:

pom依赖项:

<dependencies>
<!--  Struts 2 -->
<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-core</artifactId>
    <version>2.1.8.1</version>
</dependency>

<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-sitemesh-plugin</artifactId>
    <version>2.1.8.1</version>
</dependency>

<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-spring-plugin</artifactId>
    <version>2.1.8.1</version>
</dependency>

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jsp-api</artifactId>
    <version>2.0</version>
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.0.5</version>
</dependency>

<dependency>
    <groupId>org.apache.ibatis</groupId>
    <artifactId>ibatis-sqlmap</artifactId>
    <version>2.3.0</version>
</dependency>

</dependencies>

完成application-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC 
    "-//SPRING//DTD BEAN//EN" 
    "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:jdbc.properties"/>
    </bean>

    <bean id="baseCarsAction" class="com.microed.cars.web.BaseCarsAction" singleton="false" >
            <property name="carsService" ref="carsService"/>
    </bean>

<bean id="homeAction" class="com.microed.cars.web.HomeAction" singleton="false" parent="baseCarsAction" >
    </bean>

    <bean id="carsService" class="com.microed.cars.business.CarsService" singleton="false" >
        <property name="carsDAO" ref="carsDAO"/>
    </bean>

    <bean id="carsDAO" class="com.microed.cars.dataaccess.CarsDAO" singleton="false" />
</beans>

完成home.jsp(请注意我的评论'我如何在此处获得结果')

    <!DOCTYPE html PUBLIC 
        "-//W3C//DTD XHTML 1.1 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <%@taglib prefix="s" uri="/struts-tags" %>

    <s:form action="index" >
      <s:url id="loginURL" action="login" />
        <div class="row">
            <div class="span4">
            </div>
        </div>

      <div class="transBlock">
        <div class="row">
            <div class="span7 offset1">
                <s:textfield name="searchTags" cssClass="span7" placeholder="%{getText('placeholder.search.home')}" />      
            </div>

            <div class="span2 offset1" title="<s:text name='tooltip.search.keywords'/>" >
                <s:submit key="button.search" method="searchTags" cssClass="btn btn-success span2" id="btnSearch" />        
            </div>

            <!--  after calling getData in action class - how do I display it here? -->
        </div>

      </div>
    </s:form>

完成HomeAction:

package com.microed.cars.web;

import java.sql.SQLException;

public class HomeAction extends BaseCarsAction {
    /** How do I call this when user inputs into a text field? **/
    public void getData() throws SQLException {
    }

    @Override
    public String execute() throws Exception {
        return INPUT;
    }

}

用于注入服务的基本动作类:

package com.microed.cars.web;

import org.springframework.beans.factory.annotation.Required;

import com.microed.cars.business.CarsService;
import com.opensymphony.xwork2.ActionSupport;

public class BaseCarsAction extends ActionSupport {

    protected CarsService carsService;
    protected String searchTags;

    @Required
    public void setCarsService(CarsService carsService) {
        this.carsService = carsService;
    }

}

0 个答案:

没有答案