0

I´m coding a shopping cart simple aplication using JSF and JPA (mysql). I have a xhtml page and in the upper it shows a table of books.I´ve used a simple with a "Buy link"(commandlink) in the last column.When I click this link, it must draw another table in the bottom of the page with ajax(the shopping cart).

xhtml

<f:view>
        <h:form id="formulario">
            <center><h1>Libros del tema: <h:outputText value="#{temasBean.tema}"/></h1></center>
            <table align="center" border="1">
                <tr>
                    <td>Título</td><td>Autor</td><td>Precio</td>
                </tr>
                <c:forEach  id="libros" var="libros" items="#{temasBean.librosList}">
                    <tr>
                        <td><h:outputText value="${libros.titulo}"/></td>
                        <td><h:outputText value="${libros.autor}"/></td>
                        <td><h:outputText value="${libros.precio}"/></td>
                        <td><h:commandLink  action="#{ventasBean.doComprar()}">
                                Comprar
                                <f:param id="isbn"  name="isbn" value="${libros.isbn}"/>
                                <f:ajax  execute="#{ventasBean.recuperaCarrito()}" render="carro"/>


                            </h:commandLink></td>
                    </tr>
                </c:forEach>
            </table>
            <center><a href="buscar.xhtml">Volver</a></center>
            <center><h1>Carrito</h1></center>
            <table  id="carro" align="center" border="1">
                <tr>
                    <td>Título</td><td>Precio</td>
                </tr>

                <c:forEach id="items" var="item" items="#{ventasBean.recuperaCarrito()}">
                    <tr>
                        <td><h:outputText id="titulo" value="${item.libro.titulo}"/></td>
                        <td><h:outputText id="precio" value="${item.libro.precio}"/></td>
                        <td><h:commandLink  action="#{ventasBean.doEliminarArticulo()}">
                                Eliminar
                                <f:param id="isbn2"  name="isbn" value="${item.libro.isbn}"/>
                                <f:ajax render="carro"/>
                            </h:commandLink></td>
                    </tr>
                </c:forEach>


            </table>
                    <center><h:commandLink action="#{ventasBean.doEfectuarCompra()}">Ejecutar compra</h:commandLink></center>
        </h:form>
    </f:view>
Pedro
  • 115
  • 11
  • By the way, `
    ` is deprecated since HTML 4.0 which was released 1998. Are you sure you're using [up to date resources](http://htmldog.com/guides/html/beginner/) while learning HTML?
    – BalusC Sep 16 '15 at 10:07
  • I´ve searched and tried lots of answers and none worked for me – Pedro Sep 16 '15 at 10:30
  • Is there any reason why you are not using `h:dataTable` or `ui:repeat` JSF components to show your tabular data? – Javier Haro Sep 16 '15 at 10:37
  • There is no reason.Do you think I should use h:dataTable? – Pedro Sep 16 '15 at 10:51
  • You've another problem with ``. It isn't being used as shown in a normal JSF book/tutorial. But that's a different problem. – BalusC Sep 16 '15 at 11:16
  • Just open Google Search site and search by `jsf+2+datatable+simple+example`, choose one of the results and try to implement it on your computer. – Javier Haro Sep 16 '15 at 12:14

0 Answers0