Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Dynamically adding <jsp:include> tags from backing bean.

843844May 27 2008 — edited May 28 2008
Hey guys,

I've been banging my head against the wall with this one for a while.
Working in a Visual Web JSF project, I want to create some content dynamically in the backing bean before the JSF page renders. I am in Netbeans 6.1 and working with some Woodstock components (don't worry, this isnt a Woodstock question). So far so good, I can do something like:
String[] nameList = new String[]{"Tom", "Dick", "Harry"};
for (String nextName : nameList) {
 com.sun.webui.jsf.component.Label myLabel = new com.sun.webui.jsf.component.Label();
 myLabel.setText(nextName);
 // Parent component is some UIComponent that already exists in the JSP page..
 parentComponent.getChildren().add(myLabel);
}
This will give me three labels with the given names. Perfect.

Disclaimer: This is a made up example so we are going to be assuming a great deal here.
Suppose I have a JSF fragment (.jspf) for each person above that contains some information related to them. Well I want to include that fragment when I create the label for that person. If I weren't creating this dynamically, I would put something like <jsp:include page="tomBean.jspf"> in my .jsp file, but I cannot think of a way to do this in the backing bean similar to how I created a new Label component on the fly above.

If there isn't a way to create a <jsp:*> tag from the backing bean in this fashion, is there any way I can 'write to the .jsp file' from the backing bean?

If this can't be done, does anyone have any clever ideas on how to get the same effect without relying on the jsp:include tag?


Grasping at string here heh,
Sean
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 25 2008
Added on May 27 2008
5 comments
385 views