My problem would be the following: I have a jqgrid to which I give a rowNum 10 when I create it. The problem arises if I change the rowNum to 20 and give it to save I always get the value to 10 when the page is reloaded and I would be interested to go to 20 (I say 20 as any other number).
My jqgrid code is as follows:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
<%@ include file="/WEB-INF/jsp/comun/directivas.jsp"%>
<script type="text/javascript">
var _editable = false;
<app:orzamentoAbierto estadoPresupuesto="${reglaFormBean.presupuesto.estado}">
<sec:accesscontrollist hasPermission="orz_modificar_regra" domainObject="">
_editable = '${reglaFormBean.esUltimaVersion}' === 'true';
</sec:accesscontrollist>
</app:orzamentoAbierto>
jQuery(function() {
var lastsel2;
jQuery("#grid").jqGrid({
url: "${pageContext.request.contextPath}/estruturasComuns/regras/detalleRegra/ingresos/grid?" + $('#formEdicionDetalleReglaValidacion').serialize(),
loadonce:false,
mtype: 'GET',
datatype: "json",
search: "${buscadorDetallesReglaValidacionForm.hacerBusqueda}",
<%-- indica el formato de la estructura en el que se recuperan los datos--%>
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false
},
<%-- tamaño--%>
height: 230,
width: 1075,
scrollOffset: 0,
colNames:[
'id'
, '<******:mensaje code="etiqueta.economicaIngresos"/>'
, '<******:mensaje code="etiqueta.detalleReglaValidacion.importeMinimoPresupuestado.abr"/>'
, '<******:mensaje code="etiqueta.detalleReglaValidacion.importeMaximoPresupuestado.abr"/>'
, '<******:mensaje code="etiqueta.detalleReglaValidacion.importeCapturado.abr"/>'
, ''
],
colModel:[
{name:'id', index:'id', hidden:true}
, {name:'mascaraEconomicaIngresos', index:'mascaraEconomicaIngresos', editable:true, hidden:false, resizable:false, align: 'left', width: 150, classes: 'monospace-font'}
, {name:'importeMinimoPresupuestado', index:'importeMinimoPresupuestado',
editable:true, editoptions:{ dataInit: function (elem){
$(elem).attr("class","numerico importeSinDecimales");
$(elem).addClass("mono-font");
}
},hidden:false, resizable:false, formatter:'number', formatoptions:{decimalPlaces: 0,defaultValue: '<div style="text-align:center"></div>'}, align: 'right', width: 45}
, {name:'importeMaximoPresupuestado', index:'importeMaximoPresupuestado',
editable:true, editoptions:{ dataInit: function (elem){
$(elem).attr("class","numerico importeSinDecimales");
$(elem).addClass("mono-font");
}
}, hidden:false, resizable:false, formatter:'number', formatoptions:{decimalPlaces: 0,defaultValue: '<div style="text-align:center"></div>'}, align: 'right', width: 45}
, {name:'importeCapturado', index:'importeCapturado', editable:false, hidden:false, resizable:false, formatter:'number', formatoptions:{decimalPlaces: 0,defaultValue: '<div style="text-align:center"></div>'}, align: 'right', width: 45}
, {name:'detalle', index:'detalle', editable:false, edittype: 'button', formatter: displayDetalleButton, hidden:false, resizable:false, fixed:true, search:false, sortable: false, width:30, align: 'center'}
],
<%-- desplegable que indica el numero de registros --%>
rowNum:20,
rowList:[10,20,30],
pager: '#pager',
onPaging : function(pgButton) {
var temp1= $('#grid').closest('.ui-jqgrid').find('.ui-pg-selbox').val();
alert ("temp1 " + temp1);
ajustarTamanhoJqgrid(pgButton, "#grid").trigger('reloadGrid');
},
viewrecords: true,
rownumbers: true,
loadError : function(xhr,st,err) {
if (xhr.responseText != '') {
var respuesta = JSON.parse(xhr.responseText);
jQuery("#rsperror").html(respuesta.mensajeError);
}
else {
jQuery("#rsperror").html("Error: "+st+"; "+ xhr.status + " "+xhr.statusText);
}
},
loadComplete: function(){
$.ajax({
url : global_contextPath + "estruturasComuns/regras/${reglaFormBean.id}/importesCapturados",
type : 'GET',
cache: false
}).success(function(importes){
if(importes){
$.each(importes, function(id, importe) {
jQuery("#grid").jqGrid('setCell', parseInt(id), 'importeCapturado', importe);
// now change the internal local data
jQuery("#grid").jqGrid('getLocalRow', parseInt(id)).importeCapturado = importe;
});
} else {
var rows = $('#grid').jqGrid('getRowData');
$.each(rows, function(id, row) {
jQuery("#grid").jqGrid('setCell', row.id, 'importeCapturado', '<div/>');
});
}
});
},
editurl: "ingresos/grid"
});
jQuery("#grid").jqGrid('setLabel', 'mascaraEconomicaIngresos', '<******:mensaje code="etiqueta.economicaIngresos"/>', {'text-align':'left'},{'title':''});
jQuery("#grid").jqGrid('setLabel', 'importeMinimoPresupuestado', '<******:mensaje code="etiqueta.detalleReglaValidacion.importeMinimoPresupuestado.abr"/>', {'text-align':'right'},{'title':''});
jQuery("#grid").jqGrid('setLabel', 'importeMaximoPresupuestado', '<******:mensaje code="etiqueta.detalleReglaValidacion.importeMaximoPresupuestado.abr"/>', {'text-align':'right'},{'title':''});
jQuery("#grid").jqGrid('setLabel', 'importeCapturado', '<******:mensaje code="etiqueta.detalleReglaValidacion.importeCapturado.abr"/>', {'text-align':'right'},{'title':''});
if (_editable) {
jQuery("#grid")
.navGrid('#pager',{ edit: false, add: false, del: true, search: true, refresh: true },
{},{},{
afterComplete: function(data){
if(data.responseText && $('#idRegla').val() !== data.responseText){
window.location.replace("${pageContext.request.contextPath}/estruturasComuns/regras/detalleRegra/" + data.responseText) + '?oper=nuevaVigencia';
}
}
})
.navButtonAdd('#pager',{
caption:'<spring:message code="boton.nuevo" />',
buttonicon:"ui-icon-plus",
onClickButton: function(){
abrirDialogDetalleRegla();
},
position:"last"
});
} else {
jQuery("#grid").navGrid('#pager',{ edit: false, add: false, del: false, search: true, refresh: true });
}
$("#next_pager").attr('title','<******:mensaje code="jqgrid.next_pager.descripcion"/>');
$("#last_pager").attr('title','<******:mensaje code="jqgrid.last_pager.descripcion"/>');
$("#prev_pager").attr('title','<******:mensaje code="jqgrid.prev_pager.descripcion"/>');
$("#first_pager").attr('title','<******:mensaje code="jqgrid.first_page.descripcion"/>');
$("#last_pager").next().find("select").attr('title','<******:mensaje code="jqgrid.rowList.descripcion"/>');
});
function abrirDialogDetalleRegla(rowid){
if (_editable) {
$( "#detalleReglaForm" ).dialog({
width: 900,
title: '<******:mensaje code="titulo.detalleReglaValidacion.detalle" />',
resizable : false,
modal: true,
buttons: [{
text: '<******:mensaje code="boton.cerrar" />',
click: cerrarDialogDetalleRegla
},
{
text: '<******:mensaje code="boton.actualizar" />',
click: submitDetalleRegla
}],
open : function() {
//Oculta el boton de cerrar (X) de la ventana de dialogo
$(this).parent().find(".ui-dialog-titlebar-close").hide();
$(this).parent().find(".ui-dialog-buttonpane .ui-button:eq(0)").addClass("botonIzquierdaDialog");
$(this).parent().find(".ui-dialog-buttonpane .ui-button:eq(1)").addClass("botonDerechaDialog");
}
});
initDialogDetalleRegla(rowid);
}
}
function cerrarDialogDetalleRegla(){
$('#detalleReglaForm').trigger('reset');
cerrarDialogo($('#detalleReglaForm'));
}
function reload(rowid, result) {
$("#grid").trigger("reloadGrid");
}
function successFunction() {
vaciarErrores();
jQuery("#rspexito").html('<******:mensaje code="aplicacion.mensaje.aviso.guardadoCorrecto" />');
return true;
}
function displayDetalleButton(cellvalue, options, rowObject) {
var html = '<span class="botonEditar" onclick="abrirDialogDetalleRegla(' + options.rowId +')"></span>';
return html;
}
function submitDetalleRegla(){
var formCrearDetalleRegla = $('#detalleReglaForm');
var dataForm = formCrearDetalleRegla.serialize();
var urlPeticion = formCrearDetalleRegla.attr('action');
$.ajax({
type: "POST",
cache: false,
url: "${pageContext.request.contextPath}/" + urlPeticion,
data: dataForm,
success: function(data, textStatus, jqXHR ){
if (data.hasOwnProperty("errores")) {
var html = '';
$.each(JSON.parse(data.errores), function(k, v) {
html += '<span class="error">'+ v +'</span><br/>';
});
alertDialog('Erro', html);
} else if (data.hasOwnProperty("idRegla")) {
if(data.idRegla && $('#idRegla').val() !== data.idRegla){
window.location.replace("${pageContext.request.contextPath}/estruturasComuns/regras/detalleRegra/" + data.idRegla + '?accion=nuevaVigencia');
}
}
cerrarDialogDetalleRegla();
//resetForm('#detalleReglaForm');
reloadGrid("#grid");
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
renderizaErrores('#detalleReglaForm', XMLHttpRequest.responseText);
}
});
}
</script>
<%-- insertar grid en pagina --%>
<div id="jqgrid">
<span id="rsperror" style="color: red"></span>
<table id="grid"></table>
<div id="pager"></div>
</div>
<%-- dialog oculto para creacion/edicion de detalles de regla --%>
<form:form id="detalleReglaForm" action="estruturasComuns/regras/detalleRegra/ingresos/grid" modelAttribute="detalleReglaForm" style="display:none">
<jsp:include page="./formDetalleDetalleReglaIngreso.jsp"/>
</form:form>
The code that receives the request in the Controller would be:
@RequestMapping(value = "/detalleRegra/{id}", params = "accion=actualizar", method = RequestMethod.POST)
public ModelAndView formDetalleActualizar(
@Valid @ModelAttribute("reglaFormBean") final ReglaFormBean reglaFormBean, final BindingResult result,
final RedirectAttributes redirectAttributes, final Locale locale)
throws DemasiadosRegistrosRecuperadosException {
LOGGER.debug("Acción de actualizar detalleRegla");
if (result.hasErrors()) {
return crearVistaDetalleRegla(reglaFormBean, reglaFormBean.getPresupuesto(), locale);
}
final Regla reglaBD = reglaService.getRegla(reglaFormBean.getId());
setCamposActualizablesFromBean(reglaBD, reglaFormBean);
final RespuestaNegocio<Regla> respuestaNegocio = reglaService.updateRegla(reglaBD);
if (respuestaNegocio.huboErrores()) {
BindingResultUtil.addAllBusinessErrorsToResult(result, respuestaNegocio.getErrores());
return crearVistaDetalleRegla(reglaFormBean, reglaFormBean.getPresupuesto(), locale);
}
final ModelAndView mav = new ModelAndView();
mav.setViewName("redirect:/estruturasComuns/regras/detalleRegra/"
+ respuestaNegocio.getObjetoRespuesta().getId());
return mav;
}
The part of the Controller in which the View is generated would be:
private ModelAndView crearVistaDetalleRegla(final ReglaFormBean reglaFormBean,
final Presupuesto presupuesto,
final Locale locale) {
final ModelAndView mav = new ModelAndView();
mav.addObject("valoresComboTipoRegla", getTipoReglaValuesOrdenados(locale));
mav.addObject("valoresComboTipoEnviable", Arrays.asList(TipoEnviable.values()));
mav.addObject("valoresComboTipoPresupuesto", Arrays.asList(TipoPresupuesto.values()));
mav.addObject("reglaFormBean", reglaFormBean);
mav.addObject("valoresComboTipoTerritorializacion", Arrays.asList(TipoTerritorializacion.values()));
if (reglaFormBean.getTipoRegla().equals(TipoRegla.GASTOS_IMPORTE_DEFINITIVO)
|| reglaFormBean.getTipoRegla().equals(TipoRegla.GASTOS_IMPORTE_PROPUESTA)) {
mav.addObject("valoresComboEnviable", dropdownPresupuestoProvider.obtenerComboEnviables(presupuesto));
mav.addObject("valoresComboMascaraTipoFondo", obtenerJqGridComboTipoFondo(locale));
mav.setViewName("presupuesto.detallesReglaValidacion.listadoDetalle");
mav.addObject("detalleReglaForm", new DetalleReglaGastosForm());
} else if (reglaFormBean.getTipoRegla().equals(TipoRegla.GASTOS_TERRIT)) {
mav.addObject("valoresComboMascaraTipoFondo", obtenerJqGridComboTipoFondo(locale));
mav.setViewName("presupuesto.detallesReglaTerritorial.listadoDetalle");
mav.addObject("detalleReglaForm", new DetalleReglaGastosForm());
} else if (reglaFormBean.getTipoRegla().equals(TipoRegla.INGRESOS_DEFINITIVO)
|| reglaFormBean.getTipoRegla().equals(TipoRegla.INGRESOS_PROPUESTA)) {
mav.addObject("valoresComboEnviable", dropdownPresupuestoProvider.obtenerComboEnviables(presupuesto));
mav.setViewName("presupuesto.detallesReglaIngreso.listadoDetalle");
mav.addObject("detalleReglaForm", new DetalleReglaIngresosForm());
}
return mav;
}
What I had in mind is: When creating the view, pass as the parameter the initial rowNum to 10. That when changing it in the jsp, this value is saved. I managed to capture it in the "onPaging", that value passed to the Controller when I click on update (Here is where I'm more lost) and that somehow in formDetailleUpdate instead of reedirecting I go to the method CreateDetailStandardView and change the value to the rowNum of said method so that when you create the view, create it with that value at 20.
This is the idea that came to my mind, but if there is some simpler way, suggestions are appreciated that it is always good to see other approaches, apart from the fact that I am starting and I do not have much knowledge.
Thank you very much in advance.