Personally I'm having trouble displaying an image within my project on a Data Table. Simply the image goes blank. The system makes a query in the mySQL database of the image directory to know which image represents the specific team. Here is the code to see:
public ArrayList<Jogo> listarTodosBrasao() throws SQLException{
StringBuilder sql = new StringBuilder();
sql.append("SELECT j.id_jogo, j.dia, t_a.brasao, t_b.brasao FROM bolaodovibao.jogo j ");
sql.append("INNER JOIN bolaodovibao.time t_a ");
sql.append("ON t_a.id_time=j.time_a ");
sql.append("INNER JOIN bolaodovibao.time t_b ");
sql.append("ON t_b.id_time=j.time_b ORDER BY j.dia ASC ");
Connection conexao = ConexaoFactory.conectar();
PreparedStatement comando = conexao.prepareStatement(sql.toString());
ResultSet resultado = comando.executeQuery();
ArrayList<Jogo> lista = new ArrayList<Jogo>();
while (resultado.next()) {
Time time_a = new Time();
time_a.setNome_time(resultado.getString("t_a.brasao"));
Time time_b = new Time();
time_b.setNome_time(resultado.getString("t_b.brasao"));
Jogo jogo = new Jogo();
jogo.setId_jogo(resultado.getInt("j.id_jogo"));
jogo.setDia(resultado.getString("j.dia"));
jogo.setTime_a(time_a);
jogo.setTime_b(time_b);
lista.add(jogo);
}
return lista;
}
This is my xhtml:
<p:dataTable emptyMessage="Nenhum registro encontrado." value="#{JogoMB.jogos}"
var="jogo" paginator="true" paginatorPosition="bottom" rows="4" >
<p:column headerText="Dia da Partida">
<h:outputText value="#{jogo.dia}" ></h:outputText>
</p:column>
<p:column headerText="Time A" >
<p:graphicImage style="width: 80px; height: 80px;" value="#{jogo.time_a.brasao}" stream="false" />
</p:column>
<p:column headerText="Time B" >
<p:graphicImage style="width: 80px; height: 80px;" value="#{jogo.time_b.brasao}" stream="false" />
</p:column>
<p:column headerText="Apostar" >
<p:commandButton type="button" value="Apostar" />
</p:column>
</p:dataTable>
My bank, id_time is PK and has another table in the bank called GAME that receives PK as FK:
Resultonscreen: