craigmcc 02/03/16 17:44:42
Modified: doc/userGuide struts-html.xml
src/share/org/apache/struts/taglib/html HiddenTag.java
web/example registration.jsp subscription.jsp
Log:
Add a new write="true" attribute to the <html:hidden> custom tag, which tells
Struts to render the value for this field to the response as well as create the
<input> tag. For backwards compatibility, the default value is false.
This feature eliminates the need for an extra <bean:write> tag in the common
case where you use conditional logic to make a field editable or not, but
always want it included in the POST data:
<logic:equal name="formBean" property="nameEditable" value="true">
<html:text property="name"/>
</logic:equal>
<logic:notEqual name="formBean" property="nameEditable" value="true">
<html:hidden property="name" write="true"/>
</logic:notEqual>
PR: Bugzilla #6142
Submitted by: Brill Pappin <brill at users.sourceforge.net>
Revision Changes Path
1.5 +13 -0 jakarta-struts/doc/userGuide/struts-html.xml
Index: struts-html.xml
===================================================================
RCS file: /home/cvs/jakarta-struts/doc/userGuide/struts-html.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- struts-html.xml 16 Mar 2002 04:02:07 -0000 1.4
+++ struts-html.xml 17 Mar 2002 01:44:41 -0000 1.5
@@ -1595,6 +1595,19 @@
corresponding bean property value]
</info>
</attribute>
+
+ <attribute>
+ <name>write</name>
+ <required>false</required>
+ <rtexprvalue>true</rtexprvalue>
+ <info>
+ Should the value of this field also be rendered to the
+ response page to make it visible, in addition to creating
+ an HTML type="hidden" element? By default, only the
+ hidden element is created.
+ </info>
+ </attribute>
+
</tag>
1.2 +79 -4
jakarta-struts/src/share/org/apache/struts/taglib/html/HiddenTag.java
Index: HiddenTag.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/HiddenTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HiddenTag.java 6 Jan 2001 21:50:39 -0000 1.1
+++ HiddenTag.java 17 Mar 2002 01:44:41 -0000 1.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/HiddenTag.java,v 1.1
2001/01/06 21:50:39 mschachter Exp $
- * $Revision: 1.1 $
- * $Date: 2001/01/06 21:50:39 $
+ * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/HiddenTag.java,v 1.2
2002/03/17 01:44:41 craigmcc Exp $
+ * $Revision: 1.2 $
+ * $Date: 2002/03/17 01:44:41 $
*
* ====================================================================
*
@@ -63,16 +63,23 @@
package org.apache.struts.taglib.html;
+import javax.servlet.jsp.JspException;
+import org.apache.struts.util.RequestUtils;
+import org.apache.struts.util.ResponseUtils;
+
+
/**
* Custom tag for input fields of type "text".
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2001/01/06 21:50:39 $
+ * @version $Revision: 1.2 $ $Date: 2002/03/17 01:44:41 $
*/
public class HiddenTag extends BaseFieldTag {
+ // ----------------------------------------------------------- Constructors
+
/**
* Construct a new instance of this tag.
*/
@@ -80,6 +87,74 @@
super();
this.type = "hidden";
+
+ }
+
+
+ // ------------------------------------------------------------- Properties
+
+
+ /**
+ * Should the value of this field also be rendered to the response?
+ */
+ protected boolean write = false;
+
+ public boolean getWrite() {
+ return (this.write);
+ }
+
+ public void setWrite(boolean write) {
+ this.write = write;
+ }
+
+
+ // --------------------------------------------------------- Public Methods
+
+
+ /**
+ * Generate the required input tag, followed by the optional rendered text.
+ * Support for <code>write</code> property since 1.1.
+ *
+ * @exception JspException if a JSP exception has occurred
+ */
+ public int doStartTag() throws JspException {
+
+ // Render the <html:input type="hidden"> tag as before
+ super.doStartTag();
+
+ // Is rendering the value separately requested?
+ if (!write) {
+ return (EVAL_BODY_TAG);
+ }
+
+ // Calculate the value to be rendered separately
+ String results = null;
+ if (value != null) {
+ results = ResponseUtils.filter(value);
+ } else {
+ Object value = RequestUtils.lookup(pageContext, name, property,
+ null);
+ if (value == null) {
+ results = "";
+ } else {
+ results = ResponseUtils.filter(value.toString());
+ }
+ }
+
+ // Render the result to the output writer
+ ResponseUtils.write(pageContext, results);
+ return (EVAL_BODY_TAG);
+
+ }
+
+
+ /**
+ * Release any acquired resources.
+ */
+ public void release() {
+
+ super.release();
+ write = false;
}
1.21 +3 -1 jakarta-struts/web/example/registration.jsp
Index: registration.jsp
===================================================================
RCS file: /home/cvs/jakarta-struts/web/example/registration.jsp,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- registration.jsp 30 Nov 2001 02:12:00 -0000 1.20
+++ registration.jsp 17 Mar 2002 01:44:42 -0000 1.21
@@ -39,9 +39,11 @@
</logic:equal>
<logic:equal name="registrationForm" property="action"
scope="request" value="Edit">
+<%--
<bean:write name="registrationForm" property="username"
scope="request" filter="true"/>
- <html:hidden property="username"/>
+--%>
+ <html:hidden property="username" write="true"/>
</logic:equal>
</td>
</tr>
1.28 +1 -2 jakarta-struts/web/example/subscription.jsp
Index: subscription.jsp
===================================================================
RCS file: /home/cvs/jakarta-struts/web/example/subscription.jsp,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- subscription.jsp 5 Mar 2002 04:23:57 -0000 1.27
+++ subscription.jsp 17 Mar 2002 01:44:42 -0000 1.28
@@ -57,8 +57,7 @@
</logic:equal>
<logic:notEqual name="subscriptionForm" property="action"
scope="request" value="Create">
- <bean:write name="subscriptionForm" property="host"/>
- <html:hidden property="host"/>
+ <html:hidden property="host" write="true"/>
</logic:notEqual>
</td>
</tr>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>