我正在JSF 2.1和PrimeFaces 5.0上工作,我正嘗試從@PostConstructor
創建TabView
,但無法實現。有可能使此標籤視圖變爲可能。如何通過@PostConstructor創建tabView
@PostConstructor
但無法使其正確發生。
XHTML來源:
<div align="center">
<h1 style="margin-top:0; color: cornflowerblue">Basic User Form</h1>
</div>
<h:form id="initTest" >
<p:tabView binding="#{initTestMgBean.tabView}"/>
</h:form>
ManagedBean來源:
@ManagedBean
@RequestScoped
public class initTestMgBean {
private TabView tabView;
public TabView getTabView() {
return tabView;
}
public void setTabView(TabView tabView) {
this.tabView = tabView;
}
@PostConstruct
public void init() {
tabView = new TabView();
tabView.setInView(true);
Tab tab1 = new Tab();
tab1.setTitle("User Form 1");
Tab tab2 = new Tab();
tab2.setTitle("User Form 2");
tabView.getChildren().add(tab1);
tabView.getChildren().add(tab2);
PanelGrid panel1 = new PanelGrid();
panel1.setId("panel1");
panel1.setColumns(2);
PanelGrid panel2 = new PanelGrid();
panel2.setId("panel2");
panel2.setColumns(2);
HtmlOutputLabel label = new HtmlOutputLabel();
label.setId("outlab");
label.setValue("Name ");
label.setFor("name");
InputText text = new InputText();
text.setId("name");
text.setSize(15);
text.setStyle("height:30px");
HtmlOutputLabel label4 = new HtmlOutputLabel();
label4.setId("outlab4");
label4.setFor("userName");
label4.setValue("User Name");
InputText text4 = new InputText();
text4.setId("userName");
text4.setSize(15);
text4.setStyle("height:30px");
tab1.getChildren().add(panel1);
panel1.getChildren().add(label);
panel1.getChildren().add(text);
tab2.getChildren().add(panel2);
panel2.getChildren().add(label4);
panel2.getChildren().add(text4);
}
}
無法實現其添加TabView的動態,你可以給有關注射或如何我實現它..感謝名單答覆一些想法 – Kandy 2014-11-10 09:23:36
從Oracle閱讀:http://www.oracle.com/technetwork/articles/java/cdi-javaee-bien-225152.html或更具體的教程在這裏:http://www.javacodegeeks.com/2013/ 05/java -ee-cdi-dependency -injection-inject-tutorial.html – 2014-11-10 16:10:31
感謝@Mattias F提供良好的學習鏈接。 – Kandy 2014-11-11 04:58:01