Geert,
When a property is constrained with editable to false, it is not shown.
But there are cases where it is needed to see such data even if it must
not be changed.
May I suggest a new constrain "visible" that will be false by default if
editable is false.
This need to replace the editable test in
Edit/Add/DeleteTemplateTransformer.java of Rife-crud.
A step further: when a value is non editable, to be able to give a first
value, automatically or manually.
Herewith proposition patches about this two points.
Happy new year (with some hours in advance...)
Pierre
Index:
C:/DEV/Rife/rife-svn/src/framework/com/uwyn/rife/engine/ElementContext.java
===================================================================
--- C:/DEV/Rife/rife-svn/src/framework/com/uwyn/rife/engine/ElementContext.java
(revision 2808)
+++ C:/DEV/Rife/rife-svn/src/framework/com/uwyn/rife/engine/ElementContext.java
(working copy)
@@ -7,24 +7,6 @@
*/
package com.uwyn.rife.engine;
-import com.uwyn.rife.engine.exceptions.*;
-import com.uwyn.rife.template.*;
-import com.uwyn.rife.tools.*;
-import java.util.*;
-
-import com.uwyn.rife.authentication.credentialsmanagers.RoleUserAttributes;
-import com.uwyn.rife.authentication.credentialsmanagers.RoleUserIdentity;
-import com.uwyn.rife.authentication.elements.Identified;
-import com.uwyn.rife.config.RifeConfig;
-import com.uwyn.rife.engine.ContinuationContext;
-import com.uwyn.rife.site.Constrained;
-import com.uwyn.rife.site.ConstrainedProperty;
-import com.uwyn.rife.site.ConstrainedUtils;
-import com.uwyn.rife.site.FormBuilder;
-import com.uwyn.rife.template.exceptions.TemplateException;
-import com.uwyn.rife.tools.exceptions.BeanUtilsException;
-import com.uwyn.rife.tools.exceptions.ConversionException;
-import com.uwyn.rife.tools.exceptions.SerializationUtilsErrorException;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
@@ -34,12 +16,31 @@
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+
import javax.servlet.RequestDispatcher;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
+import com.uwyn.rife.authentication.credentialsmanagers.RoleUserAttributes;
+import com.uwyn.rife.authentication.credentialsmanagers.RoleUserIdentity;
+import com.uwyn.rife.authentication.elements.Identified;
+import com.uwyn.rife.config.RifeConfig;
+import com.uwyn.rife.engine.exceptions.*;
+import com.uwyn.rife.i18n.Encoder;
+import com.uwyn.rife.site.Constrained;
+import com.uwyn.rife.site.ConstrainedProperty;
+import com.uwyn.rife.site.ConstrainedUtils;
+import com.uwyn.rife.site.FormBuilder;
+import com.uwyn.rife.template.*;
+import com.uwyn.rife.template.exceptions.TemplateException;
+import com.uwyn.rife.tools.*;
+import com.uwyn.rife.tools.exceptions.BeanUtilsException;
+import com.uwyn.rife.tools.exceptions.ConversionException;
+import com.uwyn.rife.tools.exceptions.SerializationUtilsErrorException;
+
public class ElementContext
{
public static final String
PREFIX_EXIT_QUERY = "EXIT:QUERY:";
@@ -67,6 +68,7 @@
public static final String
TAG_JANINO_ROLEUSER =
"(?s)^("+PREFIX_JANINO_ROLEUSER+".*):\\s*\\[\\[\\s*(.*)\\s*\\]\\]\\s*$";
public static final String
TAG_GROOVY_ROLEUSER =
"(?s)^("+PREFIX_GROOVY_ROLEUSER+".*):\\s*\\[\\[\\s*(.*)\\s*\\]\\]\\s*$";
+ protected final static String EMPTY_STRING = "";
//$NON-NLS-1$
private static ThreadLocal<ElementSupport> sActiveElements = new
ThreadLocal<ElementSupport>();
private ElementSupport mElement = null;
@@ -1090,14 +1092,14 @@
{
return mOutputs;
}
-
+
Template getHtmlTemplate(String name, String encoding,
TemplateTransformer transformer)
throws TemplateException
{
if (null == name) throw new
IllegalArgumentException("name can't be null.");
if (0 == name.length()) throw new
IllegalArgumentException("name can't be empty.");
- return TemplateFactory.ENGINEHTML.get(name, encoding,
transformer);
+ return mElement.getTemplate(TemplateFactory.ENGINEHTML, name,
encoding, transformer);
}
Template getXhtmlTemplate(String name, String encoding,
TemplateTransformer transformer)
@@ -1106,7 +1108,7 @@
if (null == name) throw new
IllegalArgumentException("name can't be null.");
if (0 == name.length()) throw new
IllegalArgumentException("name can't be empty.");
- return TemplateFactory.ENGINEXHTML.get(name, encoding,
transformer);
+ return mElement.getTemplate(TemplateFactory.ENGINEXHTML, name,
encoding, transformer);
}
Template getXmlTemplate(String name, String encoding,
TemplateTransformer transformer)
@@ -1115,7 +1117,7 @@
if (null == name) throw new
IllegalArgumentException("name can't be null.");
if (0 == name.length()) throw new
IllegalArgumentException("name can't be empty.");
- return TemplateFactory.ENGINEXML.get(name, encoding,
transformer);
+ return mElement.getTemplate(TemplateFactory.ENGINEXML, name,
encoding, transformer);
}
Template getTxtTemplate(String name, String encoding,
TemplateTransformer transformer)
@@ -1124,7 +1126,7 @@
if (null == name) throw new
IllegalArgumentException("name can't be null.");
if (0 == name.length()) throw new
IllegalArgumentException("name can't be empty.");
- return TemplateFactory.ENGINETXT.get(name, encoding,
transformer);
+ return mElement.getTemplate(TemplateFactory.ENGINETXT, name,
encoding, transformer);
}
void processEmbeddedElements(Template template, ElementSupport
embeddingElement)
@@ -1148,6 +1150,7 @@
void print(Template template)
throws TemplateException, EngineException
{
+
List<String> set_values = processTemplate(template);
// set the content type
@@ -1178,7 +1181,7 @@
ArrayList<String> set_values = new ArrayList<String>();
// retrieve the template encoder
- TemplateEncoder encoder = template.getEncoder();
+ Encoder encoder = template.getEncoder();
// process the filtered roleuser tags
evaluateExpressionRoleUserTags(template, null);
@@ -3542,6 +3545,7 @@
}
}
}
+
}
for (Pattern parameter_regexp :
submission.getParameterRegexps())
@@ -3643,14 +3647,26 @@
HashMap<String, PropertyDescriptor> bean_properties =
getBeanUppercasedProperties(bean.getClass());
String[]
parameter_values = null;
ArrayList<String>
set_bean_properties = new ArrayList<String>();
+ ArrayList<String>
set_properties_to_remove = new ArrayList<String>();
+ Constrained constrained =
ConstrainedUtils.makeConstrainedInstance(bean);
Object empty_bean = null;
// handle regular parameters
for (String parameter_name : submission.getParameterNames())
{
- parameter_values =
mElementState.getParameterValues(parameter_name);
- if (null == empty_bean &&
+ parameter_values =
mElementState.getParameterValues(parameter_name);
+
+ if ( parameter_values == null
+ && ConstrainedUtils.visibleConstrainedProperty(constrained,
parameter_name, EMPTY_STRING)
+ && ! ConstrainedUtils.editConstrainedProperty(constrained,
parameter_name, EMPTY_STRING)
+ )
+ {
+ set_properties_to_remove.add(parameter_name);
+ continue;
+ }
+
+ if (null == empty_bean &&
(null == parameter_values ||
0 == parameter_values[0].length()))
{
@@ -3678,6 +3694,7 @@
throw new EngineException(e);
}
}
+ submission.getParameterNames().removeAll(set_properties_to_remove);
// handle regexp parameters
for (Pattern parameter_regexp :
submission.getParameterRegexps())
@@ -3741,7 +3758,6 @@
{
return;
}
-
mElementInfo.validateSubmissionName(submissionName);
if (!hasSubmission(submissionName))
Index:
C:/DEV/Rife/rife-svn/src/framework/com/uwyn/rife/site/ConstrainedProperty.java
===================================================================
---
C:/DEV/Rife/rife-svn/src/framework/com/uwyn/rife/site/ConstrainedProperty.java
(revision 2808)
+++
C:/DEV/Rife/rife-svn/src/framework/com/uwyn/rife/site/ConstrainedProperty.java
(working copy)
@@ -86,6 +86,7 @@
public final static String UNIQUE = "UNIQUE";
public final static String IDENTIFIER = "IDENTIFIER";
public final static String EDITABLE = "EDITABLE";
+ public final static String VISIBLE = "VISIBLE";
public final static String PERSISTANT = "PERSISTANT";
public final static String SAVED = "SAVED";
public final static String DISPLAYED_RAW = "DISPLAYED_RAW";
@@ -653,6 +654,23 @@
return Convert.toBoolean(mConstraints.get(EDITABLE), true);
}
+ public T visible(boolean visible)
+ {
+ setVisible(visible);
+
+ return (T)this;
+ }
+
+ public void setVisible(boolean visible)
+ {
+ mConstraints.put(VISIBLE, visible);
+ }
+
+ public boolean isVisible()
+ {
+ return Convert.toBoolean(mConstraints.get(VISIBLE),
isEditable());
+ }
+
public T persistent(boolean persistent)
{
setPersistent(persistent);
Index:
C:/DEV/Rife/rife-svn/src/framework/com/uwyn/rife/site/FormBuilderXhtml.java
===================================================================
--- C:/DEV/Rife/rife-svn/src/framework/com/uwyn/rife/site/FormBuilderXhtml.java
(revision 2808)
+++ C:/DEV/Rife/rife-svn/src/framework/com/uwyn/rife/site/FormBuilderXhtml.java
(working copy)
@@ -60,7 +60,12 @@
return generateForm(template, bean.getClass(), bean, values,
prefix);
}
- private Collection<String> generateForm(Template template, Class
beanClass, Object bean, Map<String, String[]> values, String prefix)
+ private Collection<String> generateForm( Template template
+ , Class beanClass
+ , Object bean
+ , Map<String, String[]>
values
+ , String prefix
+ )
throws BeanUtilsException
{
ArrayList<String> set_values = new ArrayList<String>();
@@ -90,7 +95,7 @@
}
}
- generateFormField(template, null,
property_name, property_values, prefix, set_values);
+ generateFormField(template, null,
property_name, property_values, prefix, set_values, false);
}
}
else
@@ -112,9 +117,9 @@
set_values.addAll(mValidationBuilder.generateValidationErrors(template,
validated.getValidationErrors(), validated.getValidatedSubjects(), prefix));
set_values.addAll(mValidationBuilder.generateErrorMarkings(template,
validated.getValidationErrors(), validated.getValidatedSubjects(), prefix));
- // store the validation errors and
revalidate
+ // store the validation errors before
revalidate
previous_errors =
validated.getValidationErrors();
-
+
// revalidate the bean to check which
fields have to be displayed
validated.resetValidation();
validated.validate();
@@ -139,18 +144,21 @@
// check if the bean is validated and if the
validation error for the
// property contains an erroneous value, in
that case this value will
// be used instead, since it contains the exact
cause of the error.
+ boolean withError = false;
if (previous_errors != null &&
previous_errors.size() > 0)
{
for (ValidationError error :
previous_errors)
{
- if (error.getErroneousValue()
!= null &&
-
error.getSubject().equals(property_name))
- {
- property_values =
ArrayUtils.createStringArray(error.getErroneousValue(), constrained_property);
- break;
- }
- }
+ if (error.getSubject().equals(property_name)) {
+ withError = withError || true;
+ if (error.getErroneousValue() != null)
+ {
+ property_values =
ArrayUtils.createStringArray(error.getErroneousValue(), constrained_property);
+ break;
+ }
+ }
+ }
}
if (values != null)
@@ -182,7 +190,7 @@
}
// generate the form field
- generateFormField(template, constrained,
property_name, property_values, prefix, set_values);
+ generateFormField(template, constrained,
property_name, property_values, prefix, set_values, withError);
}
if (validated != null)
@@ -195,7 +203,14 @@
return set_values;
}
- private void generateFormField(Template template, Constrained
constrained, String propertyName, String[] propertyValues, String prefix,
ArrayList<String> setValues)
+ private void generateFormField( Template template
+ , Constrained constrained
+ , String propertyName
+ , String[] propertyValues
+ , String prefix
+ , ArrayList<String> setValues
+ , boolean withError
+ )
{
ConstrainedProperty constrained_property = null;
@@ -206,20 +221,30 @@
if (null == constrained_property)
{
- generateField(template, propertyName, propertyValues,
prefix, setValues);
+ generateField(template, propertyName, propertyValues,
prefix, setValues, withError);
}
else
{
- generateField(template, constrained_property,
propertyValues, prefix, setValues);
+ generateField(template, constrained_property,
propertyValues, prefix, setValues, withError);
}
}
- public Collection<String> generateField(Template template,
ConstrainedProperty property, String[] values, String prefix)
+ public Collection<String> generateField( Template template
+ , ConstrainedProperty
property
+ , String[] values
+ , String prefix
+ )
{
- return generateField(template, property, values, prefix, null);
+ return generateField(template, property, values, prefix, null,
false);
}
- private Collection<String> generateField(Template template,
ConstrainedProperty property, String[] values, String prefix, ArrayList<String>
setValues)
+ private Collection<String> generateField( Template template
+ , ConstrainedProperty
property
+ , String[] values
+ , String prefix
+ , ArrayList<String>
setValues
+ , boolean withError
+ )
{
if (null == setValues)
{
@@ -242,17 +267,23 @@
name = prefix+property.getPropertyName();
}
- generateField(template, name, property, values, setValues);
+ generateField(template, name, property, values, setValues,
withError);
return setValues;
}
public Collection<String> generateField(Template template, String name,
String[] values, String prefix)
{
- return generateField(template, name, values, prefix, null);
+ return generateField(template, name, values, prefix, null,
false);
}
- private Collection<String> generateField(Template template, String
name, String[] values, String prefix, ArrayList<String> setValues)
+ private Collection<String> generateField(Template template
+ , String name
+ , String[] values
+ , String prefix
+ , ArrayList<String>
setValues
+ , boolean withError
+ )
{
if (null == setValues)
{
@@ -271,26 +302,44 @@
name = prefix+name;
}
- generateField(template, name, null, values, setValues);
+ generateField(template, name, null, values, setValues,
withError);
return setValues;
}
-
- private void generateField(Template template, String name,
ConstrainedProperty property, String[] values, ArrayList<String> setValues)
+
+ private void generateField( Template template
+ , String name
+ , ConstrainedProperty property
+ , String[] values
+ , ArrayList<String> setValues
+ , boolean withError
+ )
{
Template builder_template =
TemplateFactory.XHTML.get("formbuilder.fields");
- generateFieldHidden(template, name, property, values,
builder_template, setValues);
- generateFieldInput(template, name, property, values,
builder_template, setValues);
- generateFieldSecret(template, name, property, values,
builder_template, setValues);
- generateFieldTextarea(template, name, property, values,
builder_template, setValues);
+ generateFieldHidden(template, name, property, values,
builder_template, setValues, withError);
+ generateFieldInput(template, name, property, values,
builder_template, setValues, withError);
+ generateFieldSecret(template, name, property, values,
builder_template, setValues, withError);
+ generateFieldTextarea(template, name, property, values,
builder_template, setValues, withError);
generateFieldRadio(template, name, property, values,
builder_template, setValues);
generateFieldCheckbox(template, name, property, values,
builder_template, setValues);
generateFieldSelect(template, name, property, values,
builder_template, setValues);
generateFieldDisplay(template, name, property, values,
builder_template, setValues);
}
- private void generateFieldText(String prefix, boolean setValue, boolean
valueAsAttribute, boolean limitLength, boolean disableField, Template template,
String name, ConstrainedProperty property, String[] values, Template
builderTemplate, ArrayList<String> setValues)
+ private void generateFieldText( String prefix
+ , boolean setValue
+ , boolean valueAsAttribute
+ , boolean limitLength
+ , boolean disableField
+ , Template template
+ , String name
+ , ConstrainedProperty property
+ , String[] values
+ , Template builderTemplate
+ , ArrayList<String> setValues
+ , boolean withError
+ )
{
StringBuffer field_buffer = null;
String field = null;
@@ -385,10 +434,13 @@
}
// set the field to disabled if the ConstrainedProperty
is not
- // editable
+ // editable unless it is null or there are errors
if (disableField &&
property != null &&
- !property.isEditable())
+ !property.isEditable()
+ && (value != null)
+ && !withError
+ )
{
builderTemplate.appendBlock(ID_ATTRIBUTES,
ID_DISABLED);
}
@@ -409,24 +461,43 @@
}
}
- private void generateFieldHidden(Template template, String name,
ConstrainedProperty property, String[] values, Template builderTemplate,
ArrayList<String> setValues)
+ private void generateFieldHidden(Template template, String name,
ConstrainedProperty property, String[] values, Template builderTemplate,
ArrayList<String> setValues, boolean withError)
{
- generateFieldText(PREFIX_FORM_HIDDEN, true, true, false, false,
template, name, property, values, builderTemplate, setValues);
+ generateFieldText(PREFIX_FORM_HIDDEN, true, true, false, false,
template, name, property, values, builderTemplate, setValues, withError);
}
- private void generateFieldInput(Template template, String name,
ConstrainedProperty property, String[] values, Template builderTemplate,
ArrayList<String> setValues)
+ private void generateFieldInput( Template template
+ , String name
+ , ConstrainedProperty property
+ , String[] values
+ , Template builderTemplate
+ , ArrayList<String> setValues
+ , boolean withError
+ )
{
- generateFieldText(PREFIX_FORM_INPUT, true, true, true, true,
template, name, property, values, builderTemplate, setValues);
+ generateFieldText( PREFIX_FORM_INPUT
+ , true
+ , true
+ , true
+ , true
+ , template
+ , name
+ , property
+ , values
+ , builderTemplate
+ , setValues
+ , withError
+ );
}
- private void generateFieldSecret(Template template, String name,
ConstrainedProperty property, String[] values, Template builderTemplate,
ArrayList<String> setValues)
+ private void generateFieldSecret(Template template, String name,
ConstrainedProperty property, String[] values, Template builderTemplate,
ArrayList<String> setValues, boolean withError)
{
- generateFieldText(PREFIX_FORM_SECRET, false, true, true, true,
template, name, property, values, builderTemplate, setValues);
+ generateFieldText(PREFIX_FORM_SECRET, false, true, true, true,
template, name, property, values, builderTemplate, setValues, withError);
}
- private void generateFieldTextarea(Template template, String name,
ConstrainedProperty property, String[] values, Template builderTemplate,
ArrayList<String> setValues)
+ private void generateFieldTextarea(Template template, String name,
ConstrainedProperty property, String[] values, Template builderTemplate,
ArrayList<String> setValues, boolean withError)
{
- generateFieldText(PREFIX_FORM_TEXTAREA, true, false, false,
true, template, name, property, values, builderTemplate, setValues);
+ generateFieldText(PREFIX_FORM_TEXTAREA, true, false, false,
true, template, name, property, values, builderTemplate, setValues, withError);
}
private void generateFieldCollection(String prefix, boolean
singleValue, Template template, String name, ConstrainedProperty property,
String[] values, Template builderTemplate, ArrayList<String> setValues)
Index:
C:/DEV/Rife/rife-svn/src/framework/com/uwyn/rife/site/ConstrainedUtils.java
===================================================================
--- C:/DEV/Rife/rife-svn/src/framework/com/uwyn/rife/site/ConstrainedUtils.java
(revision 2808)
+++ C:/DEV/Rife/rife-svn/src/framework/com/uwyn/rife/site/ConstrainedUtils.java
(working copy)
@@ -5,8 +5,6 @@
*/
package com.uwyn.rife.site;
-import com.uwyn.rife.site.Constrained;
-import com.uwyn.rife.site.ConstrainedProperty;
import java.util.Iterator;
public class ConstrainedUtils
@@ -120,6 +118,44 @@
return true;
}
+ public static boolean visibleConstrainedProperty(Constrained bean,
String propertyName, String prefix)
+ {
+ return getConstraint( bean, propertyName, prefix
+ , new Constraint() { public boolean
getDefaultValue(){return true;}
+ public boolean getValue(ConstrainedProperty
property){return !property.isVisible();}}
+ );
+ }
+
+ private interface Constraint {
+ boolean getDefaultValue();
+ boolean getValue(ConstrainedProperty property);
+ }
+
+ private static boolean getConstraint( Constrained bean
+ , String propertyName
+ , String prefix
+ , Constraint constraint
+ )
+ {
+ if (null == bean)
+ {
+ return constraint.getDefaultValue();
+ }
+
+ if ((prefix != null) && propertyName.startsWith(prefix))
+ {
+ propertyName = propertyName.substring(prefix.length());
+ }
+ ConstrainedProperty constrained_property =
bean.getConstrainedProperty(propertyName);
+
+ if ((constrained_property != null) &&
constraint.getValue(constrained_property))
+ {
+ return !constraint.getDefaultValue();
+ }
+
+ return constraint.getDefaultValue();
+ }
+
public static boolean persistConstrainedProperty(Constrained bean,
String propertyName, String prefix)
{
if (null == bean)
Index: C:/DEV/Rife/rife-svn/src/framework/com/uwyn/rife/engine/Submission.java
===================================================================
--- C:/DEV/Rife/rife-svn/src/framework/com/uwyn/rife/engine/Submission.java
(revision 2808)
+++ C:/DEV/Rife/rife-svn/src/framework/com/uwyn/rife/engine/Submission.java
(working copy)
@@ -403,7 +403,8 @@
for (String property : properties)
{
- if
(ConstrainedUtils.editConstrainedProperty(constrained, property,
bean.getPrefix()))
+ // never show if not visible, even if editable
+ if (ConstrainedUtils.visibleConstrainedProperty(constrained,
property, bean.getPrefix()))
{
if
(ConstrainedUtils.fileConstrainedProperty(constrained, property,
bean.getPrefix()))
{
Index:
C:/DEV/Rife/rife-crud-svn/src/java/com/uwyn/rife/crud/templates/DeleteTemplateTransformer.java
===================================================================
---
C:/DEV/Rife/rife-crud-svn/src/java/com/uwyn/rife/crud/templates/DeleteTemplateTransformer.java
(revision 2802)
+++
C:/DEV/Rife/rife-crud-svn/src/java/com/uwyn/rife/crud/templates/DeleteTemplateTransformer.java
(working copy)
@@ -34,8 +34,8 @@
// display the constrained properties in the correct order
for (ConstrainedProperty property : getPositionedProperties())
{
- // only show the CMF admin properties that can be edited
- if (!property.isEditable())
+ // only show the CMF admin properties that are visible
+ if (!property.isVisible())
{
continue;
}
Index:
C:/DEV/Rife/rife-crud-svn/src/java/com/uwyn/rife/crud/templates/EditTemplateTransformer.java
===================================================================
---
C:/DEV/Rife/rife-crud-svn/src/java/com/uwyn/rife/crud/templates/EditTemplateTransformer.java
(revision 2802)
+++
C:/DEV/Rife/rife-crud-svn/src/java/com/uwyn/rife/crud/templates/EditTemplateTransformer.java
(working copy)
@@ -35,8 +35,8 @@
// display the constrained properties in the correct order
for (ConstrainedProperty property : getPositionedProperties())
{
- // only show the CMF admin properties that can be edited
- if (!property.isEditable())
+ // only show the CMF admin properties that are visible
+ if (!property.isVisible())
{
continue;
}
Index:
C:/DEV/Rife/rife-crud-svn/src/java/com/uwyn/rife/crud/templates/AddTemplateTransformer.java
===================================================================
---
C:/DEV/Rife/rife-crud-svn/src/java/com/uwyn/rife/crud/templates/AddTemplateTransformer.java
(revision 2802)
+++
C:/DEV/Rife/rife-crud-svn/src/java/com/uwyn/rife/crud/templates/AddTemplateTransformer.java
(working copy)
@@ -33,8 +33,8 @@
// display the constrained properties in the correct order
for (ConstrainedProperty property : getPositionedProperties())
{
- // only show the CMF admin properties that can be edited
- if (!property.isEditable())
+ // only show the CMF admin properties that are visible
+ if (!property.isVisible())
{
continue;
}
_______________________________________________
Rife-users mailing list
[email protected]
http://www.uwyn.com/mailman/listinfo/rife-users