• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSTL forEach for my select tag works fine but does not work for tables

 
Ranch Hand
Posts: 675
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi people,
I have a strange problem. I will send out pieces of my projects.

1 - jsp page

[<jsp:useBean id="eletroclass" class="ITC_Systems_WEB_Package_V0.EXM_Eletrocard_S001" />
               <div id="requisitante">
                   <label>Requisitante:</label>
                   <select name="requisitante1">
                       <c:forEach var="prof" items="${requisitante}">
                           <option><c:out value="${prof.nome}"></c:out></option>
                       </c:forEach>
                   </select>
               </div>
               <div id="tabpacientes">
                   <table border="0">
                       <tbody>
                           <thead>
                               <tr>
                                   <th>Data</th>
                                   <th>Hora</th>
                                   <th>Nome</th>
                                   <th>Sexo</th>
                                   <th>Telefone</th>
                               </tr>
                           </thead>
                           <c:forEach var="tabpac" items="${pacientes}">
                           <tr>                                    
                           <td>${tabpac.data}</td>                                          
                           <td>${tabpac.hora}</td>                                          
                           <td>${tabpac.nome}</td>                                          
                           <td>${tabpac.sexo}</td>                                          
                           <td>${tabpac.telefone}</td>                                          
                           </tr>                              
                           </c:forEach>
                           </tbody>
                   </table>]

2 - Servlet

[

                  for select tag work fine

PacientesDAO_W01 pcdao = new PacientesDAO_W01();
           DadosPaciente dpaciente = new DadosPaciente();
           System.out.println("Montando lista dos profissionais..");
           List<DadosPaciente> requisitante = new ArrayList<DadosPaciente>();
           System.out.println("Requisitante: " + requisitante);
           dpaciente = pcdao.getConsultaPaciente(prontuario);
-----------------------------------------------------------------------

               for table tag don't work

try
       {
           PacientesDAO_W01 pcdaoag = new PacientesDAO_W01();
           List<DadosPaciente> pacientes = new ArrayList<DadosPaciente>();
           pacientes = pcdaoag.getPaciente();
           request.setAttribute("pacientes", pacientes);
           System.out.println("Paciente: " + pacientes);
       }catch (Exception ex)
       {
           ex.printStackTrace();
           JOptionPane.showMessageDialog(null, "Erro ao tentar montar tabela.");
       }]

Thanks in advance.

Cezar Apulchro.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean by "does not work"?
What are you seeing on the browser that you don't expect to see?
What is appearing in your logs on the server?
 
Cezar Apulchro
Ranch Hand
Posts: 675
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dave,

in my first forEach for select I get names in DB MySql and I put this names in select tag and appear to choice. All names appear without problems.

But in my second forEach to populate an table, appear only the thead tag, in the td tag nothing appear.

In my logs I don't have any kind of errors.

To check this problem I put System println to see the content returned by my DAO, all data for my table are returned ok, but don't appear in the table.

Thanks and best regards,

Cezar.
 
Cezar Apulchro
Ranch Hand
Posts: 675
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dave,

in my first forEach for select I get names in DB MySql and I put this names in select tag and appear to choice. All names appear without problems.

But in my second forEach to populate an table, appear only the thead tag, in the td tag nothing appear.

In my logs I don't have any kind of errors.

To check this problem I put System println to see the content returned by my DAO, all data for my table are returned ok, but don't appear in the table.

Thanks and best regards,

Cezar.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so this bit of code:

is running, because you see the output from that println in your logs?

So it must be something after this point.

Can you post the <div id="tabpacientes"> section from your browser?
Just to see exactly what has been produced.
 
Cezar Apulchro
Ranch Hand
Posts: 675
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I don't know how I send for you this section of my browser, can you help me?
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you right click on most browsers one of the options is "show source".
Then you can find the relevant bit to copy.

That, and F12 (for most browsers) for the Developer Tools, is something you need to know (F12 is more important) if you;re going to develop web apps.
 
Cezar Apulchro
Ranch Hand
Posts: 675
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you,
this is the section of browser, I can't understand how the tbody tag appear closing my table.
[<div id="tabpacientes">
                   <table border="0">
                       <tbody>
                           </tbody><thead>
                               <tr>
                                   <th>Data</th>
                                   <th>Hora</th>
                                   <th>Nome</th>
                                   <th>Sexo</th>
                                   <th>Telefone</th>
                               </tr>
                           </thead>
                           
                           
                   </table>
               </div>]
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, the JSP code you posted above has this:

And what is output is:

Note the <tbody></tbody> and the lack of a <tbody> after the thead in the browser output.
Compare that to the JSP.
That output cannot be from that JSP code.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indeed, that table is incorrect in both cases.
Only the <tr> elements should be inside the <tbody>.

Indeed, I suspect that's your issue.

Edit to clarify:

That's the structure the table should have.
 
Cezar Apulchro
Ranch Hand
Posts: 675
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have deleted tbody tags but the problem still the same.
 
Cezar Apulchro
Ranch Hand
Posts: 675
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed to:
"<div id="tabpacientes">
                   <table border="0">                        
                       <thead>
                           <tr>
                               <th>Data</th>
                               <th>Hora</th>
                               <th>Nome</th>
                               <th>Sexo</th>
                               <th>Telefone</th>
                           </tr>
                       </thead>
                       <tbody>
                           <c:forEach var="tabpac" items="${pacientes}">
                           <tr>                                    
                               <td>${tabpac.data}</td>                                          
                               <td>${tabpac.hora}</td>                                          
                               <td>${tabpac.nome}</td>                                          
                               <td>${tabpac.sexo}</td>                                          
                               <td>${tabpac.telefone}</td>                                          
                           </tr>                              
                           </c:forEach>
                       </tbody>
                   </table>"
 
Cezar Apulchro
Ranch Hand
Posts: 675
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry,

The section in browse still whith the same problem, my td tag don't appear...
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cezar Apulchro wrote:
The section in browse still whith the same problem, my td tag don't appear...


Don't tell us, show us. What is the source sent to the browser for the table?
 
Cezar Apulchro
Ranch Hand
Posts: 675
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good news everyone, problem is solved.

The solution was, I have deleted the table and I created an new table using the icon "HTML" of the jsp pallette in NetBeans.

Thanks to all.

Cezar.
 
Cezar Apulchro
Ranch Hand
Posts: 675
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I was wrong, the problem remains the same.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK.
So show us the HTML that is produced on the browser, and the JSP code for the table.
 
Rancher
Posts: 517
15
Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you try this and tell what is the output:

 
Cezar Apulchro
Ranch Hand
Posts: 675
3
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi people,
now is real, problem is solved. My problem was not in my jsp table but in my BEAN class, after make change in my bean the table work fine.

Thanks a lot.
Once again, sorry.

Cezar.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reporting back! 🐻
 
reply
    Bookmark Topic Watch Topic
  • New Topic