How to reuse Primefaces datatable with different data in different browser tabs?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-2















My application has a query param in the url which is used to render different data using the same xhtml (all dynamic content) in a datatable.



Scope of the bean is session scope, the datatable renders all data, and has lots of input elements which open different dialogs.



If I open another browser tab sending a different query param, the datatable renders perfectly, however if I go back to the first tab, all commandlinks won't invoke the actions and the whole application will start to act very erratically.



According to my research this is because I changed the data in the datatable, I tried naming it with dynamic ids, dynamic widget names, but nothing seems to work.



<f:metadata>
<f:viewParam name="param" value="#{moduleBean.param}"/>
<f:viewAction action="#{moduleBean.setup}" />
</f:metadata>

<c:set var="module" value="#{moduleBean.param}" />

<p:dataTable id="#{module}-dataTable" value="#{moduleBean.model[module]}" var="data">

<p:commandLink action="#{moduleBean.openModuleDetails}" update=":#{module}-searchDialog" oncomplete="PF('#{module}-searchWidget').show();">
<f:param name="module" value="#{module}" />
<f:param name="dataRow" value="#{data.dbKey}" />
</p:commandLink>
</p:dataTable>


@Named
@javax.faces.view.ViewScoped
public class ModuleBean implements Serializable {

private String param;

public void setup() throws IOException {
this.model.put(this.param, new LazyDataModel(this.param));
}

public Map<String, LazyDataModel> getModel() {
return model;
}
}


This builds all the expected html with all correct ids in each tab, however JSF is still not processing the action inside the commandlink. Needless to say, if I stick to only one browser tab everything works perfectly.



Sometimes it starts working after clicking twice in the link, but going back and forth between the browser tabs will eventually always crash it.



Adding an action listener to the commandlink didnt fix it either.



Any suggestions on how to make JSF treat the same datatable as different entities on the same page but with different parameters ?










