if ((sectionName == null) || sectionName.equals("")) {
throw new GenericEntityException("Screen section name is required.");
}
UIWebScreenSection uiWebScreenSection = getUiWebScreenSection(userInfo,
screenName, sectionName, delegator, uiCache);
if (TIMER) {
timer.timerString(
"[GenericWebEventProcessor.processEvents] Got web screen section");
}
// Get the additional parameters that are needed for this screen section. These will be used
// for filtering a related entity on a tab page, or in completing keys in a SELECT screen.
evalUseQueryParameterList(uiWebScreenSection, request);
if (TIMER) {
timer.timerString(
"[GenericWebEventProcessor.processEvents] Evaluated \"use\" query parameter list");
}
Debug.logVerbose("Returned from evalUseQueryParameterList.", module);
// Find out what needs to be done depending on the action passed in the request object.
String action = "";
if (request.getParameter("action") != null) {
// Actions for Free Form sections:
// ACTION_SHOW - Display the entity in non-edit mode
// ACTION_SHOW_UPDATE - Display the entity so the user can edit it
// ACTION_SHOW_INSERT - Show the form with empty cells so the user can enter a new entity
// ACTION_SHOW_QUERY - Show the form in Query mode, and set next action to QUERY.
// ACTION_SHOW_QUERY_REPORT - Show the form in Query mode, and set next action to SHOW_REPORT.
// ACTION_SHOW_REPORT - Show the form in Report mode, and set next action to SHOW_REPORT.
// ACTION_SHOW_SELECT - Show the form in select mode, and set next action to UPDATE_SELECT.
// ACTION_SHOW_COPY - Show the form with a copy of the specified entity from which a new
// entity will be created. (Same as showCreate with values prefilled.)
// ACTION_UPDATE - Save the entity into the database using the form values.
// ACTION_INSERT - Insert a new entity into into the database using the form values
// ACTION_DELETE - Delete the entity from the database.
// ACTION_BUTTON - A button in the header was pushed to get here. Look for a parameter with
// each possible button name until we know which button was pushed.
// Actions for Tabular sections:
// ACTION_QUERY - Search for values based on attibute values using a custom WHERE clause.
// ACTION_QUERY_UPDATE - Search for values based on attibute values using a custom WHERE clause,
// and go into update mode.
// ACTION_QUERY_ALL - Search for all values.
// ACTION_UPDATE - Save the entit(ies) into the database using the form values.
// ACTION_UPDATE_SELECT - Add and remove entities in a many-to-many relationship table.
action = request.getParameter("action");
} else {
// No action specified.
action = uiWebScreenSection.ACTION_NONE;
}
if (!action.equals(uiWebScreenSection.ACTION_BUTTON) &&
!action.equals(uiWebScreenSection.ACTION_COPY) &&
!action.equals(uiWebScreenSection.ACTION_DELETE) &&
!action.equals(uiWebScreenSection.ACTION_INSERT) &&
!action.equals(uiWebScreenSection.ACTION_NONE) &&
!action.equals(uiWebScreenSection.ACTION_QUERY) &&
!action.equals(uiWebScreenSection.ACTION_QUERY_UPDATE) &&
!action.equals(uiWebScreenSection.ACTION_QUERY_ALL) &&
!action.equals(uiWebScreenSection.ACTION_UPDATE) &&
!action.equals(uiWebScreenSection.ACTION_UPDATE_SELECT) &&
!action.equals(uiWebScreenSection.ACTION_SHOW) &&
!action.equals(uiWebScreenSection.ACTION_SHOW_COPY) &&
!action.equals(uiWebScreenSection.ACTION_SHOW_INSERT) &&
!action.equals(uiWebScreenSection.ACTION_SHOW_QUERY) &&
!action.equals(uiWebScreenSection.ACTION_SHOW_QUERY_REPORT) &&
!action.equals(uiWebScreenSection.ACTION_SHOW_REPORT) &&
!action.equals(uiWebScreenSection.ACTION_SHOW_SELECT) &&
!action.equals(uiWebScreenSection.ACTION_SHOW_UPDATE)) {
Debug.logWarning("\"" + action + "\" is not a valid action.", module);
throw new GenericEntityException(
"[GenericWebEventProcessor.processEvents] \"" + action +
"\" is not a valid action.");
}
Debug.logVerbose("Starting action is \"" + action + "\".", module);
Debug.logVerbose(
"About to convert button action to regular action if necessary.", module);
action = UIWebUtility.convertButtonAction(action, request);
Debug.logVerbose("Final action is \"" + action + "\".", module);
if (TIMER) {
timer.timerString(
"[GenericWebEventProcessor.processEvents] Determined action");
}
String queryId = "";
if (request.getParameter("queryId") != null) {
queryId = request.getParameter("queryId");
} else if (request.getParameter("savedQueryName") != null) {
// The calling link specified to use a named query if it exists.
String savedQueryName = request.getParameter("savedQueryName");
GenericValue queryGV = UIQuery.getUiQueryByName(delegator,
userInfo.getPartyId(), sectionName, screenName,
savedQueryName);
if (queryGV == null) {
// Named query was not found. Don't use a query.
queryId = "1"; // Query = All
Debug.logWarning("Named query not found for query name " +
savedQueryName + ", partyId " + userInfo.getPartyId() +
", sectionName " + sectionName + ", and screenName " +
screenName + ". queryId is now \"" + queryId + "\"", module);
} else {
// Named query was found.
queryId = (queryGV.getString("queryId") == null) ? "NONE"
: queryGV.getString(
"queryId");
Debug.logVerbose("Named query was found. queryId is \"" +
queryId + "\"", module);
}
}
DataMatrix dataMatrix = new DataMatrix(delegator,
uiWebScreenSection.getEntityParamVector());
if (TIMER) {
timer.timerString(
"[GenericWebEventProcessor.processEvents] Constructed data matrix");
}
// ---------------------------------------------------------------------------------
// Process all events before generating the HTML to display the data on the screen.
// ---------------------------------------------------------------------------------
// --------
// INSERT
// --------
if (action.equals(uiWebScreenSection.ACTION_INSERT)) {
// Insert the new record(s) into the database.
int status = this.processInsert(userInfo, uiWebScreenSection,
request, response, delegator, eventProcessor, dataMatrix,
uiCache);
if (TIMER) {
timer.timerString(
"[GenericWebEventProcessor.processEvents] Finished insert");
}
switch (status) {
case STATUS_ERROR:
return "An error occurred while inserting the new information into the data base.";
case STATUS_CANCEL:
return "Insert canceled.";
}
// --------
// UPDATE
// --------
} else if (action.equals(uiWebScreenSection.ACTION_UPDATE)) {
// Update the existing record(s) in the database.
int status = this.processUpdate(userInfo, uiWebScreenSection,
request, response, delegator, eventProcessor, dataMatrix,
uiCache);
if (TIMER) {
timer.timerString(
"[GenericWebEventProcessor.processEvents] Finished update");
}
switch (status) {
case STATUS_ERROR:
return "An error occurred while updating the information in the data base.";
case STATUS_CANCEL:
return "Update canceled.";
}
// --------
// UPDATE_SELECT
// --------
} else if (action.equals(uiWebScreenSection.ACTION_UPDATE_SELECT)) {
// Add and/or remove records in a many-to-many table.
int status = this.processUpdateSelect(userInfo, uiWebScreenSection,
request, response, delegator, eventProcessor);
if (TIMER) {
timer.timerString(
"[GenericWebEventProcessor.processEventsSelect] Finished update");
}
switch (status) {
case STATUS_ERROR:
return "An error occurred while updating the information in the data base.";
case STATUS_CANCEL:
return "Update canceled.";
}
// --------
// DELETE
// --------
} else if (action.equals(uiWebScreenSection.ACTION_DELETE)) {
// Delete the current record.
int status = this.processDelete(userInfo, uiWebScreenSection,
request, response, delegator, eventProcessor, uiCache);
switch (status) {
case STATUS_ERROR:
return "An error occurred while deleting the information.";
case STATUS_CANCEL:
return "Delete canceled.";
}
// Create an empty entity so the user can insert a new one.
status = this.processCreate(userInfo, uiWebScreenSection, request,
response, delegator, eventProcessor, dataMatrix);
switch (status) {
case STATUS_ERROR:
return "An error occurred while creating an empty data form.";
case STATUS_CANCEL:
return "Create canceled.";
}
if (TIMER) {
timer.timerString(
"[GenericWebEventProcessor.processEvents] Finished delete");
}
// --------
// SHOW_INSERT
// --------
} else if (action.equals(uiWebScreenSection.ACTION_SHOW_INSERT)) {
// Create an empty entity so the user can insert a new one.
int status = this.processCreate(userInfo, uiWebScreenSection,
request, response, delegator, eventProcessor, dataMatrix);
switch (status) {
case STATUS_ERROR:
return "An error occurred while creating an empty data form.";
case STATUS_CANCEL:
return "Create canceled.";
}
if (TIMER) {
timer.timerString(
"[GenericWebEventProcessor.processEvents] Finished show_insert");
}
// --------
// SHOW_QUERY or SHOW_QUERY_REPORT
// --------
} else if (action.equals(uiWebScreenSection.ACTION_SHOW_QUERY) ||
action.equals(uiWebScreenSection.ACTION_SHOW_QUERY_REPORT)) {
// Create an empty entity to be displayed for query mode.
int status = this.processShowQuery(userInfo, uiWebScreenSection,
request, response, delegator, eventProcessor, dataMatrix);
switch (status) {
case STATUS_ERROR:
return "An error occurred while creating an empty query form.";
case STATUS_CANCEL:
return "Create canceled.";
}
if (TIMER) {
timer.timerString(
"[GenericWebEventProcessor.processEvents] Finished show_query");
}
// --------
// SHOW_REPORT
// --------
} else if (action.equals(uiWebScreenSection.ACTION_SHOW_REPORT)) {
// Load in the entered query criteria, and re-display them in query mode.
int status = this.processShowReport(userInfo, uiWebScreenSection,
request, response, delegator, eventProcessor, dataMatrix);
switch (status) {
case STATUS_ERROR:
return "An error occurred while displaying the report.";
case STATUS_CANCEL:
return "Report canceled.";
}
if (TIMER) {
timer.timerString(
"[GenericWebEventProcessor.processEvents] Finished show_report");
}
// --------
// NO ACTION
// --------
} else if (action.equals(uiWebScreenSection.ACTION_NONE)) {
// No action was specified. Allow a blank screen section to be displayed.
if (TIMER) {
timer.timerString(
"[GenericWebEventProcessor.processEvents] Finished no_action");
}
}
// --------
// RETRIEVE
// --------
if (action.equals(uiWebScreenSection.ACTION_SHOW) ||
action.equals(uiWebScreenSection.ACTION_SHOW_UPDATE) ||
action.equals(uiWebScreenSection.ACTION_SHOW_COPY) ||
action.equals(uiWebScreenSection.ACTION_QUERY) ||
action.equals(uiWebScreenSection.ACTION_QUERY_UPDATE) ||
action.equals(uiWebScreenSection.ACTION_QUERY_ALL) ||
action.equals(uiWebScreenSection.ACTION_SHOW_SELECT) ||
action.equals(uiWebScreenSection.ACTION_UPDATE_SELECT)) {
// Need to retrieve data from the data base.
// Note: ACTION_SHOW_SELECT and ACTION_UPDATE_SELECT are the only two actions that have something happen
// in the previous IF statement, and then get retrieved. In all other actions, the data matrix is either
// filled from the HTML, or does not need to be filled.
// Determine the retreive method.
int retrieveMethod = eventProcessor.RETRIEVE_METHOD_ALL;
switch (uiWebScreenSection.getLayoutTypeId()) {
case UIWebScreenSection.LAYOUT_TYPE_FREEFORM:
// Free form section should be retrieved using the primary key.
retrieveMethod = eventProcessor.RETRIEVE_METHOD_PK;
break;
case UIWebScreenSection.LAYOUT_TYPE_TABULAR:
// Tabular section can be retrieved multiple ways depending on the action
// requested by the button or link that triggered it.
if (action.equals(uiWebScreenSection.ACTION_QUERY) ||
action.equals(uiWebScreenSection.ACTION_QUERY_UPDATE)) {
retrieveMethod = eventProcessor.RETRIEVE_METHOD_CLAUSE;
} else if (action.equals(uiWebScreenSection.ACTION_QUERY_ALL)) {
retrieveMethod = eventProcessor.RETRIEVE_METHOD_ALL;
} else {
throw new GenericEntityException("Action \"" + action +
"\" is not valid for tabular layout type.");
}
break;
case UIWebScreenSection.LAYOUT_TYPE_SELECT:
// A select screen section is always retrieved as a query because it is always subordinate
// to some other entity.
retrieveMethod = eventProcessor.RETRIEVE_METHOD_CLAUSE;
break;
case UIWebScreenSection.LAYOUT_TYPE_CROSSTAB:
throw new GenericEntityException(
"Crosstab layout type not implemented yet.");
default:
throw new GenericEntityException("Invalid layout type.");
}
// handle paging of result sets.
int startRow = 0;
int rowsPerPage = uiWebScreenSection.getRowsPerPage();
if (request.getParameter("startRow") != null) {
startRow = Integer.parseInt(request.getParameter("startRow"));
}
uiWebScreenSection.setFirstVisibleRow(startRow);
eventProcessor.setRowOffset(startRow);
eventProcessor.setFetchSize(rowsPerPage);
// Retrieve the data for the screen section.
Debug.logVerbose(
"About to call GenericWebEventProcessor.processRetrieve.", module);
StringBuffer queryIdBuffer = new StringBuffer(queryId);
int status = this.processRetrieve(userInfo, uiWebScreenSection,
retrieveMethod, request, response, delegator,
eventProcessor, dataMatrix, queryIdBuffer, action);
queryId = queryIdBuffer.toString();
if ( eventProcessor.getHasMoreData() )
uiWebScreenSection.setTotalRows(eventProcessor.getTotalRows() + 1);
else
uiWebScreenSection.setTotalRows(eventProcessor.getTotalRows());
Debug.logVerbose("queryId after call to processRetrieve: " +
queryId, module);
switch (status) {
case STATUS_ERROR:
return "An error occurred while retrieving the data from the data base.";
case STATUS_CANCEL:
return "Retrieve canceled.";
}
if (TIMER) {
timer.timerString(
"[GenericWebEventProcessor.processEvents] Finished retrieve");
}
}
// --------
// SHOW_COPY
// --------
if (action.equals(uiWebScreenSection.ACTION_SHOW_COPY)) {
// Displaying a copy of the retrieved record on the screen.
int status = this.processShowCopy(userInfo, uiWebScreenSection,
request, response, delegator, eventProcessor, dataMatrix);
if (TIMER) {
timer.timerString(
"[GenericWebEventProcessor.processEvents] Finished showCopy");
}
switch (status) {
case STATUS_ERROR:
return "An error occurred while updating the copied record before displaying it.";
case STATUS_CANCEL:
return "Copy canceled.";
}
}
// Get values of extra parameters to send to other screen sections when buttons on this screen
// section are clicked.
evalSendQueryParameterList(uiWebScreenSection, request, dataMatrix);
if (TIMER) {
timer.timerString(
"[GenericWebEventProcessor.processEvents] Evaluated \"send\" query parameter list");
}
// ---------------------------------------------------------------------------------
// Generate the HTML to display the data on the screen, and return it to the calling method.
// ---------------------------------------------------------------------------------
Debug.logVerbose("Data matrix before display: " +
dataMatrix.getCurrentBuffer().getContents().toString(), module);
String displayHtml = uiWebScreenSection.display(dataMatrix, action,
queryId, isSubsection, tabOffset);
if (TIMER) {
timer.timerString("[GenericWebEventProcessor.processEvents] End");
}