0 Replies Latest reply on Feb 21, 2013 10:40 AM by Siva P

    RichFaces 4.2.3 Final  datatable not rendering in screen

    Siva P Master

      Hello,

       

      I have attachedthe screen short.Where datatable is not rendering properly in the screen.

       

      1.jpg

      <rich:autocomplete value="#{loginBean.state}" minChars="1" autocompleteMethod="#{loginBean.autocomplete}" />

                <a4j:commandButton value="GetDetails" actionListener="#{loginBean.readEmployeeDetails}" render="empID"></a4j:commandButton> 

       

      After clicking command button i have to get the value from the bean and display as in data base,Back end its calling properly.that u can see in the image attached.

      How to display or render it to screen to view?Thanks

      login.xhml:

      <!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:ui="http://java.sun.com/jsf/facelets"

                xmlns:h="http://java.sun.com/jsf/html"

                xmlns:f="http://java.sun.com/jsf/core"

                xmlns:a4j="http://richfaces.org/a4j"

          xmlns:rich="http://richfaces.org/rich">

       

       

      <!-- <ui:composition template="/WEB-INF/templates/BasicTemplate.xhtml">

       

                <ui:define name="content">

                   <h:form>  

                  <h:panelGrid columns="2">

                      <h:outputText value="Name"></h:outputText>

                      <h:inputText value="#{loginBean.name}"></h:inputText>

                      <h:outputText value="Password"></h:outputText>

                      <h:inputSecret value="#{loginBean.password}"></h:inputSecret>

                  </h:panelGrid>

                  <h:commandButton value="Login" action="login"></h:commandButton>

                 

                  <br />

       

           <h:outputText value="Enter your state" />

           <rich:autocomplete value="#{loginBean.state}" minChars="1" autocompleteMethod="#{loginBean.autocomplete}" />

          

              </h:form>

                </ui:define>

       

      </ui:composition> -->

       

       

      <f:view>

      <h:head></h:head>

      <h:body>

       

       

      <rich:panel header="Richfaces sample validation and auto-completion">

         <h:form>

           <h:panelGrid columns="2">

                      <h:outputText value="Name"></h:outputText>

                      <h:inputText value="#{loginBean.name}"></h:inputText>

                      <h:outputText value="Password"></h:outputText>

                      <h:inputSecret value="#{loginBean.password}"></h:inputSecret>

                  </h:panelGrid>

                  <h:commandButton value="Login" action="login"></h:commandButton>

           <br />

       

       

           <h:outputText value="Enter employee name:" />

           <rich:autocomplete value="#{loginBean.state}" minChars="1" autocompleteMethod="#{loginBean.autocomplete}" />

                <a4j:commandButton value="GetDetails" actionListener="#{loginBean.readEmployeeDetails}" render="empID"></a4j:commandButton> 

       

                <br/>

                <br/>

       

                <rich:dataTable id="empID" value="#{loginBean.employeelstforDisplay}" var="employee" rendered="#{loginBean.flagdisplay}" >

       

                          <rich:column>

                                    <f:facet name="header">

                                     <h:outputText value="Employee No"></h:outputText>

                                    </f:facet>

                                    <h:outputText value="#{employee.employee_id}"/>

                          </rich:column>

       

                          <rich:column>

                                    <f:facet name="header">

                                     <h:outputText value="Employee Name"></h:outputText>

                                    </f:facet>

                                    <h:outputText value="#{employee.employee_name}"/>

                          </rich:column>

       

                          <rich:column>

                                    <f:facet name="header">

                                     <h:outputText value="Employee Dept"></h:outputText>

                                    </f:facet>

                                    <h:outputText value="#{employee.employee_dept}"/>

                          </rich:column>

       

                          <rich:column>

                                    <f:facet name="header">

                                     <h:outputText value="Employee Role"></h:outputText>

                                    </f:facet>

                                    <h:outputText value="#{employee.employee_role}"/>

                          </rich:column>

       

                          </rich:dataTable>

         </h:form>

      </rich:panel>   

       

       

      </h:body>

      </f:view>

      <!-- </ui:composition> -->

       

       

       

       

      </html>

       

      Bean:

      package com.read.employee;

       

       

      import java.io.BufferedReader;

      import java.io.DataInputStream;

      import java.io.FileInputStream;

      import java.io.InputStreamReader;

      import java.util.ArrayList;

      import java.util.HashMap;

      import java.util.Iterator;

      import java.util.List;

      import java.util.StringTokenizer;

       

       

      import javax.faces.bean.ManagedBean;

      import javax.faces.event.ActionEvent;

       

       

      @ManagedBean

      public class LoginBean {

       

                private String name ="";

          private String password="";

          private String state="";

          private boolean flagdisplay = false;

       

                List<UserBean> employeelst= new ArrayList<UserBean>();

          List<UserBean> employeelstforDisplay = new ArrayList<UserBean>();

                HashMap<String, UserBean> mapEmployee = new HashMap<String, UserBean>();

         

         

          public LoginBean()

          {

                    List<String> listLine = new ArrayList<String>();

                    String strLine;    

                    try {

                  // Open the file that is the first

                  // command line parameter

                  FileInputStream fstream = new FileInputStream("D://sample.txt");

                  // Get the object of DataInputStream

                  DataInputStream in = new DataInputStream(fstream);

                  BufferedReader br = new BufferedReader(new InputStreamReader(in));

                 

                  //Read File Line By Line

                  while ((strLine = br.readLine()) != null)   {

                  // Print the content on the console

                            listLine.add(strLine.trim());

                 

                  }           

                  for(String objLine:listLine)

                  {

                             System.out.println(objLine);

                             StringTokenizer st = new StringTokenizer(objLine, ",");

                             while(st.hasMoreTokens()) {

                             String employeeid = st.nextToken();

                             String employeename = st.nextToken();

                             String employeedept = st.nextToken();

                             String employeerole = st.nextToken();

                            

                             UserBean user = new UserBean();

                             user.setEmployee_id(employeeid);

                             user.setEmployee_name(employeename);

                             user.setEmployee_dept(employeedept);

                             user.setEmployee_role(employeerole);

                             employeelst.add(user);

                             mapEmployee.put(employeename, user);

                            

                             }

                  }         

               

                  // Close the input stream

                  in.close();

              } catch (Exception e) {// Catch exception if any

                  System.err.println("Error: " + e.getMessage());

              }

          }

         

          public boolean isFlagdisplay() {

                            return flagdisplay;

                  }

       

       

       

       

                  public void setFlagdisplay(boolean flagdisplay) {

                            this.flagdisplay = flagdisplay;

                  }   

       

       

          public List<UserBean> getEmployeelstforDisplay() {

                          return employeelstforDisplay;

                }

       

       

                public void setEmployeelstforDisplay(List<UserBean> employeelstforDisplay) {

                          this.employeelstforDisplay = employeelstforDisplay;

                }

       

       

       

       

          public String getState() {

                          return state;

                }

       

       

       

       

                public void setState(String state) {

                          this.state = state;

                }

       

       

       

       

                public String getName ()

          {

              return name;

          }

       

       

       

       

          public void setName (final String name)

          {

              this.name = name;

          }

       

       

       

       

          public String getPassword ()

          {

              return password;

          }

       

       

       

       

          public void setPassword (final String password)

          {

              this.password = password;

          }

         

          public List<String> autocomplete(String prefix) {  

       

       

                    System.out.println("StartsWith:"+prefix);

                    ArrayList<String> result = new ArrayList<String>();  

                    for(UserBean beanObj:employeelst)

                    {

                              if(beanObj.getEmployee_name().toLowerCase().startsWith(prefix))

                              {

                                        result.add(beanObj.getEmployee_name());

                              }

                    }

               return result;

          }

         

         

          public void readEmployeeDetails()

          {

                    if(!employeelstforDisplay.isEmpty())

                    {

                              employeelstforDisplay = new ArrayList<UserBean>();  

                    }

                    System.out.println("Entering.....:"+state);

                    UserBean detailslist = mapEmployee.get(state);

                    System.out.println(detailslist.getEmployee_name());

                    employeelstforDisplay.add(detailslist);

                    setEmployeelstforDisplay(employeelstforDisplay);

                    flagdisplay = true;

                    System.out.println("Ending.....");

          }

         

          public void showempDetails(ActionEvent event)

          {

                    if(!employeelstforDisplay.isEmpty())

                    {

                              employeelstforDisplay = new ArrayList<UserBean>();  

                    }

                    System.out.println("Entering.....:"+state);

                    UserBean detailslist = mapEmployee.get(state);

                    System.out.println(detailslist.getEmployee_name());

                    employeelstforDisplay.add(detailslist);

                    setEmployeelstforDisplay(employeelstforDisplay);

                    flagdisplay = true;

                    System.out.println("Ending.....");

          }

       

       

      }

       

      Is it problem with RF version???

       

      Thanks,

      Siva