users@javaserverfaces.java.net

prime the pump for DataTable columns?

From: Thufir <hawat.thufir_at_gmail.com>
Date: Mon, 19 Apr 2010 03:03:57 +0000 (UTC)

I thought I'd figured JSF out, at least how to view data. The managed
bean Beatles has a List<Beatle> with correct data -- at least it shows on
the tomcat logs correctly. From experience, the trio of pages (template,
index and table) do generate output correctly. (In this case,
beatleTemplate.xhtml, index.xhtml and view.xhtml, for the record.)

Is there perhaps an additional requirement to "prime the pump" with
regards to the backing bean Beatle? The constructor for Beatle was never
called, despite Beatles.java having a List<Beatle>, I cast a List<String>
to List<Beatle> and then logged the resulting List to confirm its
correctness.

As it's indeed a List<Beatle>, and I *believe* the .xhtml clients and
template to be correct (enough to generate output in the past), why
aren't they generating output currently?

I'll go back to manually creating a few Beatles just to confirm that, of
course.

Somewhat lengthy code to follow:




login_at_dtc01l0471-05:~$
login_at_dtc01l0471-05:~$ nl NetBeansProjects/A00720398/src/java/
managedBeans/Beatles.java
     1 /*
     2 * To change this template, choose Tools | Templates
     3 * and open the template in the editor.
     4 */
     5 package managedBeans;
       
     6 /**
     7 *
     8 * @author
     9 */
    10 import database.ParametersEnum;
    11 import java.util.ArrayList;
    12 import java.util.List;
    13 import java.util.logging.Level;
    14 import java.util.logging.Logger;
    15 import javax.faces.bean.ManagedBean;
    16 import javax.faces.bean.SessionScoped;
    17 import javax.faces.context.FacesContext;
    18 import javax.servlet.ServletContext;
       
    19 /**
    20 *
    21 * @author a00720398
    22 */
    23 @ManagedBean(name = "beatles")
    24 @SessionScoped
    25 public class Beatles<Beatle> {
       
    26 //public static final Beatles INSTANCE = new Beatles();
    27 private static Logger logger = Logger.getLogger
(managedBeans.Beatles.class.getName());
    28 private List<Beatle> list = new ArrayList<Beatle>();
       
    29 private ParametersEnum initParams() {
    30 FacesContext fctx = FacesContext.getCurrentInstance();
    31 ServletContext servletContext = (ServletContext)
fctx.getExternalContext().getContext();
    32 ParametersEnum mp = ParametersEnum.INSTANCE;
    33 mp.initializeDB(servletContext);
    34 return mp;
    35 }
       
    36 public Beatles() {
    37 logger.log(Level.INFO, "Beatles...");
    38 BeatlesOperations beatlesOperations =
BeatlesOperations.getInstance();
    39 list = (List<Beatle>) beatlesOperations.populateBeatles
(initParams());
    40 }
       
    41 public List<Beatle> getList() {
    42 logger.log(Level.INFO, list.toString());
    43 return list;
    44 }
       
    45 public void setList(List<Beatle> list) {
    46 this.list = list;
    47 }
    48 }
       
