小编Tha*_*ham的帖子

如何为<p:pickList>编写自定义转换器

在使用使用POJO列表的PrimeFaces组件时,如何编写自定义转换器?我的特殊问题是<p:pickList>

<p:pickList converter="????" value="#{bean.projects}" var="project" 
                             itemLabel="#{project.name}" itemValue="#{project}">
Run Code Online (Sandbox Code Playgroud)

我没有转换器,java.lang.ClassCastException因为JSF使用未转换的java.lang.String提交值设置提交的值.

jsf converter primefaces picklist

21
推荐指数
3
解决办法
6万
查看次数

JSF:初始请求和回发请求?

请查看JSF中的以下代码行

<h:inputText id="name" value="#{customer.name}" />
Run Code Online (Sandbox Code Playgroud)

从java.sun.com引用:

对于包含此标记的页面的初始请求,JavaServer Faces实现#{customer.name}在生命周期的呈现响应阶段评估表达式.在此阶段,表达式仅访问customer bean中的name值,如立即评估中所做的那样.

对于回发请求,JavaServer Faces实现在生命周期的不同阶段评估表达式,在此期间从请求中检索值,验证并传播到customer bean.

我不确定我是否理解初始请求回发请求.客户端浏览器是否向Web服务器发出两个不同的请求?

java jsf postback java-ee

20
推荐指数
2
解决办法
2万
查看次数

将Enum值作为参数从JSF传递

我正在尝试将现有代码迁移到使用Enum,由于我缺乏Enum的经验,我遇到了一些问题.首先,这是我的结构.在我的EJB实体中,我有一个枚举类(不确定它是否甚至是一个类).

public enum Type {
    PROFILE_COMMENT,
    GROUP_COMMENT
} 
Run Code Online (Sandbox Code Playgroud)

在我的托管bean myBean.java,我有

@ManagedBean(name="myBean")
@SessionScoped
public class myBean {

    private Type type;

    public myBean() {
    }

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public void Test(Type t){
        System.out.println(t);
    }

}
Run Code Online (Sandbox Code Playgroud)

然后在我的JSF,

<h:commandButton value="Test" action="#{myBean.Test(myBean.type.PROFILE_COMMENT)}" />
Run Code Online (Sandbox Code Playgroud)

java.lang.ClassNotFoundException:Type的不是课

Type在EJB中的原因是我可以为我的Entity创建一个枚举类型,所以我的查询看起来像这样

select c from X c where c.type = Type.PROFILE_COMMENT
Run Code Online (Sandbox Code Playgroud)

java jsf enums el

19
推荐指数
1
解决办法
2万
查看次数

@Column(unique = true)似乎不起作用

即使我将属性设置为@Column(unique=true),我仍然插入重复的条目.

@Entity
public class Customer {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(unique=true )
    private String name;

    ...
}
Run Code Online (Sandbox Code Playgroud)

我设置了name使用定期ELJSF.我没有create使用表JPA

mysql orm jpa java-ee

17
推荐指数
6
解决办法
2万
查看次数

基于多个属性对ArrayList进行排序

我有一个对象的ArrayList.该对象包含属性datevalue.所以我想对它上面的对象进行排序date,对于我想要对它们进行排序的所有对象value.我怎样才能做到这一点?

java sorting

15
推荐指数
1
解决办法
1万
查看次数

CSS:white-space:nowrap似乎在IE中不起作用

这是jsfiddle以下代码.http://jsfiddle.net/ux4DD/2/.我想要的是名字Harry Pham在一行,所以我把宽度做得很小white-space:nowrap.它适用于Firefox,但不适用于IE.请帮忙

以下是答案.请看上面的JSFIDDLE看看它如何看待

<html>
<head>
   <style type="text/css">
       .linkColor{
           white-space: nowrap;
       }
   </style>
</head>
<body>
<table cellpadding="0" cellspacing="0" style="width: 450px;">
   <tr>
      <td>
         <table cellpadding="0" cellspacing="0" width="100%">
             <tr>
                <td style="width:20px;border-top:1px solid gray;">
                     <span class="linkColor">Harry Pham</span>
                </td>
                <td style="height:15px;background:url('images/line.png') no-repeat;width:28px;" width="35px"></td>
                <td style="border-bottom:1px solid gray;" width="auto"></td>
             </tr>
         </table>
      </td>
   </tr>
</table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

html css

14
推荐指数
1
解决办法
3万
查看次数

为什么使用Facade模式用于EJB会话bean

我想问一下访问EJB会话Bean时使用Facade Pattern的原因是什么.在我的Netbeans 6.9.1,如果我做New> Sessions Bean for Entity Classes,让说,我选择User实体,然后Netbeans的会看到这个代码

