java - Data from ManagedBean doesn't refresh in the view -


i trying update data table list of products when call getcatalogproducts action doesn't refresh view. data doesn't appear in view.

this jsf's managedbean:

@managedbean(name = "catalog") @viewscoped public class catalogmgtbean {      private string value = "this value";     private list<port> products;     private catalogservice catalogservice;      public void loadcatalogproducts() {          catalogservice = new catalogserviceimpl();          products = catalogservice.getproducts();          this.value = "this value";     }      public list<port> getproducts() {         return products;     }      public void setproducts(list<port> products) {         this.products = products;     }      public string getvalue() {         return value;     }      public void setvalue(string value) {         this.value = value;     } } 

and view:

<?xml version="1.0" encoding="utf-8"?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en"  "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"     xmlns:h="http://java.sun.com/jsf/html"     xmlns:f="http://java.sun.com/jsf/core"     xmlns:ui="http://java.sun.com/jsf/facelets"     xmlns:p="http://primefaces.org/ui">  <h:head> </h:head> <h:body>     <h:form id="catalogform">         <p:datatable id="productsdt" paginator="true" paginatorposition="bottom"             rows="10" value="#{products}" var="products">             <p:column headertext="id">                 <h:outputtext value="#{products.id}" />             </p:column>             <p:column headertext="id">                 <h:outputtext value="#{products.nombre}" />             </p:column>             <p:column headertext="id">                 <h:outputtext value="#{products.nacional}" />             </p:column>             <p:column headertext="fecha">                 <h:outputtext value="#{products.fecha}">                     <f:convertdatetime pattern="dd/mm/yyyy" />                 </h:outputtext>             </p:column>             <p:column headertext="estado">                 <h:outputtext value="#{products.estado}" />             </p:column>         </p:datatable>         <p:commandbutton id="gettingproducts" value="getting products..."         action="#{catalog.loadcatalogproducts()}" update="productsdt" />     </h:form> </h:body> </html> 

when press gettingproducts commandbutton calls getcatalogproducts action doesn't refresh view data.

what wrong?

i putting additional information. web.xml file:

<?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xmlns="http://java.sun.com/xml/ns/javaee"      xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"     xsi:schemalocation="http://java.sun.com/xml/ns/javaee      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"     id="webapp_id" version="2.5">    <display-name>jsac</display-name>  <context-param>     <param-name>javax.faces.project_stage</param-name>     <param-value>development</param-value> </context-param>  <!-- welcome page --> <welcome-file-list>     <welcome-file>index.xhtml</welcome-file> </welcome-file-list>  <!-- servlets --> <!-- javaserver faces --> <servlet>     <servlet-name>faces servlet</servlet-name>     <servlet-class>javax.faces.webapp.facesservlet</servlet-class>     <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping>     <servlet-name>faces servlet</servlet-name>     <url-pattern>*.xhtml</url-pattern> </servlet-mapping> 

and pom.xml file:

<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">     <modelversion>4.0.0</modelversion>     <groupid>jsac</groupid>     <artifactid>jsac</artifactid>     <version>0.0.1-snapshot</version>     <packaging>war</packaging>     <name>jsac</name>      <properties>          <!-- generic properties -->         <java.version>1.6</java.version>         <project.build.sourceencoding>utf-8</project.build.sourceencoding>         <project.reporting.outputencoding>utf-8</project.reporting.outputencoding>          <!-- web -->         <jsp.version>2.2</jsp.version>         <jstl.version>1.2</jstl.version>         <servlet.version>2.5</servlet.version>      </properties>      <repositories>         <repository>             <id>prime-repo</id>             <name>prime repo</name>             <url>http://repository.primefaces.org</url>         </repository>     </repositories>      <dependencies>          <!-- primefaces -->         <dependency>             <groupid>org.primefaces</groupid>             <artifactid>primefaces</artifactid>             <version>3.3</version>         </dependency>          <!-- jsf -->         <dependency>             <groupid>com.sun.faces</groupid>             <artifactid>jsf-api</artifactid>             <version>2.1.11</version>         </dependency>         <dependency>             <groupid>com.sun.faces</groupid>             <artifactid>jsf-impl</artifactid>             <version>2.1.11</version>         </dependency>          <!-- postgres db -->         <dependency>             <groupid>postgresql</groupid>             <artifactid>postgresql</artifactid>             <version>9.0-801.jdbc4</version>         </dependency>          <!-- servlet -->         <dependency>             <groupid>javax.servlet</groupid>             <artifactid>jstl</artifactid>             <version>${jstl.version}</version>         </dependency>          <dependency>             <groupid>javax.servlet</groupid>             <artifactid>servlet-api</artifactid>             <version>${servlet.version}</version>         </dependency>          <dependency>             <groupid>javax.servlet.jsp</groupid>             <artifactid>jsp-api</artifactid>             <version>${jsp.version}</version>         </dependency>          <!-- javamelody -->         <dependency>             <groupid>net.bull.javamelody</groupid>             <artifactid>javamelody-core</artifactid>             <version>1.46.0</version>         </dependency>      </dependencies>      <build>         <plugins>             <plugin>                 <groupid>org.apache.maven.plugins</groupid>                 <artifactid>maven-compiler-plugin</artifactid>                 <version>2.3.2</version>                 <configuration>                     <source>${java.version}</source>                     <target>${java.version}</target>                 </configuration>             </plugin>         </plugins>     </build> </project> 

and faces-config.xml:

<?xml version="1.0" encoding="utf-8"?> <faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xsi:schemalocation="http://java.sun.com/xml/ns/javaee      http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1_24.xsd" version="2.1">      <application>         <resource-bundle>             <base-name>i18n.messages</base-name>             <var>msg</var>         </resource-bundle>     </application> </faces-config> 

apart <p:commandbutton update> should specify components you'd update, you're navigating non-null/void outcome. in other words, you're creating new view. in other words, old view , view scoped beans associated destroyed. new view create new view scoped bean. view scoped beans identified view, new view not reference same view scoped bean anymore wherein loaded new list.

just make action method void (i'd clarity rename absolutely not getter).

public void loadcatalogproducts() {     catalogservice = new catalogserviceimpl();     products = catalogservice.getproducts();     this.value = "this value"; } 

this way same view reused , existing view scoped beans associated remain alive.

second problem you're not binding <p:datatable value> bean property. need bind #{catalog.products} instead of #{products} not exist managed bean.

see also:


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -