我正在创建一个JSf网页,用于显示表的数据,以及编辑,更新,将数据删除到数据库中。
我使用的是数据表,loginBean类中的update方法是
@ManagedBean(name = "loginBean" , eager=true)
@ViewScoped
public class LoginBean implements Serializable {
private static final long serialVersionUID = 1L;
private String emailid;
private String password;
boolean disabled = true;
@EJB
LoginManagerRemote loginmanager;
EntityManager em;
List<Login> list=null;
@PostConstruct
public void init()
{System.out.println(">>>> In List method <<<<");
list = new ArrayList<Login>();
list = loginmanager.findAll();
}
public List<Login> getList()
{
return list;
}
public void setList(List<Login> list) {
this.list = list;
}
public String updateAction(Login list) {
System.out.println(">>>> Started in the list for loop <<<<");
loginmanager.update(list);
System.out.println(">>>> Update nethod, ersisted data <<<<");
setEditable(false);
return "";
}
登录管理器类中的Update方法是:
@Override
public String update(Login list){
// String query = "update employee set firstName = ?,lastName = ? where id = 1";
try{
//Query q = em.createQuery("update Login set UName = ?1,emailAdd = ?2, pword= ?3 where id = 1");
// q.setParameter(1,this.UName);
// q.setString(2,this.emailAdd);
// q.setString(3,this.pword);
list.getUName();
list.getPword();
list.getEmailAdd();
em.persist(list);
System.out.println(">>>>> I m in login manager update method, and i have persisted data <<");
return "Users.xhtml";
}catch (Exception e) {
System.out.println(">>>>> The problem during update is <<" + e.getMessage());
e.printStackTrace();
return null;
}
}
此方法在id上出错。密钥1的重复输入。 在更新方法中,如何根据id更新条目,而不是更新id。