0

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();
    }
  }
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Lee Theobald
  • 8,461
  • 12
  • 49
  • 58

2 Answers2

0

I've seen issues like this before. As I recall, it's a Mojarra issue. The Ajax call isn't sending the cid parameter in the request, or it's not properly being added to the viewmap. Another thing to check is the advent listener for the preRenderView event. It'll be called for Ajax requests as well, so you'll want to check if it's a post back and skip the init.

LightGuard
  • 5,298
  • 19
  • 19
0

I encountered the same problem. This is an issue with JSF 2 for not propagating the conversation id. Try the below workaround. I'm assuming you have primefaces from p:message you are using.

<h:selectOneMenu id="type" value="#{collectionHome.selectedCollectionType}" onchange="saveCollection([{name:'cid',value:'#{javax.enterprise.context.conversation.id}'}])">
      <f:selectItems value="#{collectionHome.types}" var="colType" itemLabel="#{colType.displayName}" itemValue="#{colType}"/>
</h:selectOneMenu>
<p:remoteCommand name="saveCollection" action="#{collectionHome.switchType}"
                                 process="type" />
chinto
  • 1,486
  • 17
  • 27