문제

I'm using JSF2 and PrimeFaces and each time I make an Ajax request and check if the current conversation is transient, it isn't and a new conversation is started.

When I disable the Ajax request, the form automatically passes the cid and the conversation is resumed, but when the is an Ajax request, the cidisn't passed automatically.

How is the right way to pass the cid when using Ajax requests with @ConversationScoped? Why this parameter isn't passed automatically?

도움이 되었습니까?

해결책

I'm not really clear on what your use-case is; but in theory, you could pass the parameter using the <f:attribute/> tag on any given component.

  1. Add the <f:attribute/> tag to the component initiating the AJAX call

    <p:commandLink id="aComponent" value="#{bean.val}" action="#{bean.doSomething}">
       <f:attribute name="conversationId" value="#{param['cid']}"/>           
    </p:commandLink>
    
  2. You can pull the parameter from the component's parameter map in your backing bean:

    FacesContext context = FacesContext.getCurrentInstance();
    UIViewRoot theView = context.getViewRoot();
    UIComponent component = theView.findComponent("aComponent");
    Integer theConversationId =(Integer) component.getAttributes().get("cid");
    

The key point here is that the parameter is available in the #{param} map (as any other GET parameter). The reason why it's not automatically transmitted via ajax is just that: GET parameters require a full HTTP request to be transmitted. The whole point of AJAX is that you can pick and choose what to send to the server.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top