JSF datatable values are not displayed - jsf

Unfortunately, all the values I entered are not displayed on the website, does anyone have an idea why?
On picture 1 I have screenshotted the output.
Programming with JSF for the first time and with Java was a long time ago...
Here is my products.xhtml
<?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://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>JSF Datatable h:dataTable tag demo</title>
</h:head>
<h:body>
<ui:composition template="template/master.xhtml">
<ui:define name="content">
<h:form>
<h:dataTable value = "#{productBean.findAll}"
var = "item"
style="border: 3px solid #FF0000; width:100%"
rows="10"
border="1"
cellpadding="20"
cellspacing="20">
<h:column>
<f:facet name="header"> Produkt ID </f:facet>
<h:outputText value="#{item.id}" />
</h:column>
<h:column>
<f:facet name="header"> Produktname </f:facet>
<h:outputText value="#{item.name}" />
</h:column>
<h:column>
<f:facet name="header" > Preis </f:facet>
<h:outputText value="#{item.preis}" />
</h:column>
<h:column>
<f:facet name="header"> Beschreibung </f:facet>
<h:outputText value="#{item.beschreibung}" />
</h:column>
<h:column>
<f:facet name="header"> Foto</f:facet>
<h:graphicImage library="images" name="item.bildpfad"></h:graphicImage>
</h:column>
<h:column>
<f:facet name="header"> Stückzahl </f:facet>
<h:outputText value="#{item.stückzahl}" />
</h:column>
</h:dataTable>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
My ProductDemo.java
package com.mycompany.kuechenstudio.model;
import java.util.ArrayList;
import java.util.List;
public class ProductDemo {
public List<Product> findAll(){
List<Product> productsList = new ArrayList<>();
productsList.add(new Product(1,"Kühlschrank",400f, "weiß",
"/images/Kühlschrank.jpg",1));
productsList.add(new Product(2,"Tisch ",300f, "braun",
"/images/Küchentisch.jpg",5));
productsList.add(new Product(3,"Schrank1",150f, "klein",
"/images/Küchenschrank_klein.jpg",3));
productsList.add(new Product(4,"Schrank2",200f, "groß",
"/images/Küchenschrank_groß.jpg",2));
productsList.add(new Product(5,"Spülmaschine",350f,"schnell",
"/images/Spülmaschine.jpg",6));
return productsList;
}
}
My Product.java
package com.mycompany.kuechenstudio.model;
public class Product {
private int id;
private String name;
private float preis;
private String beschreibung;
private String bildpfad;
private int stückzahl;
public int getStückzahl(){
return stückzahl;
}
public void setStückzahl(int stückzahl) {
this.stückzahl = stückzahl;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public float getpreis() {
return preis;
}
public String getBeschreibung() {
return beschreibung;
}
public void setBeschreibung(String beschreibung) {
this.beschreibung = beschreibung;
}
public String getBildpfad() {
return bildpfad;
}
public void setBildpfad(String bildpfad) {
this.bildpfad = bildpfad;
}
public void setId(int id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setPreis(float preis) {
this.preis = preis;
}
public Product(int id, String name, float preis, String beschreibung,
String bildpfad, int stückzahl) {
super();
this.id = id;
this.name = name;
this.preis = preis;
this.beschreibung = beschreibung;
this.bildpfad = bildpfad;
this.stückzahl = stückzahl;
}
}
My beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
bean-discovery-mode="all">
<managed-bean>
<managed-bean-name>productBean</managed-bean-name>
<managed-bean-class>com.jsf.datatable.ProductDemo</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
Die Ausgabe

I got it. The ProductDemo.java must be in a managed bean and the value in the xhtml didnt match with the java class

Related

JSF Rendered property Issue

So, i have this piece of code, which basically performs CRUD on a database and displays the results in a <h:dataTable>. The problem is, my code is able to generate an edit action, when I provide a fixed ArrayList. But, if i populate the ArrayList from a database, the rendered property does not provide an editable option from the form. I am able to perform delete functionality, so it's not a matter of the object not being read properly in the action method's parameter. In short, the rendered attribute doesn't work when my data source is a table from a database.
Here's the page:
index.xhtml
<?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"
>
<h:head>
</h:head>
<h:body>
<h1>JSF 2 dataTable example</h1>
<h:form>
<h:dataTable value="#{order.orderList}" var="o"
styleClass="order-table"
headerClass="order-table-header"
rowClasses="order-table-odd-row,order-table-even-row"
>
<h:column>
<f:facet name="header">Order No</f:facet>
<h:inputText value="#{o.orderNo}" size="10" rendered="#
{o.editable}" />
<h:outputText value="#{o.orderNo}" rendered="#{not o.editable}" />
</h:column>
<h:column>
<f:facet name="header">Product Name</f:facet>
<h:inputText value="#{o.productName}" size="20" rendered="#
{o.editable}" />
<h:outputText value="#{o.productName}" rendered="#{not o.editable}"
/>
</h:column>
<h:column>
<f:facet name="header">Price</f:facet>
<h:inputText value="#{o.price}" size="10" rendered="#{o.editable}"
/>
<h:outputText value="#{o.price}" rendered="#{not o.editable}" />
</h:column>
<h:column>
<f:facet name="header">Quantity</f:facet>
<h:inputText value="#{o.qty}" size="5" rendered="#{o.editable}"
/>
<h:outputText value="#{o.qty}" rendered="#{not o.editable}" />
</h:column>
<h:column>
<f:facet name="header">Action</f:facet>
<h:commandButton value="Edit" action ="#{order.editAction(o)}">
<f:setPropertyActionListener
target = "#{Orders}" value = "#{o}" />
</h:commandButton>
</h:column>
<h:column>
<f:facet name ="header">Action</f:facet>
<h:commandButton value ="Delete" action="#
{order.delete(o)}"/>
</h:column>
</h:dataTable>
</h:form>
</h:body>
</html>
The orderBean.java:
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Arrays;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
#ManagedBean(name="order")
#RequestScoped
public class orderBean implements Serializable{
private static final long serialVersionUID = 1L;
private static ArrayList<Orders> orderList;
public ArrayList<Orders> getOrderList() {
try{
orderBean.orderList = new ArrayList();
Class.forName("com.mysql.jdbc.Driver");
Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/orders","root","");
PreparedStatement ps = conn.prepareStatement("Select *
from Orders");
ResultSet rs = ps.executeQuery();
while(rs.next())
{
Orders orders = new
Orders(rs.getString("orderNo"),rs.getString("productName"),
rs.getBigDecimal("price"),rs.getInt("qty"));
orderList.add(orders);
}
}
catch(Exception e)
{
}
return orderList;
}
public void delete(Orders order)
{
try{
orderBean.orderList = new ArrayList();
Class.forName("com.mysql.jdbc.Driver");
Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/orders","root","");
PreparedStatement ps = conn.prepareStatement("Delete
from orders where orderNo=?");
ps.setString(1,order.orderNo);
int rs = ps.executeUpdate();
}
catch(Exception e)
{
}
}
public void editAction(Orders order) {
order.setEditable(true);
}
public static class Orders{
String orderNo;
String productName;
BigDecimal price;
int qty;
boolean editable;
public Orders(String orderNo, String productName, BigDecimal price, int
qty) {
this.orderNo = orderNo;
this.productName = productName;
this.price = price;
this.qty = qty;
}
public void setOrderNo(String orderNo)
{
this.orderNo = orderNo;
}
public void setProductName(String productName)
{
this.productName = productName;
}
public void setPrice(BigDecimal price)
{
this.price = price;
}
public void setQty(int qty){
this.qty = qty;
}
public String getOrderNo()
{
return this.orderNo;
}
public String getProductName()
{
return this.productName;
}
public BigDecimal getPrice()
{
return this.price;
}
public int getQty()
{
return this.qty;
}
public boolean isEditable() {
return this.editable;
}
public void setEditable(Boolean editable) {
this.editable = editable;
}
//getter and setter methods
}
}

Get to specific book using hyperlink in JSF [duplicate]

This question already has answers here:
Creating master-detail pages for entities, how to link them and which bean scope to choose
(2 answers)
Closed 7 years ago.
I have a very strange situation here. I have made my application in JSF and it looks just great, however I am not quite sure about following: I want to have a hyperlink so that once I click on my book title I get to a page with all the details regarding that book. My code looks so far:
My class looks like this:
package com.century.rental;
import javax.ejb.Stateless;
import javax.persistence.*;
import java.util.List;
#Stateless
public class GameEJB {
#PersistenceContext(unitName = "PerUni")
private EntityManager em;
public List<Game> findGames() {
TypedQuery<Game> query = em.createNamedQuery("Game.findAll", Game.class);
return query.getResultList();
}
public List<Game> findGamesByTitle(String title) {
TypedQuery<Game> query = em.createNamedQuery("Game.findByTitle", Game.class);
query.setParameter("title", title);
return query.getResultList();
}
public Game find(Long id) {
return em.find(Game.class, id);
}
public Game createGame(Game game) {
em.persist(game);
System.out.print("game stored");
return game;
}
}
My controller class looks like this:
package com.century.rental;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
#ManagedBean
#SessionScoped
public class GameController {
#EJB
private GameEJB gameEJB;
private Game game = new Game();
private String title = new String();
private List<Game> gameList = new ArrayList<Game>();
private List<Game> sgameList = new ArrayList<Game>();
public GameController() {
}
public String doCreateGame() {
gameEJB.createGame(game);
gameList = gameEJB.findGames();
game = new Game();
return "listGames.xhtml";
}
public Game getGame() {
return this.game;
}
public void setGame(Game game) {
this.game = game;
}
public List<Game> getGameList() {
gameList = gameEJB.findGames();
return gameList;
}
public void setGameList(List<Game> gameList) {
this.gameList = gameList;
}
public String searchGames() {
sgameList = gameEJB.findGamesByTitle(title);
return "resultsGames.xhtml";
}
public List<Game> getSgameList() {
return sgameList;
}
public void setSbookList(List<Game> sgameList) {
this.sgameList = sgameList;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
Entity:
package com.century.rental;
import java.util.Date;
import javax.persistence.*;
#Entity
#NamedQueries({
#NamedQuery(name = "Game.findAll", query = "SELECT g FROM Game g"),
#NamedQuery(name = "Game.findByTitle", query = "SELECT g FROM Game g WHERE g.title = :title")
})
public class Game extends Product {
#Basic(optional = false)
#Column(name = "DEVELOPER_STUDIO", nullable = false, length = 100)
private String developerStudio;
#Basic(optional = false)
#Column(name = "PLATFORM", nullable = false, length = 100)
private String platform;
public Game() {
}
public Game(String title, String description, String rating, Date releaseDate, String developerStudio, String platform) {
super(title, description, rating, releaseDate);
this.developerStudio = developerStudio;
this.platform = platform;
}
public String getDeveloperStudio() {
return developerStudio;
}
public void setDeveloperStudio(String developerStudio) {
this.developerStudio = developerStudio;
}
public String getPlatform() {
return platform;
}
public void setPlatform(String platform) {
this.platform = platform;
}
}
My HTML code looks like this:
<?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">
<h:head>
<title>List of All Available Games in Database</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</h:head>
<h:body>
<f:view>
<h:form>
<h1><h:outputText value="List of All Available Games in Database"/></h1>
<h:dataTable value="#{gameController.gameList}" var="item" border="1">
<h:column>
<f:facet name="header">
<h:outputText value="Id"/>
</f:facet>
<h:outputText value="#{item.id}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Title"/>
</f:facet>
<h:outputText value="#{item.title}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Description"/>
</f:facet>
<h:outputText value="#{item.description}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Rating"/>
</f:facet>
<h:outputText value="#{item.rating}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Release Date"/>
</f:facet>
<h:outputText value="#{item.releaseDate}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Developer Studio"/>
</f:facet>
<h:outputText value="#{item.developerStudio}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Platform"/>
</f:facet>
<h:outputText value="#{item.platform}"/>
</h:column>
</h:dataTable>
</h:form>
</f:view>
<br /><br />
Add New -OR- Go to Main Page
</h:body>
</html>
Please, help me I am not quite sure how can I make a hyperlink to a specific book from a list of books( as shown in the code )
Thanks.
P.S.
My specific page specificGame, which is supposed to get values from a game that was clicked in listGames page.
<?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">
<h:head>
<title>List specific Game in Database</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</h:head>
<h:body>
<f:view>
<h:form>
<h1><h:outputText value="List a specific Game in Database"/></h1>
<h:dataTable value="#{GameController.sGameList}" var="item" border="1">
<h:column>
<f:facet name="header">
<h:outputText value="Name"/>
</f:facet>
<h:outputText value="#{item.name}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Title"/>
</f:facet>
<h:outputText value="#{item.title}"/>
</h:column
</h:dataTable>
</h:form>
</f:view>
<br /><br />
Add New -OR- Go to Main Page
</h:body>
</html>
Now when I click on a title from the list of games on page list Games I would be redirected to specific Game page which is supposed to look like this: http://i.stack.imgur.com/OHmdp.png
populated by all the values from the particular game.
Try to change the column title in listGames.xhtml to :
<h:column>
<f:facet name="header">
<h:outputText value="Title"/>
</f:facet>
<h:commandLink value="#{item.title}" action="#{gameController.searchGames(item.title)}" />
</h:column>
Then, adapt the action method in the backing bean to :
public String searchGames(String tit) {
sgameList = gameEJB.findGamesByTitle(tit);
return "resultsGames.xhtml";
}

<p:dialog> Primefaces Probleme?

I have created a complexe dataTable for my DiplomeBean and it shows Correctly
The deal is whene i select a row from the list ,nothing happend
I want whene i select a row it shows me the elements of the diplome.
My Bean
package com.beans;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.bo.DiplomeBo;
import com.converter.DiplomeDataModel;
import com.model.Collaborateur;
import com.model.Diplome;
public class DiplomeBean {
public Integer idDiplome;
public String ecole;
public String typeEcole;
public String typeDiplome;
public Integer promotion;
private Set<Collaborateur> collaborateurs = new HashSet<Collaborateur>(0);
public Diplome selectedDiplome;
public Diplome getSelectedDiplome() {
return selectedDiplome;
}
public void setSelectedDiplome(Diplome selectedDiplome) {
this.selectedDiplome = selectedDiplome;
}
public Integer getIdDiplome() {
return idDiplome;
}
public void setIdDiplome(Integer idDiplome) {
this.idDiplome = idDiplome;
}
private DiplomeBo diplomeBo;
public String getEcole() {
return ecole;
}
public void setEcole(String ecole) {
this.ecole = ecole;
}
public String getTypeEcole() {
return typeEcole;
}
public void setTypeEcole(String typeEcole) {
this.typeEcole = typeEcole;
}
public Integer getPromotion() {
return promotion;
}
public void setPromotion(Integer promotion) {
this.promotion = promotion;
}
public Set<Collaborateur> getCollaborateurs() {
return collaborateurs;
}
public void setCollaborateurs(Set<Collaborateur> collaborateurs) {
this.collaborateurs = collaborateurs;
}
public void setDiplomeBo(DiplomeBo diplomeBo) {
this.diplomeBo = diplomeBo;
}
public String getTypeDiplome() {
return typeDiplome;
}
public void setTypeDiplome(String typeDiplome) {
this.typeDiplome = typeDiplome;
}
public String AddDiplome(){
Diplome diplome =new Diplome();
diplome.setEcole(getEcole());
diplome.setPromotion(getPromotion());
diplome.setTypeDiplome(getTypeDiplome());
diplome.setTypeEcole(getTypeEcole());
diplomeBo.addDiplome(diplome);
clearForm();
return "Ajout Bien Fait !!";
}
public List<Diplome> getAllDiplome(){
return diplomeBo.findAllDiplome();
}
private void clearForm(){
this.setEcole("");
this.setPromotion(0);
this.setTypeEcole("Choisir type..");
this.setTypeEcole("Choisir type..");
}
}
My Page
<!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:p="http://primefaces.org/ui">
<h:head></h:head>
<body>
<f:view>
<h:outputLink value="Admin/default.xhtml">Go to your app</h:outputLink>
<h:form>
<p:dataTable value="#{diplome.getAllDiplome()}" var="d" paginator="true" rows="10" rowKey="diplome.idDiplome"
selection="#{diplome.selectedDiplome}" selectionMode="single"
onRowSelectUpdate="display" onRowSelectComplete="diplomeDialog.show()">
<f:facet name="header">
Diplome Liste
</f:facet>
<p:column sortBy="#{d.idDiplome}" filterBy="#{d.idDiplome}">
<f:facet name="header">
<h:outputText value="Model" />
</f:facet>
<h:outputText value="#{d.idDiplome}" />
</p:column>
<p:column sortBy="#{d.ecole}" filterBy="#{d.ecole}">
<f:facet name="header">
<h:outputText value="Ecole" />
</f:facet>
<h:outputText value="#{d.ecole}" />
</p:column>
</p:dataTable>
<p:dialog header="Diplome Detail" widgetVar="diplomeDialog" resizable="false"
width="200" showEffect="explode" hideEffect="explode">
<h:outputText value="id:" />
<h:outputText value="#{diplome.selectedDiplome.idDiplome}" />
<h:outputText value="Ecole:" />
<h:outputText value="#{diplome.selectedDiplome.ecole}" />
</p:dialog>
</h:form>
</f:view>
</body>
</html>
Thank's :)
Perhaps try modifying it slightly to be more like the Primefaces showcase example. For example, try something like this:
...
<h:form id="form">
...
<p:dataTable value="#{diplome.getAllDiplome()}" var="d" paginator="true" rows="10"
rowKey="diplome.idDiplome" selection="#{diplome.selectedDiplome}" selectionMode="single">
<p:ajax event="rowSelect" update=":form:display" oncomplete="PF('diplomeDialog').show()" />
...
</p:dataTable>
...
<p:dialog header="Diplome Detail" widgetVar="diplomeDialog" resizable="false"
width="200" showEffect="explode" hideEffect="explode">
<h:panelGrid id="display">
...
</h:panelGrid>
</p:dialog>
</h:form>
...
I can't test this right now, but it seems like it should work since it is essentially the same as the showcase's example.

JSF User Define Table required multiple Data Storage

I am able to print the data from a JSF home page in form of table. But the issue is that it is able to print only one entry at a time.What if I enter more names i.e. name and password without using Database. Please find managed bean and format of table is taken by tutorial.
#SessionScoped
#ManagedBean(name = "pprBean")
public class Demos {
static String firstname ;
static String password;
private static final ArrayList<Demos> employees
= new ArrayList<Demos>(Arrays.asList(
new Demos()
));
public ArrayList<Demos> getEmployees() {
return employees;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
<!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:p="http://primefaces.org/ui">
<f:view>
<h:body>
<h:form>
<h:panelGrid columns="4" cellpadding="5">
<h:outputLabel for="name" value="Name:" style="font-weight:bold"/>
<p:inputText id="name" value="#{pprBean.firstname}" />
<h:outputLabel for="pass" value="Pass:" style="font-weight:bold"/>
<p:inputText id="pass" value="#{pprBean.password}" />
<p:commandButton value="Submit"/>
</h:panelGrid>
<p:outputLabel value="Result"></p:outputLabel>
<h:dataTable value="#{pprBean.employees}" var="result" cellspacing="2"
styleClass="employeeTable"
headerClass="employeeTableHeader"
rowClasses="employeeTableOddRow,employeeTableEvenRow" border="3">
<h:column>
<f:facet name="header">Name</f:facet>
#{result.firstname}
</h:column>
<h:column>
<f:facet name="header">Password</f:facet>
#{result.password}
</h:column>
</h:dataTable>
</h:form>
</h:body>
</f:view>
</html>

JSF - populate values at runtime

Halo
My name is Sergie,I working on my school project using jsf spring and jpa to built the school automation system. i am learning jsf.
I need your help, Three header
City | School | Add/Remove
<c:column>
<f:facet name="header">
<c:outputText value="City" />
</f:facet>
<c:outputText id="ukrCity" value="" " />
</c:column>
<c:column>
<f:facet name="header">
<c:outputText value="School" />
</f:facet>
<c:inputText id="school" value=""
maxlength="12" " />
</c:column>
<c:column>
<f:facet name="header">
<c:outputText value="Add/Remove" />
</f:facet>
<c:selectBooleanCheckbox
id="addremove"
value=""
rendered="" />
</c:column>
City | School | Add/Remove
Київ "textbox" "checkbox"
Харків "textbox" "checkbox"
Cities are populated from City class
public class UkrCity {
private List<A> ukrCities;
public List<A> getUkrCities() {
return ukrCities;
}
public void setUkrCities(final List<A> ukrCities) {
this.ukrCities= ukrCities;
}
private void allCities() {
//add all cities in a list
ukrCities.add("Київ");
ukrCities.add("Харків");
}
}
how to show ukrcities on xhtml page under City and blank textbox and checkbox under school and add/remove tav.
thank you
sorry my bad english.
I have refactored your code. Here is the UkrCity Class.
package com.example;
import java.io.Serializable;
public class UkrCity implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String name;
public UkrCity(String name) {
this.setName(name);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Here is the backing bean
package com.example;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
#ManagedBean
#SessionScoped
public class TableBean implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private ArrayList<UkrCity> cities = new ArrayList<UkrCity>(Arrays.asList(new UkrCity("Київ"),new UkrCity("Харків") ));
public ArrayList<UkrCity> getCities() {
return cities;
}
}
Here is your index.xhtml
<?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:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>UkrCities Table</title>
</h:head>
<h:body>
<h:form>
<h:dataTable value="#{tableBean.cities}" var="city">
<h:column>
<f:facet name="header">City</f:facet>
<h:outputText value="#{city.name}" />
</h:column>
<h:column>
<f:facet name="header">School</f:facet>
<h:inputText value="" />
</h:column>
<h:column>
<f:facet name="header">Add/Remove</f:facet>
<h:selcectBooleanCheckbox value="" onclick="submit()" />
</h:column>
</h:dataTable>
</h:form>
</h:body>
</html>

Resources