这是一个简单的来源,声明此日期必须使用Bean验证过去:
@Past
private Date transactionDate;
Run Code Online (Sandbox Code Playgroud)
是否有BV注释用于验证日期必须是今天还是前一天?
或许我需要扩展约束并提供我自己的约束?
谢谢 !
我目前正在尝试将记录的ID从一个页面发送到另一个页面.
所以在第1页中,我有这样的事情:
<p:column>
<h:link value="#{rpb.map['transNum']}" outcome="TInput.xhtml">
<f:param name="id" value="#{rpb.map['id']}" />
</h:link>
</p:column>
Run Code Online (Sandbox Code Playgroud)
在目标页面(TInput.xhtml)中,我有类似的东西来捕获id:
....
xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<f:metadata>
<f:viewParam name="id" value="#{tInputBean.id}"></f:viewParam>
</f:metadata>
<h:head>
....
Run Code Online (Sandbox Code Playgroud)
现在,单击链接,转到第2页,第2页由一个视图范围的jsf bean处理.从我的调试来看,这是发生的顺序:
我想要实现的是: 在更新模型之后,我想对该记录id执行查询,获取它的bean以及它来自Business Service的详细信息列表.
我想知道我应该在哪里放置我的查询代码:
请赐教:)
只是一个基本需求,但无法让它工作.我想有一个primefaces按钮来显示我的图像,没有任何文字.
但我得到的是一个只包含一个^字符而不显示图像的按钮,其尺寸仅为16x16.
所以,这是primefaces按钮:
<p:commandButton image="ui-icon-csv" title="CSV Document" ajax="false">
<p:dataExporter type="csv" target="gridRPBDetails"
fileName="#{tInputBean.exportFilename}" />
</p:commandButton>
Run Code Online (Sandbox Code Playgroud)
这是css文件:
.ui-icon-csv {
background-image: url(images/csv_small.png);
}
Run Code Online (Sandbox Code Playgroud)
这是按钮生成的html:
<button type="submit" onclick=";"
name="gridRPBDetails:j_idt82" id="gridRPBDetails:j_idt82"
class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary"
role="button" aria-disabled="false">
<span class="ui-button-icon-primary ui-icon ui-icon-csv"></span><span class="ui-button-text">CSV Document</span>
</button>
Run Code Online (Sandbox Code Playgroud)
为了证明图像可以访问,我尝试这个URL,实际上它显示了图片:
http://albert:8080/mywebapp/faces/javax.faces.resource/images/csv_small.png
Run Code Online (Sandbox Code Playgroud)
我使用tomcat 7,这些是我的依赖:
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.4-b09</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.4-b09</version>
<scope>compile</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
出了什么问题?
谢谢 !
我目前正在尝试使用bean验证提供自定义验证消息.
目前使用spring mvc 3.1.1 + apache bean验证.
在我的bean中,我指定:
@Size(min=1, max=50)
private String title;
Run Code Online (Sandbox Code Playgroud)
在我的messages.properties中:
Size.addForm.title=The title must not be empty and must not exceed {1} characters.
Run Code Online (Sandbox Code Playgroud)
从实验中我发现:
并且它将显示为The title must not be empty and must not exceed 50 characters.正确的.
但所有这些都来自实验.我想知道是否有文件说明默认约束的参数顺序?
我希望使用Size.addForm.title=The title must not be empty and must not exceed {max} characters.基于默认ValidationMessages.properties的方法,但最终会使用NumberFormatException {max}.我认为它与插值有关?
因此,每个都在NumberFormatException上独立失败{max}:
我尝试使用以下类似的方法处理分组选择:
<h:selectOneMenu value="#{selectionLabBean.oneSelectMenuGroup}"
id="SelectOneMenuGroup" >
<f:selectItems value="#{selectionLabBean.heroGroupList}" />
</h:selectOneMenu>
<p:message for="SelectOneMenuGroup" />
Run Code Online (Sandbox Code Playgroud)
heroGroupList是这样的:
SelectItem[] heroArr = new SelectItem[] {
new SelectItem("Paladin"),
...
};
heroListWithGrouping.add(
new SelectItemGroup("Human",
"A collection of human race Heroes",
false,
heroArr
)
);
.....
Run Code Online (Sandbox Code Playgroud)
而且我想知道我是否可以使用POJO而不是SelectItem对象进行这种分组?
如果我无法实现这一点,我想我必须以某种方式将我的域对象或我的查询结果转换为SelectItem数组以使其工作.
有任何想法吗 ?
我已经测试了这个,试图将服务对象注入@ManagedBean,但它失败了nullpointerexception,因为userService为null.
我目前正在使用Tomcat 7,JSF 2,这里有一些我的pom.xml
<properties>
<java-version>1.6</java-version>
<org.springframework-version>3.0.3.RELEASE</org.springframework-version>
<org.hibernate-version>3.6.0.Final</org.hibernate-version>
....
</properties>
Run Code Online (Sandbox Code Playgroud)
这是异常跟踪:
javax.faces.el.EvaluationException: java.lang.NullPointerException
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:775)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1267)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:558)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:379)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:259)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:281)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:636)
Caused by: java.lang.NullPointerException
at org.albertkam.ui.LoginBean.login(LoginBean.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at …Run Code Online (Sandbox Code Playgroud) 以下是导致问题的序列:
我很困惑:
请赐教:)
谢谢 !
是否可以更改版本化的实体实例,并在不使用flush的情况下获取待增加的版本?因为从我读到的内容来看,即时冲洗并不是一种好的做法,因为它对性能甚至数据损坏都有不良影响?我不确定:D
这是一个简单的代码,输出也是注释:
/*
Hibernate: select receivingg0_.id as id9_14_, receivingg0_.creationDate as creation2_9_14_, ... too long
the version before modification : 16
the version after modification : 16
after merge the modification, the version is : 16
Hibernate: update ReceivingGood set creationDate=?, modificationDate=?, usercreate_id=?, usermodify_id=?, ... too long
after flushing the modification, the version is finally : 17
*/
public void modifyHeaderAndGetUpdatedVersion() {
String id = "3b373f6a-9cd1-4c9c-9d46-240de37f6b0f";
ReceivingGood receivingGood = em.find(ReceivingGood.class, id);
System.out.println("the version before modification : " + receivingGood.getVersion());
receivingGood.setTransactionNumber("NUM001xyz");
System.out.println("the …Run Code Online (Sandbox Code Playgroud) 目前我正在尝试应用程序管理的持久化上下文,通过手动创建实体管理器并将它们存储起来以启用跨越JSE应用程序中的多个请求调用(可能类似于扩展持久性上下文)的事务.
但是,我想知道我是否可以通过使用spring的@PersistenceContext注入来避免在整个服务和DAO方法中发送entityManager对象作为附加参数,并使用@Transactional注释标记方法以使用与该实体管理器手动启动的事务.
我想我可以通过使用ThreadLocal来管理这个功能,但我会更高兴能够将它附加到spring框架.
这是我想到的一个例子:
UI动作方法:
在这里我们可以看到事务是由ui逻辑启动的,因为后端没有外观/命令方法将这些调用分组到业务逻辑:
Long transactionid = tool.beginTransaction();
// calling business methods
tool.callBusinessLogic("purchase", "receiveGoods",
paramObject1, transactionid);
tool.callBusinessLogic("inventory", "updateInventory",
paramObject2, transactionid);
tool.commitTransaction(transactionid);
Run Code Online (Sandbox Code Playgroud)
在工具里面:
public Long beginTransaction() {
// create the entity --> for the @PersistentContext
Entitymanager entityManager = createEntityManagerFromFactory();
long id = System.currentTimeMillis();
entityManagerMap.put(id, entitymanager);
// start the transaction --> for the @Transactional ?
entityManager.getTransaction().begin();
return id;
}
public void commitTransaction(Long transactionId) {
EntityManager entityManager = entityManagerMap.get(transactionId);
entityManager.getTransaction().commit();
}
public Object callBusinessLogic(String module, String function,
Object paramObject, Long transactionid) …Run Code Online (Sandbox Code Playgroud) 基于这个例子:
@Service
public class Purchase {
@PersistenceContext
private EntityManager em;
@Autowired
private PurchaseDAO dao;
private String normalField;
.... // methods, operations, etc
}
Run Code Online (Sandbox Code Playgroud)
如果我错了,请帮助纠正我:
谢谢 !