2015-05-31 57 views
0

此数据提交author.setFindwithid()如何在此场景中重定向?

<h:form> 
      <h:outputLabel value="Id of to Be Edited record"></h:outputLabel> 
      <h:inputText value="#{author.id}"></h:inputText> 
      <h:commandButton value="submit" action="#{author.setFindwithid()}"/> 
     </h:form> 

这里是author.setFindwithid()

public String setFindwithid() throws SQLException{ 
     String query = "SELECT * FROM authors WHERE id=?"; 
     PreparedStatement ps = con.prepareStatement(query); 
     ps.setInt(1, this.getId()); 
     ResultSet rs = ps.executeQuery(); 

     while (rs.next()) { 
      Author tmp = new Author(); 

      tmp.setId(rs.getInt("id")); 
      tmp.setName(rs.getString("name123")); 
      list.add(tmp); 
     } 

     return "UpdateAuthor.xhtml"; 

    } 

定义页面可以看到我有一个list,我也重定向到UpdateAuthor.xhtml。我想在UpdateAuthor.xhtml范围内提供此list,以便可以在视图中显示list的值。我怎样才能做到这一点?

+0

问题已经通过使用[此](http://stackoverflow.com/a/5406033/4913383)配有一个不同的问题 – user4913383

+0

这个问题涉及解决。您可以只加载与目标页面关联的bean中的列表。 – BalusC

回答

0

您可以将列表中的闪光范围,使其保持跨越重定向活着:

在你setFindwithid方法:

FacesContext.getCurrentInstance().getExternalContext().getFlash().put("listName", list); 

,那么你就能够引用它UpdateAuthor.xhtml观点:

#{flash.listName} 

或得到它编程方式豆:

List myList = (List) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("listName"); 

编辑:

正如BalusC指出的那样,可以保证List甚至会之后使用目标的facelet下面的调用页面刷新保持闪光灯范围内:

#{flash.keep.listName} 

参见:

Understand Flash Scope in JSF2

How to keep JSF flash scope parameters on page reload?

+0

当F5为重定向页面时,它还能工作吗? – BalusC

+0

@BalusC:好点,我编辑了我的答案,使其在F5之后工作,重定向页面 – Zim

+0

并且当您将浏览器地址栏URL复制到新标签页/窗口时? – BalusC