Primefaces tabView activeIndexプロパティは常にnullになります。Primefaces tabView activeIndexプロパティは常にnullになります
マイview.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がnullになります。 view.jsfで は、私のコマンドボタンが
<p:commandButton value="Edit" actionListener="#{employeeEdit.edit}" />
マイprimefacesバージョンです:上記のGoogle Cloud SQLとprimefaces-3.0.M3
マネージドBean( 'EmployeeEdit')全体を投稿できますか?今はあなたが働いている部分だけを掲載しています。 –
はい、上記に投稿しました。 –
'EmployeeEdit'を' @ SessionScoped'にするとどうなりますか? –