我正在开发一个应用程序,我已经开始使用CDI
沿JSF
和JPA
.Web容器是Tomcat
.
我EntityManager
对我的CDI
豆子里的生命周期非常困惑,我需要一个很好的建议来清除我心中的一些东西.一般来说,我读过的是EntityManager
主要应该在Java EE
容器中使用,使用PersistenceContext
注释注入它.因此,容器会照顾它的生命.但是,如果你不使用Java EE
容器(as Tomcat
),那么我需要管理我EntityManager
的生活.
使用哪个是我最好的选择Tomcat, CDI, JSF and JPA
?我现在正在做的是以下内容:
public class EntityManagerFactoryProducer {
public static final String TEST = "test";
@Produces
@ApplicationScoped
public EntityManagerFactory create() {
return Persistence.createEntityManagerFactory(TEST);
}
public void destroy(@Disposes
EntityManagerFactory factory) {
factory.close();
}
}
public class EntityManagerProducer {
@Inject
private transient Logger logger;
@Inject
private EntityManagerFactory emf;
@Produces
public EntityManager …
Run Code Online (Sandbox Code Playgroud) 我有一个String作为参数(实际上是一个valueOf(一个整数),并希望将它与DB中的int值的子字符串进行比较.这是我的代码:
ClinicPatients clp = null;
// Get the criteria builder instance from entity manager
final CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
// Create criteria query and pass the value object which needs to be populated as result
CriteriaQuery<ClinicPatients> criteriaQuery = cb.createQuery(ClinicPatients.class);
// Tell to criteria query which tables/entities you want to fetch
final Root<ClinicPatients> rootClp = criteriaQuery.from(ClinicPatients.class);
criteriaQuery.select(rootClp);
Expression<String> e1 = cb.function("CONVERT", String.class, rootClp.get(idCPFieldName));
Predicate p1 = cb.equal(cb.substring(e1, 1, 3), idClinicPatient);
criteriaList.add(p1);
criteriaQuery.where(p1);
// Here entity manager will …
Run Code Online (Sandbox Code Playgroud) 当我尝试使用primefaces cropper裁剪图像时出现以下错误,但图像上没有选择任何内容(选择不存在):
2013年3月17日下午5:10:46 com.sun.faces.lifecycle.ProcessValidationsPhase执行警告:负宽度或零宽度
java.awt.image.RasterFormatException: negative or zero width
at java.awt.image.Raster.<init>(Raster.java:1108)
at java.awt.image.WritableRaster.<init>(WritableRaster.java:129)
at sun.awt.image.SunWritableRaster.<init>(SunWritableRaster.java:129)
at sun.awt.image.ByteComponentRaster.<init>(ByteComponentRaster.java:154)
at sun.awt.image.ByteInterleavedRaster.<init>(ByteInterleavedRaster.java:191)
at sun.awt.image.ByteInterleavedRaster.createWritableChild(ByteInterleavedRaster.java:1261)
at java.awt.image.BufferedImage.getSubimage(BufferedImage.java:1173)
at org.primefaces.component.imagecropper.ImageCropperRenderer.getConvertedValue(ImageCropperRenderer.java:146)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)
at javax.faces.component.UIInput.validate(UIInput.java:960)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1233)
at javax.faces.component.UIInput.processValidators(UIInput.java:698)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:510)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1612)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at …
Run Code Online (Sandbox Code Playgroud) 我正在使用JSF 2.2
,Primefaces 4.0
而且我正在使用slider
来自的组件Primefaces
.
<p:slider displayTemplate="Between {min} and {max}" minValue="20" maxValue="40" step="1"/>
Run Code Online (Sandbox Code Playgroud)
我想问你,如果是不可能性有step
作为decimal
的价值.例如step="0.1"
,或者也许是关于如何解决这个问题的一些想法.
我试过但我得到的错误如下:
javax.el.ELException: Cannot convert 0.1 of type class java.lang.String to int] with root cause
Run Code Online (Sandbox Code Playgroud)
谢谢.
是否可以设置当前显示的标签编程的<p:wizard>
?
例如,我想要对包含向导的同一页面的两个不同请求,以选择不同的选项卡.
我目前正在尝试做的是,有一个带有许多选项卡的向导,在第二个选项卡中我有一个重定向到另一个页面,所以当我回来时,我想进入导致重定向的最后一步.
你能帮我么 ?非常感谢 !
如果此方法被commandButton
组件作为AJAX请求调用,并且该方法是在托管bean的实例变量上运行,那么我们是否必须同步托管bean方法?
假设我们有这个简单的托管bean:
public class ManagedBeanTest {
private int count;
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public String increaseCount() {
count++;
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
因此,如果在这种情况下该increaseCount
方法由commandButton
内部组件调用action
,我是否必须同步此方法?
谢谢您的回答.
我正在尝试触发POST请求。我发送的数据是XML格式的(我通过JAXB进行此操作),但是我必须发送请求参数。我的问题与Content-Type有关(我在代码中添加了一些注释)。我应该使用哪一个?
见下面我的代码:
private V callAndGetResponse(K request, Class<K> requestClassType, Class<V> responseClassType) throws Exception {
JAXBContext jaxbContext = JAXBContext.newInstance(requestClassType, responseClassType);
Marshaller marshaller = jaxbContext.createMarshaller();
// set properties on marshaller
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(Marshaller.JAXB_ENCODING, charset);
marshaller.setProperty("com.sun.xml.internal.bind.xmlHeaders", String.format(XML_HEADER_FORMAT, dtd));
marshaller.marshal(request, System.out);
URL wsUrl = new URL(primaryEndpointUrl);
HttpURLConnection connection = openAndPrepareConnection(wsUrl);
tryToMarshallWsRequestToOutputStream(request, marshaller, connection);
printDebug(connection);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
Object response = unmarshaller.unmarshal(connection.getInputStream());
// cleanup
connection.disconnect();
return responseClassType.cast(response);
}
private HttpURLConnection openAndPrepareConnection(URL wsUrl) throws IOException {
HttpURLConnection connection = (HttpURLConnection) wsUrl.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Accept", "application/xml"); …
Run Code Online (Sandbox Code Playgroud) java ×3
jsf-2 ×3
primefaces ×3
hibernate ×2
jpa ×2
jsf ×2
cdi ×1
criteria ×1
criteria-api ×1
http ×1
http-headers ×1
java-ee ×1
jaxb ×1
managed-bean ×1