【发布时间】:2012-01-02 14:07:36
【问题描述】:
Primefaces tabView activeIndex 属性总是为空。
我的观点.jsf:
<h:form>
<p:growl id="growl" showDetail="true" />
<p:tabView >
<p:ajax event="myForm" listener="#{employeeEdit.onTabChange}" />
<p:tab id="basic" title="Login">
</p:tab>
<p:tab id="personal" title="Personal">
</p:tab>
<p:tab id="contact" title="Contact">
</p:tab>
</p:tabView>
我的edit.jsf:
<h:form prependId="false" >
<p:tabView id="myid" activeIndex="#{employeeEdit.tabIndex}" >
<p:tab id="basic" title="Login">
</p:tab>
<p:tab id="personal" title="Personal">
</p:tab>
<p:tab id="contact" title="Contact">
</p:tab>
</p:tabView>
支持 bean: EmployeeEdit.java:
@Component("employeeEdit")
@ViewScoped
@Repository
public class EmployeeEdit implements Serializable{
/**
*
*/
private static final long serialVersionUID = -2784529548783517864L;
private EmployeeDTO employeeDTO = new EmployeeDTO();
public static HibernateTemplate hibernateTemplate;
private int tabIndex;
@Autowired
public void setSessionFactory(SessionFactory sessionFactory)
{
System.out.println("in SessionFactory" +sessionFactory);
this.hibernateTemplate = new HibernateTemplate(sessionFactory);
System.out.println("in SessionFactory" +hibernateTemplate);
}
public int onTabChange(TabChangeEvent event) {
System.out.println("tab id = " + event.getTab().getId()+event.getTab().getTitle());
if(event.getTab().getId().equals("personal"))
{
tabIndex =0;
}
else if(event.getTab().getId().equals("address"))
{
tabIndex =1;
}
else
{
tabIndex =2;
}
System.out.println("tabIndex = "+tabIndex);
return tabIndex;
}
public void edit() throws IOException
{
FacesContext.getCurrentInstance().getExternalContext().redirect("/employeeedit.jsf");
}
public void cancel() throws IOException
{
FacesContext.getCurrentInstance().getExternalContext().redirect("/employeelist.jsf");
}
public EmployeeDTO getEmployeeDTO() {
return employeeDTO;
}
public void setEmployeeDTO(EmployeeDTO employeeDTO) {
this.employeeDTO = employeeDTO;
}
public int getTabIndex() {
return tabIndex;
}
public void setTabIndex(int tabIndex) {
this.tabIndex = tabIndex;
}
}
但总是得到 tabIndex=0;为什么会这样? AJAX 工作正常。但是在单击视图页面 tabIndex 中的编辑按钮时,它会变为空。 在 view.jsf 中,我的命令按钮是
<p:commandButton value="Edit" actionListener="#{employeeEdit.edit}" />
我的 primefaces 版本是:primefaces-3.0.M3 with Google Cloud SQL
【问题讨论】:
-
你能发布整个托管 bean (
EmployeeEdit) 吗?现在你只发布了你说有效的部分。 -
如果你把你的
EmployeeEdit@SessionScoped写成@SessionScoped会发生什么? -
@ βнɛƨн Ǥʋяʋиɢ:现在工作正常。非常感谢!
-
我已将其发布为答案。您可以接受它以将您的帖子标记为已解决。
-
呃,这不是解决方案,而是解决方法。在同一会话中的不同浏览器选项卡/窗口中打开同一页面,并在每个页面中播放。你会明白为什么这不是一个解决方案。
标签: java google-app-engine jsf-2 primefaces