I have two struts2 jQuery grids in my page. I have to load the 2nd grid on row click of the first grid. I have added a rowselect
event listener to the first grid and in that method I am trying to reload the grid.
$("#dgJobsDetailMain").jqGrid().trigger("reloadGrid");
I also tried firing an Ajax request
function populateJobRunDetails(jobName,dbSid)
{
$.ajax({
url: "ecmComparisonJobDetailDataAction?jobId="+jobName+"&selectedDbSid="+selectedDbSid+"&date="+new Date().getTime()+"&rowClicked=true",
type: "GET",
dataType: "json",
success: function(data,textStatus,jqXHR)
{
//$("#dgJobsDetailMain").jqGrid().trigger("reloadGrid");
},
error:function(jqXHR, textStatus, errorThrown)
{
alert('error');
}
});
}
My problem is
- Action's execute method gets several times for every action. When I ran the application on debug mode, i found that the action classes execute method got called three times. of which, the selected values from the jsp pages were bound to the action classes variable twice and the third time, the values were null.
- And when I fire the reload grid event on
success
of the ajax function, the action class params are set to null, so I am unable to proceed with the data fetch.
1st grid
<sjg:grid viewrecords="true" formIds="ecmComparisonMainForm" reloadTopics="reloadDataGrid" pagerPosition="center" onSelectRowTopics="rowselect" id="dgJobsMain" caption="Job List" dataType="json" href="%{ecmComparisonDataActionUrl}" pager="true"
gridModel="gridModel" rowList="4,6,8" rowNum="5" rownumbers="true" height="150" width="1200">
<sjg:gridColumn name="jobId" index="jobId" title="Job ID" hidden="true" />
<sjg:gridColumn name="jobName" index="jobName" title="Job" sortable="true" />
<sjg:gridColumn name="jobDescription" index="jobDescription" title="Job Description" sortable="true"/>
<sjg:gridColumn name="database" index="database" title="Database" sortable="false" />
<sjg:gridColumn name="sourceSchema" index="sourceSchema" title="Source Schema" sortable="false"/>
<sjg:gridColumn name="targetSchema" index="targetSchema" title="Target Schema" sortable="true"/>
<sjg:gridColumn name="prDescription" index="prDescription" title="PR Description" hidden="true" sortable="false"/>
<sjg:gridColumn name="createdDate" index="createdDate" title="Created Date" sortable="false"/>
<sjg:gridColumn name="createdBy" index="createdBy" title="Created By" sortable="false"/>
</sjg:grid>
Row select function
$.subscribe('rowselect', function(event, data)
{
rowClicked = true;
var grid = event.originalEvent.grid;
var sel_id = grid.jqGrid('getGridParam', 'selrow');
var jobName = grid.jqGrid('getCell', sel_id, 'jobName');
var dbSid = document.getElementById('schemaDbSid');
$("#dgJobsDetailMain").jqGrid().trigger("reloadGrid");
//populateJobRunDetails(jobName,dbSid.value);
}
);
2nd Grid
<sjg:grid pagerPosition="center" id="dgJobsDetailMain" caption="Job Details List" dataType="json" href="%{ecmJobRunDetailsActionUrl}" pager="true"
gridModel="jobsDetailGridModel" rowList="4,6,8" rowNum="5" rownumbers="true" height="150" width="1200">
<sjg:gridColumn name="runId" index="runId" title="Run" sortable="true" />
<sjg:gridColumn name="startDate" index="startDate" title="Start Time" sortable="true"/>
<sjg:gridColumn name="endDate" index="endDate" title="End Time" sortable="false" />
<sjg:gridColumn name="status" index="status" title="Run Status" sortable="false"/>
<sjg:gridColumn name="statusMsg" index="statusMsg" title="Status Details" sortable="true"/>
</sjg:grid>
Action class:
//Form variables/getter setters
public String execute()
{
// code to database
}
public String getJSON()
{
return execute();
}
Please let me know what is missing.