我有一个带有两个按钮和几个输入字段的jsf 1.2表单.第一个按钮放弃输入的值,并使用db中的值重新填充页面,第二个按钮保存输入的值.当用户在光标位于其中一个输入字段中时按下enter键,表单被提交并且与第一个按钮相关联的操作被执行时,会出现问题.
代码如下所示:
<h:commandButton action="#{bean.reset}" value="Reset" />
<h:commandButton action="#{bean.save}" value="Save" />
<!-- h:datatable with several h:inputText elements -->
Run Code Online (Sandbox Code Playgroud)
按Enter键是否可以将特定按钮声明为默认操作?这种行为实际上是在某处指定的吗?
在浏览Java 7 API文档时,我偶然发现了新类java.lang.ClassValue,其中包含以下相当少的文档:
懒惰地将计算值与(可能)每种类型相关联.例如,如果动态语言需要为消息发送调用站点遇到的每个类构造消息调度表,则它可以使用a
ClassValue来缓存执行消息快速发送所需的信息,以便遇到每个类.
任何人都可以更好地解释这个类解决了什么问题,也许还有一些示例代码或已经使用过该类的开源项目?
更新:我仍然对使用这个新类的一些实际源代码或示例感兴趣.
我还在mlvm-dev邮件列表上找到了关于一些实现改进的邮件.显然,从使用WeakHashMap变为java.lang.Class上的新私有字段,使其更具可伸缩性.
在具有多个ClassLoader的环境中使用ServiceLoader的最佳实践是什么?文档建议在初始化时创建并保存单个服务实例:
private static ServiceLoader<CodecSet> codecSetLoader = ServiceLoader.load(CodecSet.class);
Run Code Online (Sandbox Code Playgroud)
这将使用当前上下文类加载器初始化ServiceLoader.现在假设此片段包含在使用Web容器中的共享类加载器加载的类中,并且多个Web应用程序想要定义自己的服务实现.这些不会在上面的代码中被提取,甚至可能使用第一个webapps上下文类加载器初始化加载器并向其他用户提供错误的实现.
始终创建新的ServiceLoader似乎是浪费性能,因为它必须每次枚举和解析服务文件.编辑:这甚至可能是一个很大的性能问题,如关于java的XPath实现的答案所示.
其他库如何处理这个?他们是否为每个类加载器缓存实现,他们是否每次都重新分析它们的配置,还是只是忽略了这个问题而只适用于一个类加载器?
我有一个类从第三方源解组xml(我无法控制内容).这是解组的片段:
JAXBContext jContext = JAXBContext.newInstance("com.optimumlightpath.it.aspenoss.xsd");
Unmarshaller unmarshaller = jContext.createUnmarshaller() ;
StringReader xmlStr = new StringReader(str.value);
Connections conns = (Connections) unmarshaller.unmarshal(xmlStr);
Run Code Online (Sandbox Code Playgroud)
Connections是使用xjc生成的dtd-> xsd->类的类.该包com.optimumlightpath.it.aspenoss.xsd包含所有这些类.
我收到的xml包含DOCTYPE中的相对路径.基本上str.value上面包含:
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE Connections SYSTEM "./dtd/Connections.dtd">
<Connections>
...
</Connections>
Run Code Online (Sandbox Code Playgroud)
这作为java 1.5应用程序成功运行.为了避免上面的错误,我不得不在项目根目录下创建一个./dtd目录并包含所有dtd文件(不知道为什么我必须这样做但我们会这样做).
我已经在Tomcat5.5上创建了一个使用上述类的Web服务.我正在进入[org.xml.sax.SAXParseException: Relative URI "./dtd/Connections.dtd"; can not be resolved without a document URI.]unmarshal线.我尝试在每个relavant文件夹(项目根目录,WebContent,WEB-INF,tomcat工作目录等)中创建./dtd无济于事.
问题1:我在哪里可以找到./dtd,以便在作为tomcat webservice运行时,类可以找到它?我需要做什么tomcat或服务配置才能识别目录?
问题2:为什么该类甚至首先需要dtd文件?它是否具有在dtd-> xsd->类的注释中解组所需的所有信息?我已经阅读了很多关于禁用验证,设置EntityResource和其他解决方案的帖子,但是这个类并不总是作为Web服务部署,我不想有两个代码序列.
给定以下代码框架,是否可以确定该属性foo实际上是类型String?
public class TestIntrospection {
public static class SuperBean<T> {
private T foo;
public T getFoo() { return foo; }
public void setFoo(T foo) { this.foo = foo; }
}
public static class SubBean extends SuperBean<String> {
}
public static void main(String[] args) throws IntrospectionException {
BeanInfo beanInfo = Introspector.getBeanInfo(SubBean.class);
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor prop : propertyDescriptors) {
if ("foo".equals(prop.getName())) {
System.out.printf("%s of %s\n", prop.getName(), prop.getPropertyType());
Method readMethod = prop.getReadMethod();
Type returnType = prop.getReadMethod().getGenericReturnType(); …Run Code Online (Sandbox Code Playgroud) 我经常使用类似的模式创建SimpleDateFormat,HH:mm:ss或者yyyy-MM-dd以区域设置独立的方式输出日期.由于还有一个构造函数采用了额外的语言环境参数,我想知道是否存在这样的格式可能依赖于语言环境的情况,或者我是否应该始终指定Locale.ENGLISH或Locale.GERMANY.让我们假设时区是明确设置的.
在阅读HTML5 IndexedDB规范时,我对其异步请求模型有一些疑问.查看请求api示例时,该open方法用于启动异步请求.
var request = indexedDB.open('AddressBook', 'Address Book');
request.onsuccess = function(evt) {...};
request.onerror = function(evt) {...};
Run Code Online (Sandbox Code Playgroud)
在此请求启动时,尚未定义事件处理程序.
open在javascript解释器执行赋值之前方法成功时会发生什么onsuccess?在我看来,像下面这样的api会更合乎逻辑:
db.open('AddressBook', 'Address Book', {
onsuccess: function(e) { ... },
onerror : function(e) { ... }
});
Run Code Online (Sandbox Code Playgroud) 注意:我找不到这个问题的直接答案,所以我将在下面记录我的解决方案作为答案.
我使用Axis 1.4和wsdl从wsdl生成了web服务的服务器端部分axistools-maven-plugin.Axis servlet映射到/services/*,服务配置WEB-INF/server-config.wsdd如下:
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="TestService" style="document" use="literal">
<namespace>http://example.com/testservier</namespace>
<parameter name="className" value="com.example.TestServiceImpl"/>
<parameter name="allowedMethods" value="*"/>
<parameter name="scope" value="Session"/>
</service>
</deployment>
Run Code Online (Sandbox Code Playgroud)
当我将此Web应用程序部署到Tomcat并http://localhost:8080/testservice/services返回访问
已部署服务的列表时.
现在......一些服务
- TestService(wsdl)
- TestService的
单击wsdl应该返回此服务的描述,但会导致以下错误页面:
AXIS错误
无法生成WSDL!
此位置没有SOAP服务
我有一个maven项目设置.
在我的maven POM文件中,它定义如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.myProject</groupId>
<artifactId>basePOM</artifactId>
<version>1.0</version>
<relativePath>../../../shared/common/pom.xml</relativePath>
</parent>
<groupId>com.myProject.services</groupId>
<artifactId>orderservice</artifactId>
<version>developer</version>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!--Internal dependencies-->
<dependency>
<groupId>com.myProject.shared</groupId>
<artifactId>model</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-spring</artifactId>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
我有一个父POM定义了一些常见的位:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>Base POM</name>
<groupId>com.myProject</groupId>
<artifactId>basePOM</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.myProject.shared</groupId>
<artifactId>model</artifactId>
<version>developer</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>1.2.GA</version>
<exclusions>
<exclusion> …Run Code Online (Sandbox Code Playgroud) 我在postgres中定义了以下嵌套类型:
CREATE TYPE address AS (
name text,
street text,
zip text,
city text,
country text
);
CREATE TYPE customer AS (
customer_number text,
created timestamp WITH TIME ZONE,
default_billing_address address,
default_shipping_address address
);
Run Code Online (Sandbox Code Playgroud)
现在想在存储过程中填充这些类型,它将json作为输入参数.这适用于顶级字段,输出显示postgres复合类型的内部格式:
# select json_populate_record(null::customer, '{"customer_number":"12345678"}'::json)::customer;
json_populate_record
----------------------
(12345678,,,)
(1 row)
Run Code Online (Sandbox Code Playgroud)
但是,postgres不处理嵌套的json结构:
# select json_populate_record(null::customer, '{"customer_number":"12345678","default_shipping_address":{"name":"","street":"","zip":"12345","city":"Berlin","country":"DE"}}'::json)::customer;
ERROR: malformed record literal: "{"name":"","street":"","zip":"12345","city":"Berlin","country":"DE"}"
DETAIL: Missing left parenthesis.
Run Code Online (Sandbox Code Playgroud)
再次起作用的是,如果嵌套属性是postgres的内部格式,如下所示:
# select json_populate_record(null::customer, '{"customer_number":"12345678","default_shipping_address":"(\"\",\"\",12345,Berlin,DE)"}'::json)::customer;
json_populate_record
--------------------------------------------
(12345678,,,"("""","""",12345,Berlin,DE)")
(1 row)
Run Code Online (Sandbox Code Playgroud)
有没有办法让postgres从嵌套的json结构转换为相应的复合类型?
java ×5
action ×1
asynchronous ×1
axis ×1
classloader ×1
datetime ×1
default ×1
dtd ×1
enter ×1
form-submit ×1
generics ×1
html5 ×1
java-7 ×1
javabeans ×1
javascript ×1
jaxb ×1
jsf ×1
json ×1
maven-2 ×1
postgresql ×1
web-services ×1
xml ×1