Thank you Quinton.
Here is my final solution; it seems to work OK.
Torque generated me four classes .
BaseFormulaire
BaseFormulairePeer
Formulaire
FormulairePeer.
In the classe Formulaire, I added a property queryKey. I needed to add 2
methods :
public String getQueryKey() {
return this.queryKey;
}
public void setQueryKey(String queryKey) {
this.queryKey = queryKey;
}
In the � SecureScreen � class, I get the business object from Torque.
public void doBuildTemplate( RunData data, Context context )
{
// get the display mode : insert, modify or delete
mode = data.getParameters().getString("mode");
context.put("mode", mode);
// get the l'objet form Torque
Formulaire entry = new Formulaire();
if (!mode.equals("insert"))
{
try {
Integer formulaireId =
data.getParameters().getInteger("formulaireid");
entry=FormulairePeer.getById(formulaireId);
context.put("entry", entry);
}
catch (Exception e)
{
context.put("errorTemplate", e.getLocalizedMessage());
}
} else {
try {
context.put("entry", entry);
}
catch (Exception e)
{
context.put("errorTemplate",
e.getLocalizedMessage());
}
}
}
Here is what I did in the Velocity template
$entry.setQueryKey("abc")
<form method="post" action="$link.setAction("param.FormulaireAction")">
#set($formualaireGroup = $intake.FormulaireGroup.mapTo($entry) )
<input type="text" name="$formualaireGroup.Champ.Key"
value="$!formualaireGroup.Champ">
$intake.declareGroups()
</form>
In the action classe, I need also to change the way to get the record Id
and to checkl the form.
public void doUpdate(RunData data, Context context)
throws Exception
{
IntakeTool intake = (IntakeTool)context.get("intake");
Group formulaireGroup = intake.get("FormulaireGroup", "abc");
Integer formulaireId= new Integer();
if ( formulaireGroup != null )
{
formulaireId =
Integer.valueOf(formulaireGroup.get("FormulaireId").toString());
}
/** Get old data */
Formulaire entry = FormulairePeer.getById(formulaireId);
/** Get data */
if (doCtrl(entry, data, context, "modify"))
{
entry.setModified(true);
entry.setNew(false);
entry.save();
}
}
public boolean doCtrl(Formulaire entry, RunData data, Context
context, String mode)
throws Exception
{
IntakeTool intake = (IntakeTool)context.get("intake");
Group formulaireGroup = intake.get("FormulaireGroup",
ProjectConstantes.FORMULAIRE_KEY);
/** formulaire validation */
if (!intake.isAllValid()) {
setTemplate(data, "/param/FormulaireForm.vm");
context.put("mode", mode);
data.getParameters().add("mode", mode);
return false;
} else {
setTemplate(data, "/param/FormulaireList.vm");
}
try
{
if ( formulaireGroup != null )
{
formulaireGroup.setProperties(entry);
} else {
context.put("errorTemplate", "The form is null !");
context.put("mode", mode);
setTemplate(data, "/param/FormulaireForm.vm");
return false;
}
} catch (org.apache.turbine.util.TurbineException tex) {
/** Formulaire constraints not OK */
context.put("errorTemplate", tex.getLocalizedMessage());
context.put("mode", mode);
data.getParameters().add("mode", mode);
setTemplate(data, "/param/FormulaireForm.vm");
return false;
}
/** Properties OK */
data.getParameters().add("mode", mode);
intake.remove(formulaireGroup);
return true;
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
- How to create a business object to represent the intake gr... Xavier Ottolini
- RE: How to create a business object to represent the ... Quinton McCombs
- Re: How to create a business object to represent ... Xavier Ottolini
- Re: How to create a business object to repres... Xavier Ottolini
- RE: How to create a business object to represent the ... Quinton McCombs
- Xavier Ottolini
