1

I have been trying to conduct some simple tests on Seam Weld and MyFaces CODI. After adding CODI jar files to my projects, I found that it adds a windowId request value to every request even if the bean scope is RequestScoped. Is it really necessary to add windowId request parameter to every request while the bean is in RequestScoped? Is there any practical real-world scenario for this case? Is is possible to remove it if it is not necessary? For example:

This is the code of bean class:

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

@Named("myBean")
@RequestScoped
public class MyBean{
private String firstName;
private String lastName;

public String getFirstName() {
    return firstName;
}

public void setFirstName(String firstName) {
    this.firstName = firstName;
}

public String getLastName() {
    return lastName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}
}

This is the body of the page:

<body>
<h:form>
<h:inputText value="#{myBean.firstName}"></h:inputText>
<br/>
<h:inputText value="#{myBean.lastName}"></h:inputText>
<br/>
<h:commandButton value="submit"></h:commandButton>
</h:form>
</body>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
carawan
  • 508
  • 3
  • 10

2 Answers2

3

It takes some time to find solution in official wiki. https://cwiki.apache.org/confluence/display/EXTCDI/Index

If you do not use @WindowScoped, @ViewAccessScoped and sure you don't need this windowId parameter, then you can create class like this in your project:

@Specializes
@ApplicationScoped
public class CustomWindowContextConfig extends WindowContextConfig {

    @Override
    public boolean isAddWindowIdToActionUrlsEnabled() {
        return false;
    }

    @Override
    public boolean isUrlParameterSupported() {
        return false;
    }
}
Sasa7812
  • 583
  • 1
  • 7
  • 11
3

Apache MyFaces CODI adds the windowId to support browser tab seperated beans. If you use some CODI scopes like @WindowScoped, @ViewAccessScoped, CODIs @ConversationScoped, then you will get a separate contextual instance for each browser tab.

Assume you have a customer relation management app. With CODI @WindowScoped you can open different Customers in different browser tabs/windows. Would you use @SessionScoped, then you would overwrite the values each time (For @SessionScoped beans there is only 1 contextual instance for each session).

And of course you can disabled this feature pretty easily. Please check our official WIKI: https://cwiki.apache.org/confluence/display/EXTCDI/Index

struberg
  • 730
  • 5
  • 12
  • Thank you very much for your prompt answer; however, I have to argue a bit more. Yes, the windowId is necessary to distinguish a browser tab from other one; however, do we need to distinguish a tab all the time? My mean is why do we need it if there is no conversation involved? I made a test like this: I have one JSF page only and it contains a h:form; it also contains a h:commandButton which redisplays current page; I have one bean only and it is RequestScoped; this bean is referenced in that h:form in that page; however, CODI still adds windowId to the request. Is it necessary? – carawan Oct 19 '11 at 09:14
  • > My mean is why do we need it if there is no conversation involved? Let's assume that you go from a page which uses ConversationScoped to another page (ViewScoped) and then back to the original ConversationScoped. If you would drop the windowId on the intermediate page, then you would have lost your conversation. Please note that the 'Conversation' mechanism of CODI is fundamentally different than conversations from Seam2 and CDI. – struberg Oct 31 '11 at 16:41
  • I am not sure if we are on the same page. My question is why do we need windowId if all we have is just one bean (only one) in the project and it is RequestScoped. I don't have any other bean at all. – carawan Oct 31 '11 at 18:47