0

There used to be a concept of natural conversation in seam. basically the conversation id could be custom, ie. someAction:100, and this could be associated with a restlike url for a conversation. hence the url would be something like:

http:localhost:8080/some_context/someAction:100

I am failing to find the alternative in standard JSF. How do you do it?

Please help as I am in a desperate situation. at least let me know if there is any literature, or if it could be achieved by deltaspike.

Many Thanks

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Ikthiander
  • 3,917
  • 8
  • 37
  • 54
  • It is possible using a conversation scoped bean but you will have to have some url rewriting rules in place that converts the path parameter into a query parameter: ```cid=conversionid``` and vice-versa – maress Oct 06 '15 at 06:27
  • @maress thanks for your comment, care to give an example? – Ikthiander Oct 08 '15 at 13:12
  • FYI: If you would have asked on the mailing list for DeltaSpike you would have seen an answer within few hours. – Dar Whi Oct 09 '15 at 09:11
  • Thanks @DarWhi, i will definitely subscribe myself to it now. – Ikthiander Oct 09 '15 at 10:16
  • For future reference, please avoid using words like 'desperate' or 'urgent', those words stress people and will be counter-productive to your needs http://www.catb.org/esr/faqs/smart-questions.html#urgent – jpangamarca Dec 01 '15 at 20:11

1 Answers1

2

You can do it with DeltaSpike - just inject WindowContext and use/restore whatever window-id you like via the method activateWindow. Afterwards the conversation-scope provided by DeltaSpike (@GroupedConversationScoped) can be used without any further initialization as described in the documentation.

If you have e.g. a JSF application in combination with the JSF-module of DeltaSpike which renders the window-id as 'dswid', you can use the following Servlet-Filter to restore and activate the same window for any Servlet-based technology like JAX-RS,... (don't forget the mapping for the Servlet-Filter).

With JSF don't forget to add the tag to your page-template (as described in the documentation). If you need to create a manual link you can get the current window-id via:

dswid=#{dsWindowContext.currentWindowId}

If you don't like to use 'dswid', just use and extract the information as with any other custom parameter (or use a lib like prettyfaces/rewrite).

If you don't use JSF, you need to render the window-id on your own and ensure that it gets sent back to the server as request-parameter (as with any other parameter you are using).

In your code which finally handles the request, you can just inject any grouped-conversation-scoped bean (or do a lookup via BeanProvider).

public class WindowIdFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

        String windowId = request.getParameter("dswid");

        if (windowId != null) {
            WindowContext windowContext = BeanProvider.getContextualReference(WindowContext.class);
            windowContext.activateWindow(windowId);
        }

        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
    }
}
Dar Whi
  • 822
  • 5
  • 14
  • thanks @DarWhi, 1. is it possible to share some example codes or even an example link, so that i can accept your answer as the right one? – Ikthiander Oct 09 '15 at 10:30
  • thanks @DarWhi , but how to add the conversation name like editAction:100 and also generalize it, as it might be used for others. i tried urlrewrite but it does not allow the total conversation id to be more than 9 characters. I must admit your solution is very close to what i want, but not exact. reflecting on your advice, now i am starting the conversation from the action class, which i am not happy with, but url rewriting is not allowing me more than 9 chars. – Ikthiander Oct 12 '15 at 21:33
  • Per default the max. length for the window-id in DeltaSpike is 10. However, you can reduce it to 9 with the config-key 'deltaspike.window-id.max_length'. With that DeltaSpike won't use keys longer than 9 characters and you don't have an issue at all. If you need more than 10, you can run in potential security-issues... I would go with 100 as the window-id and solve the rest with groups per use-case - that's way more powerful. – Dar Whi Oct 12 '15 at 21:51
  • are you sure about the max length of deltaspike id? sorry not challanging you, but i just tried editAction:100 and it worked. am i getting something wrong here? i even tried extremely huge ids, and they worked. – Ikthiander Oct 12 '15 at 22:57
  • It will cut off the rest behind the scenes. See the config at: https://git-wip-us.apache.org/repos/asf?p=deltaspike.git;a=blob;f=deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/api/config/base/JsfBaseConfig.java;h=c41dcaff3cf0a11b1f7e66b1f917618bc15bb24e;hb=HEAD#l63 – Dar Whi Oct 14 '15 at 16:09