Revision: 1356
http://stripes.svn.sourceforge.net/stripes/?rev=1356&view=rev
Author: bengunter
Date: 2010-11-17 04:20:41 +0000 (Wed, 17 Nov 2010)
Log Message:
-----------
Applied fix for STS-771 from 1.5.x branch.
Modified Paths:
--------------
trunk/stripes/src/net/sourceforge/stripes/tag/FormTag.java
trunk/stripes/src/net/sourceforge/stripes/tag/WizardFieldsTag.java
Modified: trunk/stripes/src/net/sourceforge/stripes/tag/FormTag.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/tag/FormTag.java 2010-11-17
04:18:57 UTC (rev 1355)
+++ trunk/stripes/src/net/sourceforge/stripes/tag/FormTag.java 2010-11-17
04:20:41 UTC (rev 1356)
@@ -247,24 +247,7 @@
}
if (!isPartial()) {
- // Write out a hidden field with the name of the page in it....
- // The div is necessary in order to be XHTML compliant, where
a form can contain
- // only block level elements (which seems stupid, but
whatever).
- out.write("<div style=\"display: none;\">");
- out.write("<input type=\"hidden\" name=\"");
- out.write(StripesConstants.URL_KEY_SOURCE_PAGE);
- out.write("\" value=\"");
- HttpServletRequest request = (HttpServletRequest)
getPageContext().getRequest();
- out.write(CryptoUtil.encrypt(request.getServletPath()));
- out.write("\" />");
-
- if (isWizard()) {
- writeWizardFields();
- }
-
- writeFieldsPresentHiddenField(out);
- out.write("</div>");
-
+ writeHiddenTags(out);
writeCloseTag(getPageContext().getOut(), "form");
}
@@ -302,6 +285,36 @@
}
}
+ /** Write out hidden tags that are internally required by Stripes to
process request. */
+ protected void writeHiddenTags(JspWriter out) throws IOException,
JspException {
+ /*
+ * The div is necessary in order to be XHTML compliant, where a form
can contain only block
+ * level elements (which seems stupid, but whatever).
+ */
+ out.write("<div style=\"display: none;\">");
+ writeSourcePageHiddenField(out);
+ if (isWizard()) {
+ writeWizardFields();
+ }
+ writeFieldsPresentHiddenField(out);
+ out.write("</div>");
+ }
+
+ /** Write out a hidden field with the name of the page in it. */
+ protected void writeSourcePageHiddenField(JspWriter out) throws
IOException {
+ out.write("<input type=\"hidden\" name=\"");
+ out.write(StripesConstants.URL_KEY_SOURCE_PAGE);
+ out.write("\" value=\"");
+ out.write(getSourcePageValue());
+ out.write("\" />");
+ }
+
+ /** Get the encrypted value for the hidden _sourcePage field. */
+ protected String getSourcePageValue() {
+ HttpServletRequest request = (HttpServletRequest)
getPageContext().getRequest();
+ return CryptoUtil.encrypt(request.getServletPath());
+ }
+
/**
* <p>In general writes out a hidden field notifying the server exactly
what fields were
* present on the page. Exact behaviour depends upon whether or not the
current form
@@ -320,6 +333,15 @@
* @throws IOException if the writer throws one
*/
protected void writeFieldsPresentHiddenField(JspWriter out) throws
IOException {
+ out.write("<input type=\"hidden\" name=\"");
+ out.write(StripesConstants.URL_KEY_FIELDS_PRESENT);
+ out.write("\" value=\"");
+ out.write(getFieldsPresentValue());
+ out.write("\" />");
+ }
+
+ /** Get the encrypted value of the __fp hidden field. */
+ protected String getFieldsPresentValue() {
// Figure out what set of names to include
Set<String> namesToInclude = new HashSet<String>();
@@ -338,13 +360,7 @@
// Combine the names into a delimited String and encrypt it
String hiddenFieldValue = HtmlUtil.combineValues(namesToInclude);
- hiddenFieldValue = CryptoUtil.encrypt(hiddenFieldValue);
-
- out.write("<input type=\"hidden\" name=\"");
- out.write(StripesConstants.URL_KEY_FIELDS_PRESENT);
- out.write("\" value=\"");
- out.write(hiddenFieldValue);
- out.write("\" />");
+ return CryptoUtil.encrypt(hiddenFieldValue);
}
/**
Modified: trunk/stripes/src/net/sourceforge/stripes/tag/WizardFieldsTag.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/tag/WizardFieldsTag.java
2010-11-17 04:18:57 UTC (rev 1355)
+++ trunk/stripes/src/net/sourceforge/stripes/tag/WizardFieldsTag.java
2010-11-17 04:20:41 UTC (rev 1356)
@@ -68,76 +68,18 @@
* @return EVAL_PAGE in all cases.
*/
@Override
- @SuppressWarnings("unchecked")
public int doEndTag() throws JspException {
- // Figure out the list of parameters we should not include
+ // Get the current form.
FormTag form = getParentTag(FormTag.class);
- Set<String> excludes = new HashSet<String>();
- 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
+ // 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 InputHiddenTag();
- 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<String> paramNames = new HashSet<String>();
- paramNames.addAll(request.getParameterMap().keySet());
- String fieldsPresent =
request.getParameter(URL_KEY_FIELDS_PRESENT);
- if (fieldsPresent != null) {
-
paramNames.addAll(HtmlUtil.splitValues(CryptoUtil.decrypt(fieldsPresent)));
- }
-
- // Loop through the request parameters and output the values
- Class<? extends ActionBean> 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();
- }
- }
- }
+ writeWizardFields(form);
}
return EVAL_PAGE;
@@ -158,6 +100,92 @@
}
/**
+ * Write out a hidden field which contains parameters that should be sent
along with the actual
+ * form fields.
+ */
+ protected void writeWizardFields(FormTag form) throws JspException,
StripesJspException {
+ // Set up a hidden tag to do the writing for us
+ InputHiddenTag hidden = new InputHiddenTag();
+ hidden.setPageContext(getPageContext());
+ hidden.setParent(getParent());
+
+ // Get the list of all parameters.
+ Set<String> paramNames = getParamNames();
+ // Figure out the list of parameters we should not include
+ Set<String> excludes = getExcludes(form);
+
+ // Loop through the request parameters and output the values
+ Class<? extends ActionBean> 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();
+ }
+ }
+ }
+ }
+
+ /** Returns all the submitted parameters in the current or the former
requests. */
+ @SuppressWarnings("unchecked")
+ protected Set<String> getParamNames() {
+ // Combine actual parameter names with input names from the form,
which might not be
+ // represented by a real request parameter
+ Set<String> paramNames = new HashSet<String>();
+ ServletRequest request = getPageContext().getRequest();
+ paramNames.addAll(request.getParameterMap().keySet());
+ String fieldsPresent = request.getParameter(URL_KEY_FIELDS_PRESENT);
+ if (fieldsPresent != null) {
+
paramNames.addAll(HtmlUtil.splitValues(CryptoUtil.decrypt(fieldsPresent)));
+ }
+ return paramNames;
+ }
+
+ /** Returns the list of parameters that should be excluded from the hidden
tag. */
+ protected Set<String> getExcludes(FormTag form) {
+ Set<String> excludes = new HashSet<String>();
+ 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");
+ }
+ }
+ return excludes;
+ }
+
+ /**
* Returns true if {...@code name} is the name of an event handled by
{...@link ActionBean}s of type
* {...@code beanType}.
*
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3.
Spend less time writing and rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development