Hi all,
The goal of this email is to have your thoughts on the intake tool
improvement suggestions:
1. Extend rules with custom java class So we will have the following in
the xml file:
<field name="password" ..>
<rule name="extend"
value="org.turbine.rules.XYZ">system.form.field.mandatory</rule>
</field>
and implement an interface that receives RunData/ServerData, the field
name and the intake group as parameters.
2. The intake tool is commonly known for field validation based on
implementated rules. But it is also great to use it to render
automatically UI forms. For instance, a 'LoginGrp' group is created in
the intake.xml file, the screen class extends an 'Engine' and generates
automatically the form fields described in the intake file and put the
result in the context. (see an example in the attached file). This works
partially for me, there are some missing pieces:
A UI field is composed of
- a field such as an input (type text, radio, checkbox), an selection,
textarea ... (1)
- a field name (handles by the 'displayName' attribute in intake.xml)
- a warning message when rules are not met (intake rule's content)
- a hint message to help the user to fill the field (2)
(1) can we introduce a new attribute in 'group's field' called
'mapToWidgetObject' and 'mapToWidgetObject'?
for a text field, we ll have something like:
<field name="password"
mapToWidgetObject="org.turbine.service.intake.widget.passwordfield" ..>
the org.turbine.service.intake.widget.passwordfield widget will have the
responsability to render the ui
(2) can we introduce a new attribute in 'group's field' called
'displayHint'?
e.g.
<field name="username" displayName="system.basic.username"
displayHint="system.basic.username.hint" ...>
So below is my wishes list for 2007,
Happy new year to everyone,
Thomas
package com.bobo.services.intakeEngine;
import java.util.Enumeration;
import java.util.Hashtable;
import org.apache.commons.lang.StringUtils;
import org.apache.turbine.services.intake.IntakeException;
import org.apache.turbine.services.intake.IntakeTool;
import org.apache.turbine.services.intake.model.Field;
import org.apache.turbine.services.intake.model.Group;
import org.apache.turbine.util.RunData;
import org.apache.velocity.context.Context;
import com.bobo.Constants;
import com.bobo.services.template.widget.form.InputPassword;
import com.bobo.services.template.widget.form.InputText;
import com.bobo.tools.DojoTool;
import com.bobo.tools.LocalizationTool;
import com.bobo.tools.TemplateLinkTool;
import com.bobo.utils.exception.BoboException;
import com.bobo.utils.lang.String2ReplaceUtils;
/**
* TODO - reliability testing
* @author tung
*
*/
public class IntakeEngine {
private Group intakeGrp;
private TemplateLinkTool link;
private LocalizationTool l10n;
private DojoTool dojo;
private IntakeTool intake;
private ScreenFormData screenFormDate;
private String formOpen;
private Hashtable fields = new Hashtable();
private String hiddenFields;
public IntakeEngine ( RunData data, Context context, ScreenFormData sfd )
throws IntakeException
{
link = ((TemplateLinkTool) context.get(Constants.TEMPLATE_LINK_TOOL));
l10n = ((LocalizationTool) context.get(Constants.LOCALIZATION_TOOL));
intake = ((IntakeTool) context.get(Constants.INTAKE_TOOL));
dojo = ((DojoTool) context.get(Constants.DOJO_TOOL));
screenFormDate = sfd;
IntakeTool.PullHelper ph = intake.get( sfd.getIntakeGrpName() );
if ( ph != null )
{
intakeGrp = ph.getDefault();
initFormOpen( data, context );
initFields( data, context );
initHiddenFields();
}
else
{
//TODO - rediriger l'ecran?
new BoboException(data, "Can't create intake group " +
sfd.getIntakeGrpName(),
Constants.INTAKE_ENGINE_ERROR_MESSAGE, null);
}
}
public String render()
{
return formOpen() + renderFields() + hiddenFields + formClose();
}
public String renderAllFields()
{
return renderFields() + hiddenFields;
}
public String renderHiddenFields()
{
return hiddenFields;
}
private static final String TEMPLATE_HIDDEN_FIELDS =
"<input type=\"hidden\" name=\"eventSubmit_{1}\" value=\"{2}\">";
private void initHiddenFields()
{
hiddenFields = String2ReplaceUtils.replace(
TEMPLATE_HIDDEN_FIELDS,
screenFormDate.getActionMethod(),
"Next");
hiddenFields += intake.declareGroups();
}
/**
* TODO
* In order to enable other types of input, will need an input type in
intake.xml
* @throws IntakeException
*/
private void initFields( RunData data, Context context ) throws
IntakeException
{
String [] fieldNames = intakeGrp.getFieldNames();
for ( int i=0; i<fieldNames.length; i++)
{
Field field = intakeGrp.get( fieldNames[i] );
if ( StringUtils.contains( field.getName(), "password") )
fields.put( fieldNames[i],
InputPassword.render ( data, context,
field.getKey(),
l10n.get( field.getDisplayName()
),
l10n.get( field.getMessage()) ));
else
fields.put( fieldNames[i],
InputText.render ( data, context,
field.getKey(),
l10n.get(field.getDisplayName()),
"", "",
l10n.get(field.getMessage()),
"",
field.isRequired()));
}
}
public String renderFields ()
{
String result = "";
for ( Enumeration e = fields.keys() ; e.hasMoreElements() ; )
{
String key = e.nextElement().toString();
result = fields.get( key ).toString() + result;
}
return result;
}
public String renderField( String fieldname )
{
return fields.get( fieldname ).toString();
}
public String getKey ( String fieldname )
{
try {
return intakeGrp.get( fieldname ).getKey();
} catch (IntakeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "";
}
}
private static final String TEMPLATE_FORM_OPEN = "<form id=\"{1}\"
name=\"{2}\" action=\"{3}\" method=\"post\">";
private void initFormOpen( RunData data, Context context )
{
formOpen = String2ReplaceUtils.replace(
TEMPLATE_FORM_OPEN,
intakeGrp.getGID(),
intakeGrp.getGID(),
link.setPage(data.getScreenTemplate()).setAction(screenFormDate.getActionClass()).toString());
}
public String formOpen()
{
return formOpen;
}
private static final String TEMPLATE_FORM_CLOSE = "</form>";
public String formClose()
{
return TEMPLATE_FORM_CLOSE;
}
public String getGID()
{
return intakeGrp.getGID();
}
public static final String TEMPLATE_FORM_SUBMIT_BUTTON =
"<button dojoType=\"Button\"
onclick=\"document.getElementById('{1}').submit()\">" +
"{2}" +
"</button>";
public static final String DOJO_BUTTON_LIB = "dojo.widget.Button";
public String renderSubmitButton( String buttonKey )
{
dojo.require(DOJO_BUTTON_LIB);
return String2ReplaceUtils.replace ( TEMPLATE_FORM_SUBMIT_BUTTON,
getGID(), l10n.get(buttonKey));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]