login_at_dtc01l0471-05:~$
login_at_dtc01l0471-05:~$ nl NetBeansProjects/A00720398/src/java/
managedBeans/Beatle.java
     1 /*
     2 * To change this template, choose Tools | Templates
     3 * and open the template in the editor.
     4 */
     5 package managedBeans;
       
     6 import data.AbstractDataType;
     7 import java.util.List;
     8 import java.util.logging.Level;
     9 import java.util.logging.Logger;
    10 import javax.faces.bean.ManagedBean;
    11 import javax.faces.bean.SessionScoped;
       
    12 /**
    13 *
    14 * @author
    15 */
    16 @ManagedBean(name = "beatle")
    17 @SessionScoped
    18 public class Beatle extends AbstractDataType {
       
    19 private int id;
    20 private String code, artist, title, year, time, total, label,
comments;
    21 private static Logger logger = Logger.getLogger
(managedBeans.Beatle.class.getName());
       
    22 /** Creates a new instance of Beatle */
    23 public Beatle() {
    24 logger.log(Level.INFO, "new beatle");
    25 }
       
    26 @Override
    27 public void set(List<String> record) {
    28 logger.log(Level.INFO, "set beatle as\n\n" +
record.toString());
    29 code = record.get(0);
    30 artist = record.get(1);
    31 title = record.get(2);
    32 year = record.get(3);
    33 time = record.get(4);
    34 total = record.get(5);
    35 label = record.get(6);
    36 comments = record.get(7);
    37 }
       
    38 /**
    39 * @return the id
    40 */
    41 public int getId() {
    42 return id;
    43 }
       
    44 /**
    45 * @param id the id to set
    46 */
    47 public void setId(int id) {
    48 this.id = id;
    49 }
       
    50 private int getMaxId() {
    51 return 99;
    52 }
       
    53 /**
    54 * @return the code
    55 */
    56 public String getCode() {
    57 return code;
    58 }
       
    59 /**
    60 * @param code the code to set
    61 */
    62 public void setCode(String code) {
    63 this.code = code;
    64 }
       
    65 /**
    66 * @return the artist
    67 */
    68 public String getArtist() {
    69 return artist;
    70 }
       
    71 /**
    72 * @param artist the artist to set
    73 */
    74 public void setArtist(String artist) {
    75 this.artist = artist;
    76 }
       
    77 /**
    78 * @return the title
    79 */
    80 public String getTitle() {
    81 return title;
    82 }
       
    83 /**
    84 * @param title the title to set
    85 */
    86 public void setTitle(String title) {
    87 this.title = title;
    88 }
       
    89 /**
    90 * @return the year
    91 */
    92 public String getYear() {
    93 return year;
    94 }
       
    95 /**
    96 * @param year the year to set
    97 */
    98 public void setYear(String year) {
    99 this.year = year;
   100 }
       
   101 /**
   102 * @return the time
   103 */
   104 public String getTime() {
   105 return time;
   106 }
       
   107 /**
   108 * @param time the time to set
   109 */
   110 public void setTime(String time) {
   111 this.time = time;
   112 }
       
   113 /**
   114 * @return the total
   115 */
   116 public String getTotal() {
   117 return total;
   118 }
       
   119 /**
   120 * @param total the total to set
   121 */
   122 public void setTotal(String total) {
   123 this.total = total;
   124 }
       
   125 /**
   126 * @return the label
   127 */
   128 public String getLabel() {
   129 return label;
   130 }
       
   131 /**
   132 * @param label the label to set
   133 */
   134 public void setLabel(String label) {
   135 this.label = label;
   136 }
       
   137 /**
   138 * @return the comments
   139 */
   140 public String getComments() {
   141 return comments;
   142 }
       
   143 /**
   144 * @param comments the comments to set
   145 */
   146 public void setComments(String comments) {
   147 this.comments = comments;
   148 }
   149 }
login_at_dtc01l0471-05:~$
login_at_dtc01l0471-05:~$ nl NetBeansProjects/A00720398/web/beatles/
index.xhtml
     1 <?xml version='1.0' encoding='UTF-8' ?>
     2 <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//
EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     3 <ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
     4 template="./beatlesTemplate.xhtml">
     5
     6 <ui:define name="top">
     7 top
     8 </ui:define>
       
     9 <ui:define name="content">
    10 <ui:include src="read.xhtml"/>
    11 </ui:define>
       
    12 </ui:composition>
login_at_dtc01l0471-05:~$
login_at_dtc01l0471-05:~$ nl NetBeansProjects/A00720398/web/beatles/
read.xhtml
     1 <?xml version='1.0' encoding='UTF-8' ?>
     2 <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//
EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     3 <ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
     4 xmlns:h="http://java.sun.com/jsf/html"
     5 xmlns:f="http://java.sun.com/jsf/core"
     6 template="./beatlesTemplate.xhtml">
     7 <ui:define name="content">
     8 <h:dataTable value="#{beatles.list}"
     9 var="name">
    10 <h:column>
    11 <h:outputText value="#{beatle.title}, "/>
    12 </h:column>
    13 <h:column>
    14 <h:outputText value="#{beatle.comments}"/>
    15 </h:column>
    16 </h:dataTable>
    17 </ui:define>
    18 </ui:composition>
login_at_dtc01l0471-05:~$
login_at_dtc01l0471-05:~$ nl NetBeansProjects/A00720398/web/beatles/
beatlesTemplate.xhtml
     1 <?xml version='1.0' encoding='UTF-8' ?>
     2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     3 <html xmlns="http://www.w3.org/1999/xhtml"
     4 xmlns:ui="http://java.sun.com/jsf/facelets"
     5 xmlns:h="http://java.sun.com/jsf/html">
     6
     7 <h:head>
     8 <meta http-equiv="Content-Type" content="text/html;
charset=UTF-8" />
     9 <link href="./../resources/css/default.css"
rel="stylesheet" type="text/css" />
    10 <link href="./../resources/css/cssLayout.css"
rel="stylesheet" type="text/css" />
    11 <title>Facelets Template</title>
    12 </h:head>
    13
    14 <h:body>
    15
    16 <div id="top" class="top">
    17 <ui:insert name="top">Top</ui:insert>
    18 </div>
    19
    20 <div id="content" class="center_content">
    21 <ui:insert name="content">Content</ui:insert>
    22 </div>
    23
    24 </h:body>
    25
    26 </html>
login_at_dtc01l0471-05:~$






thanks,

Thufir