share|improve this question































    -2















    My application has a query param in the url which is used to render different data using the same xhtml (all dynamic content) in a datatable.



    Scope of the bean is session scope, the datatable renders all data, and has lots of input elements which open different dialogs.



    If I open another browser tab sending a different query param, the datatable renders perfectly, however if I go back to the first tab, all commandlinks won't invoke the actions and the whole application will start to act very erratically.



    According to my research this is because I changed the data in the datatable, I tried naming it with dynamic ids, dynamic widget names, but nothing seems to work.



    <f:metadata>
    <f:viewParam name="param" value="#{moduleBean.param}"/>
    <f:viewAction action="#{moduleBean.setup}" />
    </f:metadata>

    <c:set var="module" value="#{moduleBean.param}" />

    <p:dataTable id="#{module}-dataTable" value="#{moduleBean.model[module]}" var="data">

    <p:commandLink action="#{moduleBean.openModuleDetails}" update=":#{module}-searchDialog" oncomplete="PF('#{module}-searchWidget').show();">
    <f:param name="module" value="#{module}" />
    <f:param name="dataRow" value="#{data.dbKey}" />
    </p:commandLink>
    </p:dataTable>


    @Named
    @javax.faces.view.ViewScoped
    public class ModuleBean implements Serializable {

    private String param;

    public void setup() throws IOException {
    this.model.put(this.param, new LazyDataModel(this.param));
    }

    public Map<String, LazyDataModel> getModel() {
    return model;
    }
    }


    This builds all the expected html with all correct ids in each tab, however JSF is still not processing the action inside the commandlink. Needless to say, if I stick to only one browser tab everything works perfectly.



    Sometimes it starts working after clicking twice in the link, but going back and forth between the browser tabs will eventually always crash it.



    Adding an action listener to the commandlink didnt fix it either.



    Any suggestions on how to make JSF treat the same datatable as different entities on the same page but with different parameters ?










    share|improve this question



























      -2












      -2








      -2








      My application has a query param in the url which is used to render different data using the same xhtml (all dynamic content) in a datatable.



      Scope of the bean is session scope, the datatable renders all data, and has lots of input elements which open different dialogs.



      If I open another browser tab sending a different query param, the datatable renders perfectly, however if I go back to the first tab, all commandlinks won't invoke the actions and the whole application will start to act very erratically.



      According to my research this is because I changed the data in the datatable, I tried naming it with dynamic ids, dynamic widget names, but nothing seems to work.



      <f:metadata>
      <f:viewParam name="param" value="#{moduleBean.param}"/>
      <f:viewAction action="#{moduleBean.setup}" />
      </f:metadata>

      <c:set var="module" value="#{moduleBean.param}" />

      <p:dataTable id="#{module}-dataTable" value="#{moduleBean.model[module]}" var="data">

      <p:commandLink action="#{moduleBean.openModuleDetails}" update=":#{module}-searchDialog" oncomplete="PF('#{module}-searchWidget').show();">
      <f:param name="module" value="#{module}" />
      <f:param name="dataRow" value="#{data.dbKey}" />
      </p:commandLink>
      </p:dataTable>


      @Named
      @javax.faces.view.ViewScoped
      public class ModuleBean implements Serializable {

      private String param;

      public void setup() throws IOException {
      this.model.put(this.param, new LazyDataModel(this.param));
      }

      public Map<String, LazyDataModel> getModel() {
      return model;
      }
      }


      This builds all the expected html with all correct ids in each tab, however JSF is still not processing the action inside the commandlink. Needless to say, if I stick to only one browser tab everything works perfectly.



      Sometimes it starts working after clicking twice in the link, but going back and forth between the browser tabs will eventually always crash it.



      Adding an action listener to the commandlink didnt fix it either.



      Any suggestions on how to make JSF treat the same datatable as different entities on the same page but with different parameters ?










      share|improve this question
















      My application has a query param in the url which is used to render different data using the same xhtml (all dynamic content) in a datatable.



      Scope of the bean is session scope, the datatable renders all data, and has lots of input elements which open different dialogs.



      If I open another browser tab sending a different query param, the datatable renders perfectly, however if I go back to the first tab, all commandlinks won't invoke the actions and the whole application will start to act very erratically.



      According to my research this is because I changed the data in the datatable, I tried naming it with dynamic ids, dynamic widget names, but nothing seems to work.



      <f:metadata>
      <f:viewParam name="param" value="#{moduleBean.param}"/>
      <f:viewAction action="#{moduleBean.setup}" />
      </f:metadata>

      <c:set var="module" value="#{moduleBean.param}" />

      <p:dataTable id="#{module}-dataTable" value="#{moduleBean.model[module]}" var="data">

      <p:commandLink action="#{moduleBean.openModuleDetails}" update=":#{module}-searchDialog" oncomplete="PF('#{module}-searchWidget').show();">
      <f:param name="module" value="#{module}" />
      <f:param name="dataRow" value="#{data.dbKey}" />
      </p:commandLink>
      </p:dataTable>


      @Named
      @javax.faces.view.ViewScoped
      public class ModuleBean implements Serializable {

      private String param;

      public void setup() throws IOException {
      this.model.put(this.param, new LazyDataModel(this.param));
      }

      public Map<String, LazyDataModel> getModel() {
      return model;
      }
      }


      This builds all the expected html with all correct ids in each tab, however JSF is still not processing the action inside the commandlink. Needless to say, if I stick to only one browser tab everything works perfectly.



      Sometimes it starts working after clicking twice in the link, but going back and forth between the browser tabs will eventually always crash it.



      Adding an action listener to the commandlink didnt fix it either.



      Any suggestions on how to make JSF treat the same datatable as different entities on the same page but with different parameters ?







      jsf primefaces datatable cdi






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 4 at 22:03









      mazaneicha

      2,5252029




      2,5252029










      asked Jan 4 at 17:09









      Alejandro RomanellaAlejandro Romanella

      23




      23
























          1 Answer
          1






          active

          oldest

          votes


















          2














          Without knowing more about the underlying bean - if you place your moduleBean in @SessionScoped this would be the expected behavior. The session (and session scoped beans) are shared between browser tabs. So you cannot rely on the underlying values from two different tabs.



          Try changing to @RequestScoped/@ViewScoped for the backing values of the table data.



          Here is a complete solution that works, note that this uses PrimeFaces 6.2, Apache Commons and Lombok;



          @Data
          @Named
          @ViewScoped
          public class TableTestBackingBean implements Serializable {
          private int param;

          @Inject
          private PersonsBean personsBean;

          public void onClicked() {
          System.out.println("Clicked fine!");
          }

          public List<Person> getPersons() {
          return personsBean.getPersons()[param];
          }
          }




          @Data
          @ApplicationScoped
          public class PersonsBean {
          @Data
          @AllArgsConstructor
          public class Person {
          private String firstName;
          private String lastName;
          private int age;
          }

          private List<Person> persons;

          @PostConstruct void init() {
          persons = new List[4];

          for (int j = 0; j < 4; j++) {
          persons[j] = new ArrayList<>();

          for (int i = 0; i < 30; i++) {
          final String firstName =
          RandomStringUtils.randomAlphanumeric(10);
          final String lastName =
          RandomStringUtils.randomAlphanumeric(10);
          final int age = RandomUtils.nextInt(0, 120);

          persons[j].add(new Person(firstName, lastName, age));
          }
          }
          }
          }




          <?xml version="1.0" encoding="UTF-8"?>
          <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
          xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core">
          <f:metadata>
          <f:viewParam name="param" value="#{tableTestBackingBean.param}"/>
          </f:metadata>
          <h:head>
          <title>Test</title>
          </h:head>
          <h:body>
          <p:dataTable value="#{tableTestBackingBean.persons}" var="t">
          <p:column headerText="First Name"><h:outputText value="#{t.firstName}" /></p:column>
          <p:column headerText="Last Name"><h:outputText value="#{t.lastName}" /></p:column>
          <p:column headerText="Age"><h:outputText value="#{t.age}" /></p:column>
          </p:dataTable>
          <h:form>
          <p:commandButton action="#{tableTestBackingBean.onClicked}" value="Click Me!" />
          </h:form>
          </h:body>
          </html>


          This uses an application scoped bean for the table data, keeping it completely static. This works without a hitch and the table renders the data differently based on the parameter passed in param.






          share|improve this answer


























          • Better to use a @ViewScoped bean for the ajax pagination, filtering and selection

            – Kukeltje
            Jan 4 at 17:29











          • I know they are shared, thats why my model which return the paginated results to the datatable is a map, thats get accessed by the param sent by the view. I keep all paginated results and data in the backing bean, so it should still take the correct one. Unfortunately its not enough to make it work

            – Alejandro Romanella
            Jan 4 at 17:30













          • ViewScoped isnt working for some reason at all. Thats why Im using session

            – Alejandro Romanella
            Jan 4 at 17:39











          • But #{moduleBean.param} is shared too so effectively identical for all pages. And then the initial model for page one differs from the one used when you opened page2. If you do not use the c:set but always directly use the param it might work too. And you effextively created a windowscoped which I meant to suggest to use. See deltaspike!

            – Kukeltje
            Jan 4 at 17:40













          • I actually checked and #{moduleBean.param} is not the same for all pages. It actually resolves to the correct query param sent, and use that to name all tables and components, works at view, and works in backing bean. Its just that the datatable is getting somehow confused

            – Alejandro Romanella
            Jan 4 at 17:42












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54043288%2fhow-to-reuse-primefaces-datatable-with-different-data-in-different-browser-tabs%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Without knowing more about the underlying bean - if you place your moduleBean in @SessionScoped this would be the expected behavior. The session (and session scoped beans) are shared between browser tabs. So you cannot rely on the underlying values from two different tabs.



          Try changing to @RequestScoped/@ViewScoped for the backing values of the table data.



          Here is a complete solution that works, note that this uses PrimeFaces 6.2, Apache Commons and Lombok;



          @Data
          @Named
          @ViewScoped
          public class TableTestBackingBean implements Serializable {
          private int param;

          @Inject
          private PersonsBean personsBean;

          public void onClicked() {
          System.out.println("Clicked fine!");
          }

          public List<Person> getPersons() {
          return personsBean.getPersons()[param];
          }
          }




          @Data
          @ApplicationScoped
          public class PersonsBean {
          @Data
          @AllArgsConstructor
          public class Person {
          private String firstName;
          private String lastName;
          private int age;
          }

          private List<Person> persons;

          @PostConstruct void init() {
          persons = new List[4];

          for (int j = 0; j < 4; j++) {
          persons[j] = new ArrayList<>();

          for (int i = 0; i < 30; i++) {
          final String firstName =
          RandomStringUtils.randomAlphanumeric(10);
          final String lastName =
          RandomStringUtils.randomAlphanumeric(10);
          final int age = RandomUtils.nextInt(0, 120);

          persons[j].add(new Person(firstName, lastName, age));
          }
          }
          }
          }




          <?xml version="1.0" encoding="UTF-8"?>
          <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
          xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core">
          <f:metadata>
          <f:viewParam name="param" value="#{tableTestBackingBean.param}"/>
          </f:metadata>
          <h:head>
          <title>Test</title>
          </h:head>
          <h:body>
          <p:dataTable value="#{tableTestBackingBean.persons}" var="t">
          <p:column headerText="First Name"><h:outputText value="#{t.firstName}" /></p:column>
          <p:column headerText="Last Name"><h:outputText value="#{t.lastName}" /></p:column>
          <p:column headerText="Age"><h:outputText value="#{t.age}" /></p:column>
          </p:dataTable>
          <h:form>
          <p:commandButton action="#{tableTestBackingBean.onClicked}" value="Click Me!" />
          </h:form>
          </h:body>
          </html>


          This uses an application scoped bean for the table data, keeping it completely static. This works without a hitch and the table renders the data differently based on the parameter passed in param.






          share|improve this answer


























          • Better to use a @ViewScoped bean for the ajax pagination, filtering and selection

            – Kukeltje
            Jan 4 at 17:29











          • I know they are shared, thats why my model which return the paginated results to the datatable is a map, thats get accessed by the param sent by the view. I keep all paginated results and data in the backing bean, so it should still take the correct one. Unfortunately its not enough to make it work

            – Alejandro Romanella
            Jan 4 at 17:30













          • ViewScoped isnt working for some reason at all. Thats why Im using session

            – Alejandro Romanella
            Jan 4 at 17:39











          • But #{moduleBean.param} is shared too so effectively identical for all pages. And then the initial model for page one differs from the one used when you opened page2. If you do not use the c:set but always directly use the param it might work too. And you effextively created a windowscoped which I meant to suggest to use. See deltaspike!

            – Kukeltje
            Jan 4 at 17:40













          • I actually checked and #{moduleBean.param} is not the same for all pages. It actually resolves to the correct query param sent, and use that to name all tables and components, works at view, and works in backing bean. Its just that the datatable is getting somehow confused

            – Alejandro Romanella
            Jan 4 at 17:42
















          2














          Without knowing more about the underlying bean - if you place your moduleBean in @SessionScoped this would be the expected behavior. The session (and session scoped beans) are shared between browser tabs. So you cannot rely on the underlying values from two different tabs.



          Try changing to @RequestScoped/@ViewScoped for the backing values of the table data.



          Here is a complete solution that works, note that this uses PrimeFaces 6.2, Apache Commons and Lombok;



          @Data
          @Named
          @ViewScoped
          public class TableTestBackingBean implements Serializable {
          private int param;

          @Inject
          private PersonsBean personsBean;

          public void onClicked() {
          System.out.println("Clicked fine!");
          }

          public List<Person> getPersons() {
          return personsBean.getPersons()[param];
          }
          }




          @Data
          @ApplicationScoped
          public class PersonsBean {
          @Data
          @AllArgsConstructor
          public class Person {
          private String firstName;
          private String lastName;
          private int age;
          }

          private List<Person> persons;

          @PostConstruct void init() {
          persons = new List[4];

          for (int j = 0; j < 4; j++) {
          persons[j] = new ArrayList<>();

          for (int i = 0; i < 30; i++) {
          final String firstName =
          RandomStringUtils.randomAlphanumeric(10);
          final String lastName =
          RandomStringUtils.randomAlphanumeric(10);
          final int age = RandomUtils.nextInt(0, 120);

          persons[j].add(new Person(firstName, lastName, age));
          }
          }
          }
          }




          <?xml version="1.0" encoding="UTF-8"?>
          <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
          xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core">
          <f:metadata>
          <f:viewParam name="param" value="#{tableTestBackingBean.param}"/>
          </f:metadata>
          <h:head>
          <title>Test</title>
          </h:head>
          <h:body>
          <p:dataTable value="#{tableTestBackingBean.persons}" var="t">
          <p:column headerText="First Name"><h:outputText value="#{t.firstName}" /></p:column>
          <p:column headerText="Last Name"><h:outputText value="#{t.lastName}" /></p:column>
          <p:column headerText="Age"><h:outputText value="#{t.age}" /></p:column>
          </p:dataTable>
          <h:form>
          <p:commandButton action="#{tableTestBackingBean.onClicked}" value="Click Me!" />
          </h:form>
          </h:body>
          </html>


          This uses an application scoped bean for the table data, keeping it completely static. This works without a hitch and the table renders the data differently based on the parameter passed in param.






          share|improve this answer


























          • Better to use a @ViewScoped bean for the ajax pagination, filtering and selection

            – Kukeltje
            Jan 4 at 17:29











          • I know they are shared, thats why my model which return the paginated results to the datatable is a map, thats get accessed by the param sent by the view. I keep all paginated results and data in the backing bean, so it should still take the correct one. Unfortunately its not enough to make it work

            – Alejandro Romanella
            Jan 4 at 17:30













          • ViewScoped isnt working for some reason at all. Thats why Im using session

            – Alejandro Romanella
            Jan 4 at 17:39











          • But #{moduleBean.param} is shared too so effectively identical for all pages. And then the initial model for page one differs from the one used when you opened page2. If you do not use the c:set but always directly use the param it might work too. And you effextively created a windowscoped which I meant to suggest to use. See deltaspike!

            – Kukeltje
            Jan 4 at 17:40













          • I actually checked and #{moduleBean.param} is not the same for all pages. It actually resolves to the correct query param sent, and use that to name all tables and components, works at view, and works in backing bean. Its just that the datatable is getting somehow confused

            – Alejandro Romanella
            Jan 4 at 17:42














          2












          2








          2







          Without knowing more about the underlying bean - if you place your moduleBean in @SessionScoped this would be the expected behavior. The session (and session scoped beans) are shared between browser tabs. So you cannot rely on the underlying values from two different tabs.



          Try changing to @RequestScoped/@ViewScoped for the backing values of the table data.



          Here is a complete solution that works, note that this uses PrimeFaces 6.2, Apache Commons and Lombok;



          @Data
          @Named
          @ViewScoped
          public class TableTestBackingBean implements Serializable {
          private int param;

          @Inject
          private PersonsBean personsBean;

          public void onClicked() {
          System.out.println("Clicked fine!");
          }

          public List<Person> getPersons() {
          return personsBean.getPersons()[param];
          }
          }




          @Data
          @ApplicationScoped
          public class PersonsBean {
          @Data
          @AllArgsConstructor
          public class Person {
          private String firstName;
          private String lastName;
          private int age;
          }

          private List<Person> persons;

          @PostConstruct void init() {
          persons = new List[4];

          for (int j = 0; j < 4; j++) {
          persons[j] = new ArrayList<>();

          for (int i = 0; i < 30; i++) {
          final String firstName =
          RandomStringUtils.randomAlphanumeric(10);
          final String lastName =
          RandomStringUtils.randomAlphanumeric(10);
          final int age = RandomUtils.nextInt(0, 120);

          persons[j].add(new Person(firstName, lastName, age));
          }
          }
          }
          }




          <?xml version="1.0" encoding="UTF-8"?>
          <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
          xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core">
          <f:metadata>
          <f:viewParam name="param" value="#{tableTestBackingBean.param}"/>
          </f:metadata>
          <h:head>
          <title>Test</title>
          </h:head>
          <h:body>
          <p:dataTable value="#{tableTestBackingBean.persons}" var="t">
          <p:column headerText="First Name"><h:outputText value="#{t.firstName}" /></p:column>
          <p:column headerText="Last Name"><h:outputText value="#{t.lastName}" /></p:column>
          <p:column headerText="Age"><h:outputText value="#{t.age}" /></p:column>
          </p:dataTable>
          <h:form>
          <p:commandButton action="#{tableTestBackingBean.onClicked}" value="Click Me!" />
          </h:form>
          </h:body>
          </html>


          This uses an application scoped bean for the table data, keeping it completely static. This works without a hitch and the table renders the data differently based on the parameter passed in param.






          share|improve this answer















          Without knowing more about the underlying bean - if you place your moduleBean in @SessionScoped this would be the expected behavior. The session (and session scoped beans) are shared between browser tabs. So you cannot rely on the underlying values from two different tabs.



          Try changing to @RequestScoped/@ViewScoped for the backing values of the table data.



          Here is a complete solution that works, note that this uses PrimeFaces 6.2, Apache Commons and Lombok;



          @Data
          @Named
          @ViewScoped
          public class TableTestBackingBean implements Serializable {
          private int param;

          @Inject
          private PersonsBean personsBean;

          public void onClicked() {
          System.out.println("Clicked fine!");
          }

          public List<Person> getPersons() {
          return personsBean.getPersons()[param];
          }
          }




          @Data
          @ApplicationScoped
          public class PersonsBean {
          @Data
          @AllArgsConstructor
          public class Person {
          private String firstName;
          private String lastName;
          private int age;
          }

          private List<Person> persons;

          @PostConstruct void init() {
          persons = new List[4];

          for (int j = 0; j < 4; j++) {
          persons[j] = new ArrayList<>();

          for (int i = 0; i < 30; i++) {
          final String firstName =
          RandomStringUtils.randomAlphanumeric(10);
          final String lastName =
          RandomStringUtils.randomAlphanumeric(10);
          final int age = RandomUtils.nextInt(0, 120);

          persons[j].add(new Person(firstName, lastName, age));
          }
          }
          }
          }




          <?xml version="1.0" encoding="UTF-8"?>
          <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
          xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core">
          <f:metadata>
          <f:viewParam name="param" value="#{tableTestBackingBean.param}"/>
          </f:metadata>
          <h:head>
          <title>Test</title>
          </h:head>
          <h:body>
          <p:dataTable value="#{tableTestBackingBean.persons}" var="t">
          <p:column headerText="First Name"><h:outputText value="#{t.firstName}" /></p:column>
          <p:column headerText="Last Name"><h:outputText value="#{t.lastName}" /></p:column>
          <p:column headerText="Age"><h:outputText value="#{t.age}" /></p:column>
          </p:dataTable>
          <h:form>
          <p:commandButton action="#{tableTestBackingBean.onClicked}" value="Click Me!" />
          </h:form>
          </h:body>
          </html>


          This uses an application scoped bean for the table data, keeping it completely static. This works without a hitch and the table renders the data differently based on the parameter passed in param.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 7 at 22:50

























          answered Jan 4 at 17:25









          Adam WaldenbergAdam Waldenberg

          774213




          774213













          • Better to use a @ViewScoped bean for the ajax pagination, filtering and selection

            – Kukeltje
            Jan 4 at 17:29











          • I know they are shared, thats why my model which return the paginated results to the datatable is a map, thats get accessed by the param sent by the view. I keep all paginated results and data in the backing bean, so it should still take the correct one. Unfortunately its not enough to make it work

            – Alejandro Romanella
            Jan 4 at 17:30













          • ViewScoped isnt working for some reason at all. Thats why Im using session

            – Alejandro Romanella
            Jan 4 at 17:39











          • But #{moduleBean.param} is shared too so effectively identical for all pages. And then the initial model for page one differs from the one used when you opened page2. If you do not use the c:set but always directly use the param it might work too. And you effextively created a windowscoped which I meant to suggest to use. See deltaspike!

            – Kukeltje
            Jan 4 at 17:40













          • I actually checked and #{moduleBean.param} is not the same for all pages. It actually resolves to the correct query param sent, and use that to name all tables and components, works at view, and works in backing bean. Its just that the datatable is getting somehow confused

            – Alejandro Romanella
            Jan 4 at 17:42



















          • Better to use a @ViewScoped bean for the ajax pagination, filtering and selection

            – Kukeltje
            Jan 4 at 17:29











          • I know they are shared, thats why my model which return the paginated results to the datatable is a map, thats get accessed by the param sent by the view. I keep all paginated results and data in the backing bean, so it should still take the correct one. Unfortunately its not enough to make it work

            – Alejandro Romanella
            Jan 4 at 17:30













          • ViewScoped isnt working for some reason at all. Thats why Im using session

            – Alejandro Romanella
            Jan 4 at 17:39











          • But #{moduleBean.param} is shared too so effectively identical for all pages. And then the initial model for page one differs from the one used when you opened page2. If you do not use the c:set but always directly use the param it might work too. And you effextively created a windowscoped which I meant to suggest to use. See deltaspike!

            – Kukeltje
            Jan 4 at 17:40













          • I actually checked and #{moduleBean.param} is not the same for all pages. It actually resolves to the correct query param sent, and use that to name all tables and components, works at view, and works in backing bean. Its just that the datatable is getting somehow confused

            – Alejandro Romanella
            Jan 4 at 17:42

















          Better to use a @ViewScoped bean for the ajax pagination, filtering and selection

          – Kukeltje
          Jan 4 at 17:29





          Better to use a @ViewScoped bean for the ajax pagination, filtering and selection

          – Kukeltje
          Jan 4 at 17:29













          I know they are shared, thats why my model which return the paginated results to the datatable is a map, thats get accessed by the param sent by the view. I keep all paginated results and data in the backing bean, so it should still take the correct one. Unfortunately its not enough to make it work

          – Alejandro Romanella
          Jan 4 at 17:30







          I know they are shared, thats why my model which return the paginated results to the datatable is a map, thats get accessed by the param sent by the view. I keep all paginated results and data in the backing bean, so it should still take the correct one. Unfortunately its not enough to make it work

          – Alejandro Romanella
          Jan 4 at 17:30















          ViewScoped isnt working for some reason at all. Thats why Im using session

          – Alejandro Romanella
          Jan 4 at 17:39





          ViewScoped isnt working for some reason at all. Thats why Im using session

          – Alejandro Romanella
          Jan 4 at 17:39













          But #{moduleBean.param} is shared too so effectively identical for all pages. And then the initial model for page one differs from the one used when you opened page2. If you do not use the c:set but always directly use the param it might work too. And you effextively created a windowscoped which I meant to suggest to use. See deltaspike!

          – Kukeltje
          Jan 4 at 17:40







          But #{moduleBean.param} is shared too so effectively identical for all pages. And then the initial model for page one differs from the one used when you opened page2. If you do not use the c:set but always directly use the param it might work too. And you effextively created a windowscoped which I meant to suggest to use. See deltaspike!

          – Kukeltje
          Jan 4 at 17:40















          I actually checked and #{moduleBean.param} is not the same for all pages. It actually resolves to the correct query param sent, and use that to name all tables and components, works at view, and works in backing bean. Its just that the datatable is getting somehow confused

          – Alejandro Romanella
          Jan 4 at 17:42





          I actually checked and #{moduleBean.param} is not the same for all pages. It actually resolves to the correct query param sent, and use that to name all tables and components, works at view, and works in backing bean. Its just that the datatable is getting somehow confused

          – Alejandro Romanella
          Jan 4 at 17:42




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54043288%2fhow-to-reuse-primefaces-datatable-with-different-data-in-different-browser-tabs%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Mossoró

          Can't read property showImagePicker of undefined in react native iOS

          Pushsharp Apns notification error: 'InvalidToken'