views:

663

answers:

2

Ok, heres my issue: I have a JSF application and some JSP files. Let's say i have main.jsp which has a view and includes sub.jsp. This works fine. sub.jsp contains a subview. As a result all the ID's of the form elements in sub.jsp follow the form of 'subview:component'. Now suppose I'm using some ajax and want to fetch the jsp page sub.jsp and include it in a DIV somewhere. Now the ID's all are of the form 'component'. I don't know a way around this, and having to check for 2 different sets of IDs in my interactive javascript is a pain. Is there any way to get consistant IDs?

I've tried: Removing the subview - (then the AJAX call will fail because no view is found)

and

h:form prependid=false - this only removes the form id, not the subview ids

A: 

AJAX is tricky to do with JSF. If the JSF framework you're using doesn't support it, you'll run into many view state problems.

I'm surprised an exception isn't thrown when you address sub.jsp directly - there should be no h:view in sub.jsp and without a UIViewRoot, I'm not sure how a UI tree would be created. If you have a h:view in sub.jsp, then you're putting two UIViewRoots into your UI tree - this is a bug. (The JSF component tree is roughly analogous to that of other Java widget kits like Swing or SWT.)

I suspect the problem you're observing is that you're submitting to a different view to the one that was originally rendered. Since the component tree is completely different, the clientIds will be generated from a different view root. You can read about how they are built in this answer.

In short, I do not think the mechanism you're using to update the client is a valid one.

McDowell
A: 

Have you looked at ajax4Jsf (aka Richfaces) ?

Damo