我有一个要求,即使用jsf 2.0定制组件动态创建面板。面板中的控件将从xml动态读取并在相应对象的选择上呈现(例如:如果选择了Person,我应该渲染一个面板,该面板将具有与以下人员相关的控件:人员年龄字段(inputtext),人员DOB(日历)等)。有关JSF 2.0定制组件和Primefaces的帮助
我想从扩展UIComponentBase的组件类中呈现它。
ResponseWriter writer = Util.getResponseWriter(context);
//start the <table> tag
writer.startElement(Constants.STR_TABLE, this);
//start the <tr> tag
writer.startElement(Constants.STR_TR, this);
//start the <td> tag
writer.startElement(Constants.STR_TD, this);
//encode the button 1 component inside this <td>
encodeAllComponent(context, getMyPrimePanel());
// end the <td> tag
writer.endElement(Constants.STR_TD);
//end the <tr> tag
writer.endElement(Constants.STR_TR);
//end the <table> tag
writer.endElement(Constants.STR_TABLE);
//private variable to render a panel
private Panel myPrimePanel;
/**
* @return the myPrimePanel
*/
public Panel getMyPrimePanel() {
System.out.println("inside the panel get method------");
if (myPrimePanel.getChildCount() <= 1) {
System.out.println("inside the panel creation function");
InputText input = new InputText();
myPrimePanel.getChildren().add(input);
}
System.out.println("inside the panel get method-------------");
return myPrimePanel;
}
/**
* @param myPrimePanel the myPrimePanel to set
*/
public void setMyPrimePanel(Panel myPrimePanel) {
System.out.println("inside the panel get method-------------");
//initialize the button 1 component
this.myPrimePanel = myPrimePanel;
}
我已经这样做了。但是我得到一个空指针异常。具有已定义控件的面板如何动态呈现?
这就是我得到 -
====将开始渲染==== 面板get方法里面------ 2011年9月7日上午10时01分42秒com.sun.faces.context.PartialViewContextImpl $ PhaseAwareVisitCallback访问 SEVERE:java.lang.NullPointerException
检查异常的堆栈跟踪(在服务器日志中)。必须有NPE的行号,例如“在xy行的NullPointerException”。告诉我们它在代码中的哪一行。这会让我们更容易帮助你。 –
感谢您的回复。但它没有显示任何行号。 – JaveDeveloper