每当我尝试以编程方式获取视图对象行时,我只会获得第一行。请帮忙。
这是我的代码:
BindingContext BContext=BindingContext.getCurrent();
System.out.println(1);
//BindingContainer bindings= (BindingContainer)bctx.getCurrent().getCurrentBindingsEntry();
BindingContainer bindings = (BindingContainer)BContext.getCurrent().getCurrentBindingsEntry();
DCBindingContainer dc = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding iterBind= dc.findIteratorBinding("UsersView1Iterator");
ViewObject vo=iterBind.getViewObject();
vo.executeQuery();
RowSetIterator rsIterator = vo.createRowSetIterator(null);
rsIterator.reset();
while (rsIterator.hasNext()) {
Row row = rsIterator.next();
String s=(String)row.getAttribute("Username");
String s1=(String)row.getAttribute("Password");
System.out.println(row.getAttribute("Username"));
System.out.println(row.getAttribute("Password"));
if(s.equals(user) && s1.equals(Pass)){
System.out.println(row.getAttribute("Username"));
FacesMessage fm=new FacesMessage(message.toString());
fm.setSeverity(FacesMessage.SEVERITY_INFO);
FacesContext context=FacesContext.getCurrentInstance();
context.addMessage(null, fm);
System.out.println("valid");
return "Success";
}else{
FacesMessage fm=new FacesMessage(message1.toString());
fm.setSeverity(FacesMessage.SEVERITY_INFO);
FacesContext context=FacesContext.getCurrentInstance();
System.out.println("invalid");
context.addMessage(null, fm);System.out.println(20);
return "fail";
}
}
rsIterator.closeRowSetIterator();
return null;
答案 0 :(得分:0)
如果用户和密码匹配,则返回“成功”但如果不匹配,则返回“失败”。请尝试使用该代码:
while (rsIterator.hasNext()) {
Row row = rsIterator.next();
String s=(String)row.getAttribute("Username");
String s1=(String)row.getAttribute("Password");
System.out.println(row.getAttribute("Username"));
System.out.println(row.getAttribute("Password"));
if(s.equals(user) && s1.equals(Pass)){
System.out.println(row.getAttribute("Username"));
FacesMessage fm=new FacesMessage(message.toString());
fm.setSeverity(FacesMessage.SEVERITY_INFO);
FacesContext context=FacesContext.getCurrentInstance();
context.addMessage(null, fm);
System.out.println("valid");
return "Success";
}
}
rsIterator.closeRowSetIterator();
FacesMessage fm=new FacesMessage(message1.toString());
fm.setSeverity(FacesMessage.SEVERITY_INFO);
FacesContext context=FacesContext.getCurrentInstance();
System.out.println("invalid");
context.addMessage(null, fm);System.out.println(20);
return "fail";
答案 1 :(得分:0)
试试这个
DCBindingContainer bindings =
(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding dcIteratorBindings =
bindings.findIteratorBinding("DocumentsView1Iterator");
// Get all the rows of a iterator
Row[] rows = dcIteratorBindings.getAllRowsInRange();
for (Row row : rows) {
String Username=(String)row.getAttribute("Username");
String Password=(String)row.getAttribute("Password");
System.out.println("Check"+depname);
}