Bom dia amigos,
Então, recentemente fiz um curso de javaScript e antes disso ja trabalho com java web… JSF e agora to com duvidas em ‘juntar’ os dois,
vo ilustra com meu codigo pra ficar mais claro
esse é meu formulario com datatable, os valores vem de um arraylist no meu mbean
<!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">
<h:head>
<script type="text/javascript" src="../resoures/scripts/values.js"></script>
</h:head>
<h:body>
<h:form>
<h2>#{mesg.titulodois}</h2>
<h4><h:commandLink style="color: green;" action="retornarMenu" value="#{mesg.retornar}" /></h4>
</h:form>
<h:form id="formulario">
<h:dataTable border="1" value="#{produtoMB.listAll}" var="prod">
<h:column>
<f:facet name="header">
#{mesg.prodCod}
</f:facet>
<h:outputText value="#{prod.cod}" name="codigo" >
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
#{mesg.ProdName}
</f:facet>
<h:outputText value="#{prod.nome}" name="nome">
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
#{mesg.ProdPreco}
</f:facet>
<h:outputText value="#{prod.preco}" name="preco">
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
#{mesg.emEstoque}
</f:facet>
<h:outputText value="#{prod.quantidade}" name="estoque">
</h:outputText>
</h:column>
<h:column>
<h:panelGrid columns="1">
<h:commandButton value="#{mesg.adicionar}" id="botao">
</h:commandButton>
</h:panelGrid>
</h:column>
</h:dataTable>
</h:form>
</h:body>
</html>
JavaScript
window.onload = function (){
var formulario = document.getElementById("formulario");
var cod = formulario.codigo.value;
document.getElementById("botao").onclick = function(){
alert("funciona");
};
function teste(){
alert(cod);
}
};
O objetivo desse script seria apenas pegar o valor do campo codigo e apresentar na tela, só pra teste mesmo, mas
nao consigo acessar nada, nem botao nem nada. Gostaria de algum exemplo ou dica de como acessar um DataTable e tambem se ouver
criticas construtivas para meu codigo pois so iniciante ainda.
Agradeço desde já, abraço