I have a problem in showing the last inserted code and showing it in my web application as shown in the image when I press the new button. It shows me another window and where it says code I have to show P007
but it shows me 'P0061'. I leave the code if you can help me thank you very much.
In the Model
private String id test; private String name;
public String getIdprueba() {
return idprueba;
}
public void setIdprueba(String idprueba) {
this.idprueba = idprueba;
}
public String getNombre() {
return nombre;
}
In the DAO
public Try to get LastRegister () throws Exception { ResultSet rs; Test test = null; try {
this.Conectar();
PreparedStatement st=this.getCn().prepareCall("SELECT Max(idprueba) as idprueba FROM pruebas");
rs=st.executeQuery();
if(rs.next()){
prueba=new Prueba();
prueba.setIdprueba(rs.getString("idprueba"));
}
}catch(Exception e){
// this.getCn().rollback();
throw e;
}finally{
this.Cerrar();
}
return prueba;
}
On the Bean
public void numeracionPrueba()throws Exception{
PruebaDao dao=new PruebaDao();;
try{
this.prueba=dao.obtenerUltimoRegistro();
this.idprueba=this.prueba.getIdprueba()+1;
}catch(Exception e){
throw e;
}
}
In XHTML
<f:event type="preRenderView" listener="#{pruebaBean.listar('F')}" />
<p:growl id="msj" autoUpdate="true" />
<h:form id="frm">
<p:commandButton value="Nuevo" oncomplete="PF('wdlgDatos').show();" actionListener="#{pruebaBean.setAccion('Registrar')}" onclick="#{pruebaBean.numeracionPrueba()}" update=":dlgDatos"/>
<p:dataTable id="data" value="#{pruebaBean.lstPrueba}" var="prueba">
<p:column headerText="Codigo">
<p:outputLabel value="#{prueba.idprueba}"/>
</p:column>
<p:column headerText="descripcion">
<p:outputLabel value="#{prueba.nombre}"/>
</p:column>
</p:dataTable>
</h:form>
<p:dialog header="Registro de ......" widgetVar="wdlgDatos" id="dlgDatos">
<h:form>
<p:panelGrid columns="2">
<p:outputLabel value="codigo" />
<p:outputLabel value="#{pruebaBean.idprueba}"/>
<p:outputLabel value="des" />
<p:inputText value="#{pruebaBean.prueba.nombre}"/>
<p:commandButton value="#{pruebaBean.accion}" actionListener="#{pruebaBean.operar()}" oncomplete="PF('wdlgDatos').hide();" update=":frm:data"/>
<p:commandButton value="Cancelar" immediate="true" oncomplete="PF('wdlgDatos').hide();"/>
</p:panelGrid>
</h:form>