我已经阅读了一些关于JEE6上Observer模式实现的博客文章,还有什么困扰我......我找不到任何信息,所以我问那里......
我发现了以下例子:
@Stateless
[...]
public class ParisJugService {
@Inject
Event event;
public void helloParis(){
System.out.println("Hello Paris");
event.fire("hello Paris invoked!");
}
}
@Stateless
public class EventReceiver {
public void onHelloParis(@Observes String message){
System.out.println("----------- " + message);
}
}
Run Code Online (Sandbox Code Playgroud)
和
public class MyEvent {
String data;
Date eventTime;
....
}
public class EventProducer {
@Inject @Any Event<MyEvent> event;
public void doSomething() {
MyEvent e=new MyEvent();
e.data="This is a test event";
e.eventTime=new Date();
event.fire(e);
}
}
public class EventConsumer {
public void afterMyEvent(@Observes …Run Code Online (Sandbox Code Playgroud) 你好,我有一个很大的问题,我希望在这里找到帮助我有两个实体
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="Role", discriminatorType=DiscriminatorType.STRING) public class Utilisateur implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id")
private Long id;
@Column(name="nom",nullable=false)
private String nom;
@Column(name="Role",nullable=false, insertable=false)
private String Role ;
Run Code Online (Sandbox Code Playgroud)
//... }
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="Role", discriminatorType=DiscriminatorType.STRING)
public class Utilisateur implements Serializable {
private static final long serialVersionUID = 1L;
@Entity
Run Code Online (Sandbox Code Playgroud)
//...
}
ResCom rsCom= new ResCom(nom,prenom, email,civilite,
SysQl.crypePasse(pass));
gr.create(rsCom);
Run Code Online (Sandbox Code Playgroud)
@Table(name ="ResCom")@DiscriminatorValue("ResCom")公共类ResCom扩展了Utilisateur {
/ ...
}
我做的第一件事
Utilisateur tets= gr.findByEmail(email);
message=tets.getEmail()+" and Role :"+tets.getRole()+"";
Run Code Online (Sandbox Code Playgroud)
我检查我的数据库我看到该属性是ResCom插入 …
我正在尝试在Cloudbees Paas上部署现有的Jboss 7 war应用程序,而我却陷入了数据源配置的困境.在这个专门的Cloudbees wiki条目和相关的线程之后,我最终在应用程序启动期间出现以下错误(线程中的其他人已经提到过):
javax.resource.ResourceException: Wrong driver class [class com.mysql.jdbc.Driver] for this connection URL [jdbc:cloudbees://cbdebate--1]
Run Code Online (Sandbox Code Playgroud)
我的配置文件如下:
CloudBees的-web.xml中
<?xml version="1.0" encoding="UTF-8"?>
<cloudbees-web-app xmlns="http://www.cloudbees.com/xml/webapp/1">
<!-- Application ID (formatted CB_ACCOUNT/APPNAME) -->
<appid>hck/debate</appid>
<!-- DataSources (use names refererenced via <resource-ref> in WEB-INF/web.xml) -->
<resource name="jdbc/debate" auth="Container" type="javax.sql.DataSource">
<param name="username" value="myuser" />
<param name="password" value="mypassword" />
<param name="url" value="jdbc:cloudbees://cbdebate--1" />
<!-- Connection Pool settings -->
<param name="maxActive" value="20" />
<param name="maxIdle" value="2" />
<param name="maxWait" value="10000" />
<param name="validationQuery" value="SELECT …Run Code Online (Sandbox Code Playgroud) 在Web App中,需要通过每页JSF显示6个对象(表DB的行)的视图.为了进入下一个视图,将显示另一个不同的随机6个对象,依此类推......
所以我在具有思维@Singleton,查询与该表中的所有行@Schedule在给定的时间间隔工作,比方说,每隔1小时.它将有一个getCollection()方法.
然后每个访问者都会有一个@SessionScoped CDI bean,它将查询@Singleton的Collection ,然后将其随机播放以对特定用户进行随机查看.
与许多访问一样,将创建许多将同时访问getCollection()方法的CDI bean.
这是正确的吗?这种情况需要任何特定的注释吗?这样做的其他任何方式?
----- UPDATE ---
与朋友沟通后,特意Luiggi门多萨,他们告诉我,在这里最好的办法是使用的Ehcache或类似的,而不是Singleon.我认为就是这样.
在我的项目文件夹中,我们有2个ContextPath/WEB-INF/Classes/*.class名称为App1.class和的java文件App2.class
如果我想运行App1.class,我只需要在浏览器中触发URL.
http://localhost:8080/Mapping/App1
Run Code Online (Sandbox Code Playgroud)
同样,如果要触发App2.class,请使用以下链接
http://localhost:8080/Mapping/App2
Run Code Online (Sandbox Code Playgroud)
我想触发App2的App1,意味着如果触发App1在浏览器对应的URL,这将是触发App2.
我也不想做任何回应.
我怎样才能做到这一点.
谁能帮我.
谢谢.
我对 Java EE 还很陌生,当我查看编译后的代码时(我找不到 javax:javaee-api-6.0 的源代码),我注意到了这个类。
package javax.servlet;
import java.util.EventObject;
public class ServletContextEvent extends EventObject
{
public ServletContextEvent(ServletContext paramServletContext);
public ServletContext getServletContext();
}
Run Code Online (Sandbox Code Playgroud)
但是,javax:javaee-api-7.0 中的同一个类就是这个。
package javax.servlet;
import java.util.EventObject;
public class ServletContextEvent extends EventObject
{
private static final long serialVersionUID = -7501701636134222423L;
public ServletContextEvent(ServletContext source)
{
super(source);
}
public ServletContext getServletContext()
{
return (ServletContext)super.getSource();
}
}
Run Code Online (Sandbox Code Playgroud)
同一包中的 ServletException 也会发生这种情况(可能还有更多,因为我没有逐一介绍)。
假设 Java Decompiler 给了我源代码的样子,从纯 Java 语法的角度来看,我无法理解为什么 6.0 类不是抽象的(或者不是接口)。
问题 1. 为什么 6.0 中的类不是抽象类或接口?
问题 2. 为什么在 7.0 中更改了实现?大家有没有意识到用javaee-api编译代码时6.0版本会出问题?
我问的原因是因为在 Intellij IDEA …
我正在研究JSF/Primefaces应用程序.我想阻止在primefaces对话框后面的页面.我试过这段代码:
<h:form id="form">
<p:dataTable id="types" value="#{resourcesTypesMBean.resourceTypes}" var="item"
selection="#{resourcesTypesMBean.selectedResourceType}"
rowKey="#{item.id}" selectionMode="single">
<f:facet name="header" >
<table style="border: hidden">
<tbody >
<tr >
<td align="left" style="border: hidden">
<p:outputLabel value="List of Resources' Types"/>
</td>
<td align="right" style="border: hidden">
<p:commandButton
oncomplete="ResourceTypeDialogNew.show()"
icon="ui-icon-plus" title="add"/>
<p:commandButton id="btnDelete" title="delete
" actionListener="#{resourcesTypesMBean.deleteResourceType()}"
update="types" icon="ui-icon-trash" />
<p:button outcome="Resources.xhtml"
icon="ui-icon-arrowthick-1-w" title="back"/>
</td>
</tr>
</tbody>
</table>
</f:facet>
<p:column headerText="Name">
<p:outputLabel value="#{item.name}"/>
</p:column>
<p:column headerText="Code">
<p:outputLabel value="#{item.code}"/>
</p:column>
</p:dataTable>
</h:form>
<h:form id="newResourceTypeForm">
<p:dialog header="New Resource Type" widgetVar="ResourceTypeDialogNew"
resizable="false" modal="true" appendTo="@(body)" showEffect="explode"
hideEffect="explode" style="position: …Run Code Online (Sandbox Code Playgroud) 我已将 Java EE 应用程序从 JDK 8 升级到 JDK 11。但是当我部署到 JBOSS EAP 7.3 服务器时,出现以下异常。
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: jdk.internal.ref.Cleaner from [Module "deployment.DFNNTPOMS_X_X_3.003.000.00.0.ear" from Service Module Loader]
at deployment.DFNNTPOMS_X_X_3.003.000.00.0.ear//net.openhft.chronicle.hash.impl.util.CleanerUtils.<clinit>(CleanerUtils.java:42)
... 63 more
Caused by: java.lang.ClassNotFoundException: jdk.internal.ref.Cleaner from [Module "deployment.DFNNTPOMS_X_X_3.003.000.00.0.ear" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:412)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:400)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
at deployment.DFNNTPOMS_X_X_3.003.000.00.0.ear//net.openhft.chronicle.hash.impl.util.CleanerUtils.<clinit>(CleanerUtils.java:35)
... 63 more
Run Code Online (Sandbox Code Playgroud)
有什么解决办法吗?
我的Java EE 6应用程序中有这样的托管bean:
@Named
@RequestScoped
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class RegistrationBean implements Serializable {
@PersistenceContext
EntityManager em;
public String doRegistration() {
MyEntity entity = new MyEntity();
em.persist(entity);
return "view";
}
}
Run Code Online (Sandbox Code Playgroud)
据我了解@TransactionAttribute,应自动创建新事务。但显然不是,因为我遇到了一个例外:javax.persistence.TransactionRequiredException: EntityManager must be access within a transaction
我的持久性单元具有transaction-type="JTA"属性。我正在使用JBoss 6 cr1。
我正在使用JSF 2.0和Glassfish v3.我正在测试JSR303 bean验证的功能,所以我创建了一个验证器,它实现ConstraintValidator然后在我要验证的属性上注释它.
它工作正常,但它显示Glassfish默认错误页面.我不希望这个显示,我宁愿把消息显示在一个<h:outputText>或什么的.
有谁知道如何实现这一目标?
这是我的验证方法:
@Override
public boolean isValid(String searchArg, ConstraintValidatorContext ctx) {
boolean searchArgCorrect = true;
FacesMessage msg;
if(searchArg!=null) {
ctx.disableDefaultConstraintViolation();
if(searchArg.length() < 3) {
ctx.buildConstraintViolationWithTemplate("Searcharg is too short").addConstraintViolation();
searchArgCorrect=false;
msg = new FacesMessage(
FacesMessage.SEVERITY_ERROR,
"Searcharg is too short", null);
throw new ValidatorException(msg);
}
}
return searchArgCorrect;
}
Run Code Online (Sandbox Code Playgroud)
PS:我知道有更简单的方法来验证字符串的长度,但上面的代码片段仅用于演示/测试目的.我有另一个验证器的计划.