0
Guys I’m having trouble displaying an image within my project in a Data Table. Simply the image is blank. The system makes a query in the mysql database of the image directory to know which image represents the specific team. This is the code to query:
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>
This is my bank,id_time is PK and has another table on the bench called GAME that gets PK as FK:
Do this test and see if the image appears:
– Edjane
What a test Edjane?
– Danilo Silva
Sorry I was editing! Do this test and see if the image appears: <p:graphicImage library="images" name="Pain.png" /> In this example we take the images library that has to be inside Resources and as it is already indicated the library is only necessary to indicate the name of the file. If the names of your folders are correct probably this test will work, hence you check if it is actually being called the correct image address.
– Edjane
It’s calling, just don’t call when I send a value="#{game.time_a.brasao}".
– Danilo Silva
And when you search time_a.brasao is called the correct address?
– Edjane
Yes, the result that came out of the public Arraylist<Game> listTodos() throws Sqlexception{ is this: id=6, dia=2017-01-21, brasao=/Resources/images/Pain.png x brasao=/Resources/images/Pain.png,
– Danilo Silva
See if exchanging value for name works out name="#{game.time_b.brasao}"
– Edjane
Change name and error 500: java.io.Ioexception: java.lang.Stringindexoutofboundsexception: String index out of range: 0
– Danilo Silva
Strange to have given this error, I replicated your problem here and also could not visualize the image, I will try to solve this problem then inform you.
– Edjane
I thank Edjane :) !
– Danilo Silva