我有啊:selectOneMenu,其中填充了枚举值,工作正常.唯一的问题是,当没有选择有效值时,我不知道如何覆盖标准的JSF错误消息.错误消息总是bv:title: 'Choose' must be convertible to an enum from the enum that contains the constant 'Choose'.
虽然我已经指定了requiredmessage和validatormessage(适用于InputText),但只显示标准的JSF消息.
片段:
<h:selectOneMenu id="title" value="#{personBean.person.title}" required="true"
requiredMessage="ERROR"
validatorMessage="ERROR">
<f:selectItem itemValue="Choose" />
<f:selectItems value="#{personBean.titleOptions}" />
<f:ajax event="blur" render="titleError" />
<f:validateRequired/>
</h:selectOneMenu>
<h:message for="title" errorClass="invalid" id="titleError" />
Run Code Online (Sandbox Code Playgroud)
如何覆盖标准验证器消息?或者更好 - 我可以创建带有自定义错误消息的JSF messages.properties的副本(不想再次在我自己的messages.properties中定义所有错误)吗?
我想在Scala中创建一个特定的泛型方法.它需要两个参数.第一种是通用Java接口的类型(它来自JPA条件查询).它目前看起来像这样:
def genericFind(attribute:SingularAttribute[Person, _], value:Object) {
...
}
// The Java Interface which is the type of the first parameter in my find-method:
public interface SingularAttribute<X, T> extends Attribute<X, T>, Bindable<T>
Run Code Online (Sandbox Code Playgroud)
现在我想实现以下目的: value当前是java.lang.Object类型.但我想让它更具体.值必须与第一个参数中的占位符"_"具有相同的类型(因此代表Java接口中的"T").
这是不可能的,怎么样?
BTW对不起这个愚蠢的问题标题(有什么建议吗?)
编辑: 添加了一个可以使问题更清晰的附加示例:
// A practical example how the Scala method could be called
// Java class:
public class Person_ {
public static volatile SingularAttribute<Person, Long> id;
}
// Calling the method from Scala:
genericFind(Person_.id, Long)
Run Code Online (Sandbox Code Playgroud) 在我的文档中,我使用包词汇表来创建词汇表。一切正常,除了文本中的单词与我的词汇表中的相应条目之间没有链接(因此您可以单击要解释的单词并进入词汇表条目)。
我的文档中最重要的部分:
%----Header----
...
\usepackage[nonumberlist,acronym,toc,style=altlist]{glossaries}
\usepackage[
colorlinks=true,
pdfborder=0 0 0,
pdfpagelabels,
plainpages=false,
linktocpage=false,
pdfcreator={LaTeX}]{hyperref}
...
%Glossary entries
\newglossaryentry{glos:twitter}{name=Twitter,
description={Mikroblogging-Service.}}
%----Main document----
\begin{document}
\chapter{Introduction}
This text is a normal glossary item: \gls{glos:twitter}.
This text should also link to the glossary item: \glslink{glos:twitter}{Link to Twitter}
but there is no link
...
\printglossary
\end{document}
Run Code Online (Sandbox Code Playgroud)
如您所见,我也在使用 hyperref 包,但似乎没有自动将正文中的单词链接到词汇表的机制。我也尝试使用\ref 和\label,但是当被引用的元素在主文档之外(就像我的词汇表一样)时,这不起作用。我正在使用来自 miktex 的 makeglossaries 脚本(调用makeglossaries main构建),但这也没有给我一个链接。
有人知道这样做的方法吗?或者也许我应该使用支持类似功能的词汇表之外的另一个包?
我也很感激任何可以使用此功能的工作示例。
编辑:
我刚刚得到了一个工作最小的例子,其中 gls/glslink 实际工作。似乎术语表项目的链接干扰了我在我的文档中使用的包之一。将不得不通过将我的包一一添加到示例中来尝试查看哪个包是原因。这个例子:
\listfiles
\documentclass{article}
\usepackage[
colorlinks=true,
pdfborder=0 0 0,
pdfpagelabels,
plainpages=false,
linktocpage=false,
pdfcreator={LaTeX}]{hyperref}
\usepackage[nonumberlist,acronym,toc,style=altlist,]{glossaries} …Run Code Online (Sandbox Code Playgroud) 在我的Java EE 6-webapp(运行在最新的GlassFish 3.1上)中,我正在使用JSF2-ManagedBeans并将@ManagedProperty它们注入到其他ManagedBeans中.现在我想知道我是否也可以注入@ManagedBean一个@WebServlet,使用@ManagedProperty.一些代码:
@WebServlet(name = "vdd")
public class VddServlet extends HttpServlet
{
@ManagedProperty(value = "#{userIdentity}")
private UserIdentity identity;
}
Run Code Online (Sandbox Code Playgroud)
ManagedBean看起来像这样:
@ManagedBean
public class UserIdentity
{
...
}
Run Code Online (Sandbox Code Playgroud)
这样工作吗?如果没有,我有什么其他方法将ManagedBean注入WebServlet(没有CDI,目前不是一个选项 - 因为GF 3.1 B32/33与OSGi-Java EE-apps结合存在一些问题,但我们时间不长)?
我正在使用pysvn来监视Subversion目录中的更改.这是我从修订版中获取信息的方式:
(...)
svn_root = "http://svn/"
client = pysvn.Client()
from_revision = pysvn.Revision(pysvn.opt_revision_kind.number, 1500)
to_revision = pysvn.Revision( pysvn.opt_revision_kind.head )
revisions = client.log(svn_root, to_revision, to_revision, discover_changed_paths=True)
Run Code Online (Sandbox Code Playgroud)
现在,我想从一个特定的修订版本什么变化不一样,在我的例子,但在过去5次修订中的变化(从head - 5到head).我怎么能做到这一点?我如何获得头部修订的NUMBER?
我可以通过从Python调用Shell来实现.但我想使用pysvn有一种"Pythonic"方式.
我正在尝试构建一个(几乎)独立于平台的 SWT Maven 原型来构建 SWT 应用程序。它应该根据平台自动下载所需的 SWT 库。到目前为止,这是我的pom:
<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>
<groupId>de.mackaz</groupId>
<artifactId>swttest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<swt.version>3.7</swt.version>
</properties>
<dependencies>
<dependency>
<groupId>${swt.groupId}</groupId>
<artifactId>${swt.artifactId}</artifactId>
<version>${swt.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<debug>true</debug>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>mac</id>
<activation>
<os>
<name>mac os x</name>
</os>
</activation>
<properties>
<swt.groupId>org.eclipse.swt.carbon</swt.groupId>
<swt.artifactId>macosx</swt.artifactId>
</properties>
</profile>
<profile>
<id>windows</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<properties>
<swt.groupId>org.eclipse.swt.win32.win32</swt.groupId>
<swt.artifactId>x86</swt.artifactId>
</properties>
</profile>
<profile>
<id>linux</id>
<activation>
<os>
<family>linux</family>
</os>
</activation>
<properties>
<swt.groupId>org.eclipse.swt.gtk.linux</swt.groupId>
<swt.artifactId>x86_64</swt.artifactId>
</properties>
</profile> …Run Code Online (Sandbox Code Playgroud) 我的python脚本(Python 2.6,在Debian Linux上)要求用户输入密码,然后将其保存在用户主目录中.
因为我不想将密码作为纯文本保护,我想以某种方式加密它.所以我想也许我可以使用用户的(私有)ssh-key来加密和解密保存在文件中的密码,这样只有一个访问私有ssh密钥的人才能解密保存的密码.
为此使用私有ssh密钥是个好主意吗?如何在python中使用密钥加密字符串?
(顺便说一句,我不想使用密钥环和类似的东西)
编辑
好吧,我理解使用用户ssh密钥这样的东西是个坏主意.相反,我现在只使用base64编码,如下所述: 如何使用Python对字符串进行编码和解码以在URL中使用? 当有人读我的python脚本时,当然不能保存.但它对我来说足够了,不必将密码保存为纯文本.
我正在使用Embedded Glassfish用Arquillian进行一些In-Container-Tests.现在,当我的测试失败时,我总是从那些混杂着Arquillian特定内容的测试中获得堆栈跟踪.但关于失败测试的真正原因是什么的信息很少.使用常规Glassfish,我可以检查server.log以获取更多信息.不幸的是,Embedded Glassfish似乎没有提供Server.log.我还查看了由Arquillian/Embedded Glassfish创建的临时目录,但它不包含任何日志文件.
如何在Embedded Glassfish中激活日志记录?
顺便说一下,我的pom中有以下依赖项:
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-embedded-3</artifactId>
<version>1.0.0.Alpha4</version>
</dependency>
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1-b06</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-testng</artifactId>
<version>1.0.0.Alpha4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud) 我正在编写一个在 Bash 终端内运行的 Python 程序(并且它已经依赖于 Bash 作为其环境)。我有一个小设置例程,它要求用户提供位于其文件系统上的目录。这就是我读取输入的方式:
print "Input:",
input = sys.stdin.readline().strip()
Run Code Online (Sandbox Code Playgroud)
现在我希望用户能够使用现有文件或目录的名称自动完成输入。最好的方法是什么?我是否需要自己查找目录/文件并使用该包cmd(如本例所示)?或者是否有更简单的“内置”方法来做到这一点?
如果我能够在 os.system 中使用 Bash 自动完成功能,那就没问题了。但到目前为止我尝试的一切都没有成功。这是我尝试过的:
os.system("read -e -p \"Input:\" INPUT")
Run Code Online (Sandbox Code Playgroud)
但这很奇怪:Bash 抱怨read: 1: Illegal option -e,尽管该命令在简单的 Bash 脚本内运行。但我需要 -e 修饰符来完成。
对于如何在 Python 控制台程序中自动完成文件/目录名有什么建议吗?
我有一个大型 Django 应用程序,其中包含大量需要 SQL 查询优化的测试。
我正在使用 pytest-django 来运行我的测试。
我不想单独添加assertNumQueries或django-assert-num-queries针对每个测试,而是生成有关所有测试中的每个测试触发了多少 SQL 查询的概述,以了解哪些代码需要最优化,如下所示:
test | number of queries
------------------------------------------------
test_a.py::test_my_function1 | 5
test_a.py::test_my_function3 | 2
test_a.py::test_my_function5 | 7
Run Code Online (Sandbox Code Playgroud)
是否可以在 conftest.py 中配置一个 pytest 钩子,它计算每个 (DB) 测试的 SQL 查询数量并在结果中显示它们 - 无需修改我的测试源(如添加装饰器)?
我天真的方法是使用这些钩子,并以某种方式在每次测试前后访问数据库连接:
def pytest_runtest_call(item):
pass
def pytest_runtest_teardown(item, nextitem):
return True
Run Code Online (Sandbox Code Playgroud)