我们有时候希望回车键敲在文本框(input element)里来提交表单(form),但有时候又不希望如此。比如搜索行为,希望输入完关键词之后直接按回车键立即提交表单,而有些复杂表单,可能要避免回车键误操作在未完成表单填写的时候就触发了表单提交。
要控制这些行为,不需要借助JS,浏览器已经帮我们做了这些处理,这里总结几条规则:
1、如果表单里有一个type=”submit”的按钮,回车键生效。
2、如果表单里只有一个type=”text”的input,不管按钮是什么type,回车键生效。
3、如果按钮不是用input,而是用button,并且没有加type,IE下默认为type=button,FF默认为type=submit。
4、其他表单元素如textarea、select不影响,radio checkbox不影响触发规则,但本身在FF下会响应回车键,在IE下不响应。
5、type=”image”的input,效果等同于type=”submit”,不知道为什么会设计这样一种type,不推荐使用,应该用CSS添加背景图合适些。
实际应用的时候,要让表单响应回车键很容易,保证表单里有个type=”submit”的按钮就行。而当只有一个文本框又不希望响应回车键怎么办呢?我的方法有点别扭,就是再写一个无意义的文本框,隐藏起来 但是如果设置了submit tabindex=0,则会提交 。根据第3条规则,我们在用button的时候,尽量显式声明type以使浏览器表现一致。
ServiceMix环境配置
配置使用的ServiceMix版本是servicemix-3.3,在tomcat5.5以上运行。(因为依赖包大部分是需要jdk1.5)
ServiceMix有三种部署方式:单独程序方式,servlet方式,与Geronimo and JBoss.整合方式。这里主要介绍servlet方式,因为这样可以整合到任何servlet容器中。
Servlet部署需要在web.xml中配置spring加载文件,这种spring是和xbean整合的自定义配置文件。
配置文件说明:
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>ServiceMix Web Application</display-name>
<description>Deploys ServiceMix inside a Web Application</description>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/jmx.xml /WEB-INF/core.xml /WEB-INF/activemq.xml</param-value>
</context-param>
Spring配置文件
<context-param>
<param-name>contextClass</param-name>
<param-value>org.apache.xbean.spring.context.XmlWebApplicationContext</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Spring 监听器
<!-- servlet mappings -->
<!-- the main JMX servlet -->
<servlet>
<servlet-name>JMXServlet</servlet-name>
<servlet-class>org.apache.servicemix.web.jmx.JMXServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- the HTTP binding servlet -->
<!-- START SNIPPET: servicemix-http-->
<servlet>
<servlet-name>HttpManagedServlet</servlet-name>
<servlet-class>
org.apache.servicemix.http.HttpManagedServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
http bean组件(BC)servlet
<servlet-mapping>
<servlet-name>HttpManagedServlet</servlet-name>
<url-pattern>/jbi/*</url-pattern>
</servlet-mapping>
<!-- END SNIPPET: httpBinding -->
<servlet-mapping>
<servlet-name>JMXServlet</servlet-name>
<url-pattern>/jmx/*</url-pattern>
</servlet-mapping>
</web-app>
demo主要功能的配置在core.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
xmlns:http="http://servicemix.apache.org/http/1.0"
xmlns:my="http://servicemix.apache.org/demo/"
xmlns:foo="http://servicemix.apache.org/demo/">
<!-- the JBI container -->
<sm:container id="jbi"
rootDir="#rootDir"
useMBeanServer="true"
createMBeanServer="false"
MBeanServer="#jmxServer"
installationDirPath="#installDir"
deploymentDirPath="#deployDir"
monitorInstallationDirectory="true"
transactionManager="#transactionManager"
depends-on="broker">
<sm:activationSpecs>
<!-- an example HTTP binding for use by the SpringBindingServlet -->
<!-- START SNIPPET: http -->
<sm:activationSpec componentName="servicemix-http" service="foo:httpBinding" destinationService="foo:echo">
<sm:component>
<http:component>
<http:configuration managed="true" />
<http:endpoints>
<http:endpoint service="foo:httpBinding"
endpoint="endpoint"
targetService="foo:echo"
role="consumer"
locationURI="http://localhost/exampleUri/
配置url, 会被tomcat自动转换为serverapp/jbi/ exampleUri
"
defaultMep="http://www.w3.org/2004/08/wsdl/in-out
消息请求方式是in-out,即期望又返回消息
" />
</http:endpoints>
</http:component>
</sm:component>
</sm:activationSpec>
使用http BC,作为一个消费者(consumer)目标指向服务引擎(SE)foo:echo
<!-- END SNIPPET: http -->
<!-- a simple Echo service to test InOut message exchanges using HTTP-->
<sm:activationSpec componentName="echo" service="foo:echo" >
<sm:component>
<bean class="org.apache.servicemix.components.HelloWorldComponent">
<property name="property" value="name"/>
</bean>
</sm:component>
</sm:activationSpec>
SE foo:echo,这是一个简单的helloworld
</beans>
经过这样的配置和在web.xml中配置的servlet,那么uri pattern形如 /jbi/exampleUri会请求foo:httpBinding (BC),在ESB内部foo:httpBinding通过消息路由(normalized message router)与foo:echo通信。
Web测试页面链接为http://localhost:(tomcat端口)/ESB-ServerMix-Web/examples/
需要在firefox下测试。
测试页面使用ajax请求/jbi/exampleUri经过foo:httpBinding, foo:echo处理返回信息。
Continue reading ServiceMix环境配置