我正在尝试保留用户输入(一个问题:它的id是一个自动生成的值),但我收到此异常No validator could be found for type: java.lang.Long
。
这是jsf页面的代码
<p:panel style="margin-left:30%">
<h:panelGrid columns="1" styleClass="grid">
<h:form id="form">
<h3>Titre</h3>
<p:inputText placeholder="Donner un titre significatif" size="56" value="#{questionBean.newQuestion.titre}"></p:inputText><br/>
<p:editor id="editor" width="600" value="#{questionBean.newQuestion.contenu}"/>
<h:panelGrid columns="2" style="margin-top:10px">
<p:commandButton id="submitButton" value="Poser Question" action="#{questionBean.create}"/>
</h:panelGrid>
</h:form>
</h:panelGrid>
</p:panel>
这是managedBean的代码
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.faces.model.SelectItem;
import com.portail.dao.DaoQuestion;
import com.portail.entities.Question;
@ManagedBean(name="questionBean")
@SessionScoped
public class QuestionBean implements java.io.Serializable {
private List<SelectItem> questItems;
private DataModel questions;
private List<Question> questionsEtudiant;
private List<Question> questionsProfesseur;
private Question newQuestion= new Question();
private Question editQuestion;
private List<Question> questionsForums;
private List<Question> questionssansreponses;
private DaoQuestion qDao=new DaoQuestion();
public String create(){
qDao.ajouter(newQuestion);
newQuestion= new Question();
System.out.println("question ajouter ");
questions.setWrappedData(qDao.selectAll());
return"list";
}
这是实体的代码
@Entity(name="Question")
@Table(name="QUESTION")
@NamedQuery(name="Question.findAll", query="SELECT q FROM Question q")
public class Question implements Serializable {
private static final long serialVersionUID = 1L;
@SequenceGenerator(name="seq_ques",sequenceName="SEQ_PK_QUES",initialValue=1, allocationSize=1)
@Id
@NotNull
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="seq_ques")
@Column(name="QUES_PK")
private long quesPk;
@Column(length=200)
private String contenu;
@Temporal(TemporalType.DATE)
private Date datecreation;
@Temporal(TemporalType.DATE)
private Date dateedition;
@Temporal(TemporalType.DATE)
private Date datemodification;
private int nbdownvote;
private int nbupvote;
@Column(length=300,unique=true)
private String titre;
这是用于保留问题的DAO类的代码
public class DaoQuestion {
private static final String JPA_UNIT_NAME="Portail";
private EntityManager entityManager;
protected EntityManager getEntityManager() {
if (entityManager == null) {
entityManager = Persistence.createEntityManagerFactory(
JPA_UNIT_NAME).createEntityManager();
}
return entityManager;
}
public void ajouter(Question q)
{
EntityTransaction tx = getEntityManager().getTransaction();
tx.begin();
entityManager.persist(q);
tx.commit();
}