Dear Magnolians
I'm trying to "upgrade" a custom profile update form to the STK PUR form.
However when you open the form all fields are empty. I would like to auto fill
in all of the form values by reading them from the current user – all except
the password. Of course these values should only be filled in once. If the user
removes the data from a field it should stay empty.
Is there an easy way to achieve this?
I've tried to write a custom form engine with the "handleTokenMissing()" method
below. It is called and goes through all fields, creates FormField objects for
every field and set's the value. However the form still does not display the
value set in this method... so I guess I'm still missing something. Any ideas?
@Override
protected View handleTokenMissing() throws RepositoryException {
// create a form state
FormState formState = FormStateUtil.createAndSetFormState();
// we need a step
FormStepState step = new FormStepState();
step.setParagraphUuid(this.getConfigurationNode().getUUID());
formState.addStep(step);
if (SecurityUtil.isAuthenticated()) {
User user = MgnlContext.getUser();
// auto fill in the values from the user
if (this.getConfigurationNode().hasContent("fieldsets")) {
Iterator itFieldsets =
this.getConfigurationNode().getContent("fieldsets").getChildren().iterator();
while (itFieldsets.hasNext()) {
Content fieldset = (Content) itFieldsets.next();
if (fieldset.hasContent("fields")) {
Iterator iterator =
fieldset.getContent("fields").getChildren().iterator();
while (iterator.hasNext()) {
final Content node = (Content) iterator.next();
if (node.hasNodeData("controlName")) {
final String controlName =
node.getNodeData("controlName").getString();
FormField field = new FormField();
field.setName(controlName);
if (controlName.equals("password") ||
controlName.equals("passwordConfirmation")) {
// skip this!
} else {
try {
field.setValue(BeanUtils.getProperty(user, controlName));
} catch (Exception ex) {
if (user.getProperty(controlName) !=
null) {
field.setValue(user.getProperty(controlName));
}
}
}
step.add(field);
}
}
}
}
}
}
View view = getFormView(step);
return view;
}
Thanks!
-will
----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------