Exceptions when dynamically create RichFaces component in Se
jackyeh Apr 30, 2008 10:27 PMI create a new EAR project into Eclipse by seam-gen with RichFaces support. Then I create a session bean which dynamically generates a HtmlOutputText and a RichFaces HtmlPanel object.
Session bean:
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlOutputText;
import org.richfaces.component.html.HtmlPanel;
public class HomePage {
private UIComponent layout = null;
public HomePage() {
}
public UIComponent getLayout() {
return layout;
}
public void setLayout(UIComponent layout) {
this.layout = layout;
HtmlOutputText text = new HtmlOutputText();
text.setId("TextComponent");
text.setValue("TextComponent");
layout.getChildren().add(text);
HtmlPanel panel = new HtmlPanel();
panel.setId("Panel");
layout.getChildren().add(panel);
}
}home.xhtml
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"
template="layout/template.xhtml">
<ui:define name="body">
<a4j:form id="mainForm">
<rich:panel id="mainPanel" binding="#{homePage.layout}">
<h:outputText value=" Static text." />
</rich:panel>
</a4j:form>
</ui:define>
</ui:composition>The first problem I met was java.lang.NoClassDefFoundError: org/richfaces/component/html/HtmlPanel.
I think this exception probably indicates missing some libraries, thus I put richfaces-ui.jar into the root of the jar directory of the ear archive.
It works, but then I face to the second problem: java.lang.IllegalArgumentException: Component mainForm:Panel not instance of org.richfaces.component.UIPanel.
As I know, the HtmlPanel object that I construct does derived from the org.richfaces.component.UIPanel class. Moreover, I tried to test the 'layout' argument that passed into the setLayout method by the (layout instanceof HtmlPanel) statement, it returns false.
So, I really have no idea what's going on here, neither how this exception occurs. I tried to debug the problem, but the exception seems not causing by my code but inside of the Seam or RichFaces.
When I comment out the last line of the session bean code, the page shows up as expected with the dynamic created HtmlOutputText object.
layout.getChildren().add(panel);
I spend many days to solve this problem but still failed. I'll be very appreciate who can help me. Thank you very much in advance.