I'm having a bit of trouble with my AJAX event and I was wondering if someone could help me spot where I'm going wrong.
I have a dropdown on my page that when it changes, I want it to update another portion of this page. When I use the page with no long running conversation, all works fine. But as soon as I attempt to start a long running conversation & try to use the dropdown box I get a "WELD-000321 No conversation found to restore for id 1" error. Can anyone think of a reason for this? I'm sure the conversation has been started and is available to the page. This is run on Tomcat 6 and uses Mojarra 2.1.6, Weld 1.1.5 & PrimeFaces is also there (although not involved in this part).
I can tell the error is occurring due to the onerror of my f:ajax tag. This is calling a JavaScript function that prints out the error object that is occurring. Debugging the code on the initial page request shows the conversation is started and part of the code printing out the conversation (#{collectionHome.conversation}) returns my conversation.
Trimmed down version of my code follows.
The Form:
<ui:define name="metadata">
<f:metadata>
<f:event type="preRenderView" listener="#{collectionHome.init(true)}" />
</f:metadata>
</ui:define>
<ui:define name="content">
<h:form id="modalForm" class="modalForm">
<ul class="layout form">
<li>
<label for="type" class="required">Type:</label>
<h:selectOneMenu id="type" value="#{collectionHome.selectedCollectionType}">
<f:selectItems value="#{collectionHome.types}" var="colType" itemLabel="#{colType.displayName}" itemValue="#{colType}"/>
<f:ajax event="change" listener="#{collectionHome.switchType}" onerror="handleError" render="@form" />
</h:selectOneMenu>
<p:message id="typeMsg" for="type" />
</li>
<li>
<p>#{collectionHome.conversation}</p>
</li>
<h:panelGroup rendered="#{collectionHome.selectedCollectionType eq 'IMAGE'}">
<li>
<!-- Content to show/hide goes here -->
</li>
</h:panelGroup>
</ul>
</h:form>
</ui:define>
CollectionHome:
@Named("collectionHome")
public class CollectionHome extends EntityHome<FileCollection> implements Serializable {
private CollectionTypes selectedCollectionType;
public boolean doInit() {
return true;
}
public String switchType(AjaxBehaviorEvent event) {
switch (selectedCollectionType) {
case IMAGE:
setEntity(new ImageCollection(getEntity()));
break;
case DOCUMENT:
setEntity(new DocumentCollection(getEntity()));
break;
default:
break;
}
return OutcomeStrings.SUCCESS;
}
}
EntityHome:
@ConversationScoped
public abstract class EntityHome<T extends BaseEntity> {
@Inject
private Conversation conversation;
public void init(boolean startConversation) throws AuthenticationException {
if (doInit()) {
if (startConversation) {
beginConversation();
}
postInit();
}
}
}