AbstractFacade.java
public abstract class AbstractFacade<T> {
    private Class<T> entityClass;

    public AbstractFacade(Class<T> entityClass) {
        this.entityClass = entityClass;
    }

    protected abstract EntityManager getEntityManager();

    public void create(T entity) {
        getEntityManager().persist(entity);
    }

    public T edit(T entity) {
        return getEntityManager().merge(entity);
    }

    public void remove(T entity) {
        getEntityManager().remove(getEntityManager().merge(entity));
    }

    public T find(Object id) {
        return getEntityManager().find(entityClass, id);
    }

    public List<T> findAll() {
        javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
        cq.select(cq.from(entityClass));
        return getEntityManager().createQuery(cq).getResultList();
    }

    public List<T> findRange(int[] …
Run Code Online (Sandbox Code Playgroud)

netbeans ejb facade java-ee

14
推荐指数
2
解决办法
3万
查看次数

有什么区别:使用JPA @TableGenerator的序列id,@ GeneratedValue与数据库Auto_Increment

Q1.:使用数据库应用序列ID之间的区别是什么

一个.

CREATE TABLE Person
(
   id long NOT NULL AUTO_INCREMENT
   ...
   PRIMARY KEY (id)
)
Run Code Online (Sandbox Code Playgroud)

B.

@Entity
public class Person {
    @Id
    @TableGenerator(name="TABLE_GEN", table="SEQUENCE_TABLE", pkColumnName="SEQ_NAME",
        valueColumnName="SEQ_COUNT", pkColumnValue="PERSON_SEQ")
    @GeneratedValue(strategy=GenerationType.TABLE, generator="TABLE_GEN")
    private long id;
    ...
}
Run Code Online (Sandbox Code Playgroud)

我的系统高度并发.由于我的数据库是Microsoft SQL服务器,我认为它不支持@SequenceGenerator,所以我必须坚持使用@TableGenerator容易出现并发问题.

Q2.这里的链接(http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Advanced_Sequencing)表明B可能会遇到并发问题,但我不理解建议的解决方案.如果有人能向我解释如何避免与B的并发问题,我将不胜感激.以下是他们解决方案的片段:

If a large sequence pre-allocation size is used this becomes less of an issue, because the sequence table is rarely accessed.

Q2.1:我们在这里讨论的分配大小是多少?我应该做的allocationSize=10还是allocationSize=100? …

java sql sql-server jpa eclipselink

14
推荐指数
2
解决办法
1万
查看次数

JAXB:当使用XML模式(.xsd)验证XML文件时,如果验证失败,我可以知道导致它的XML标记吗?

所以当我使用XML模式验证XML文件时,我只能知道它是失败还是通过,如果我想知道它为什么失败,我需要查看错误消息,如

[org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'City'. One of '{Address1}' is expected.]
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,它失败,因为我缺少标记Address1.我的问题是当验证失败时,我能知道导致失败的标签吗?这是因为我需要为每个重要的缺失标记处理不同的故障.现在我的想法是

FileInputStream inputStream = null;
try{
    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = sf.newSchema(new File(config.getXmlSchema()));
    JAXBContext context = JAXBContext.newInstance(PackageLabel.class);
    Unmarshaller unmarshaller = context.createUnmarshaller();
    unmarshaller.setSchema(schema);
    inputStream = new FileInputStream(xmlFile);
    pl = (PackageLabel) unmarshaller.unmarshal(inputStream);
} catch (JAXBException e) {
    if(pl.getAddress1() == null){
         System.out.println("Invalid Mailing Address");
    }
    //EDIT: CANNOT DO THIS, SINCE pl  IS NULL AT THIS POINT
    //Some more logics …
Run Code Online (Sandbox Code Playgroud)

java xsd jaxb xml-validation

12
推荐指数
1
解决办法
6818
查看次数

JPA:关于在删除实体之前合并实体的问题

我知道我必须在删除它之前合并该实体,但我从未想过我必须在EJB中执行它.首先我有这些:

e = (Event) scholarBean.merge(e);
scholarBean.remove(e);
Run Code Online (Sandbox Code Playgroud)

在我的托管bean中.它给了我这个错误

java.lang.IllegalArgumentException: Entity must be managed to call remove: com.scholar.entity.Event@998, try merging the detached and try the remove again.
Run Code Online (Sandbox Code Playgroud)

那么我将这两行放在我的会话bean中,它就可以了.知道为什么吗?

Managed Bean

myEJB.deleteEvent(e);
Run Code Online (Sandbox Code Playgroud)

myEJB.java

public void deleteEvent(Event e){
    e = (Event) merge(e);
    em.remove(e);
}
Run Code Online (Sandbox Code Playgroud)

java orm ejb jpa java-ee

11
推荐指数
2
解决办法
1万
查看次数