package net.sourceforge.stripes.tag; import java.util.HashSet; import java.util.Set; import javax.servlet.ServletRequest; import javax.servlet.jsp.JspException; import net.sourceforge.stripes.action.ActionBean; import net.sourceforge.stripes.controller.StripesConstants; import net.sourceforge.stripes.exception.StripesJspException; import net.sourceforge.stripes.util.CryptoUtil; import net.sourceforge.stripes.util.HtmlUtil; public class ValidWizardFieldsTag extends WizardFieldsTag { @Override @SuppressWarnings("unchecked") public int doEndTag() throws JspException { // Figure out the list of parameters we should not include FormTag form = getParentTag(FormTag.class); Set excludes = new HashSet(); excludes.addAll(form.getRegisteredFields()); excludes.add(StripesConstants.URL_KEY_SOURCE_PAGE); excludes.add(StripesConstants.URL_KEY_FIELDS_PRESENT); excludes.add(StripesConstants.URL_KEY_EVENT_NAME); excludes.add(StripesConstants.URL_KEY_FLASH_SCOPE_ID); // Use the submitted action bean to eliminate any event related parameters ServletRequest request = getPageContext().getRequest(); ActionBean submittedActionBean = (ActionBean) request .getAttribute(StripesConstants.REQ_ATTR_ACTION_BEAN); if (submittedActionBean != null) { String eventName = submittedActionBean.getContext().getEventName(); if (eventName != null) { excludes.add(eventName); excludes.add(eventName + ".x"); excludes.add(eventName + ".y"); } } // Now get the action bean on this form ActionBean actionBean = form.getActionBean(); // If current form only is not specified, go ahead, otherwise check that // the current form had an ActionBean attached - which indicates that the // last submit was to the same form/action as this form if (!isCurrentFormOnly() || actionBean != null) { // Set up a hidden tag to do the writing for us InputHiddenTag hidden = new ValidInputHiddenTag(); hidden.setPageContext(getPageContext()); hidden.setParent(getParent()); // Combine actual parameter names with input names from the form, which might not be // represented by a real request parameter Set paramNames = new HashSet(); paramNames.addAll(request.getParameterMap().keySet()); String fieldsPresent = request.getParameter(StripesConstants.URL_KEY_FIELDS_PRESENT); if (fieldsPresent != null) { paramNames.addAll(HtmlUtil.splitValues(CryptoUtil.decrypt(fieldsPresent))); } // Loop through the request parameters and output the values Class actionBeanType = form.getActionBeanClass(); for (String name : paramNames) { if (!excludes.contains(name) && !isEventName(actionBeanType, name)) { hidden.setName(name); try { hidden.doStartTag(); hidden.doAfterBody(); hidden.doEndTag(); } catch (Throwable t) { /** * Catch whatever comes back out of the doCatch() method and deal with it */ try { hidden.doCatch(t); } catch (Throwable t2) { if (t2 instanceof JspException) throw (JspException) t2; if (t2 instanceof RuntimeException) throw (RuntimeException) t2; else throw new StripesJspException(t2); } } finally { hidden.doFinally(); } } } } return EVAL_PAGE; } }