public void handlePageBody(Writer writer, NavigationContext nc) throws ServletException, IOException { HttpServletRequest request = nc.getHttpRequest(); String commandSpec = request.getParameter(PanelEditorCommand.PANEL_EDITOR_COMMAND_REQUEST_PARAM_NAME); if (commandSpec != null) { PanelEditorCommand command = new PanelEditorCommand(); command.setParameters(commandSpec); // verify that this command is configured to be in this pae if (verifyPanelEditorInPage(nc, command)) { try { command.handleCommand(writer, nc, false); } catch (CommandException e) { getLog().error("Command error in body", e); throw new ServletException(e); } return; } else { log.error( "Request to execute a panel editor '" + command.getPanelEditorName() + "' that does not exist in page."); } } super.handlePageBody(writer, nc); }
/** * Verify that the request panel editor does exist in the page * * @param nc * @param peCommand * @return */ public boolean verifyPanelEditorInPage(NavigationContext nc, PanelEditorCommand peCommand) { boolean valid = false; int bodyType = getBodyType().getValueIndex(); if (bodyType == NavigationPageBodyType.COMMAND) { ValueSource commandExpr = getCommandExpr(); if (commandExpr != null) { String commandText = commandExpr.getTextValue(nc); if (commandText != null) { try { Command command = Commands.getInstance().getCommand(commandText); if (command instanceof PanelEditorCommand) { String peName = ((PanelEditorCommand) command).getPanelEditorName(); if (peCommand.getPanelEditorName().equals(peName)) valid = true; } } catch (Exception e) { getLog().error("Command error in " + this.getClass().getName(), e); } } } } else if (bodyType == NavigationPageBodyType.PANEL) { // this is the layout panel defined for the page HtmlPanels panels = getBodyPanel().getChildren(); for (int i = 0; i < panels.size(); i++) { if (panels.get(i) instanceof HtmlCommandPanel) { Command command = ((HtmlCommandPanel) panels.get(i)).getCommand(); if (command instanceof PanelEditorCommand) { String peName = ((PanelEditorCommand) command).getPanelEditorName(); if (peCommand.getPanelEditorName().equals(peName)) { valid = true; break; } } } } } return valid; }