velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jon Stevens <>
Subject Re: automatic context filling ??
Date Tue, 06 Feb 2001 18:36:02 GMT
on 2/6/01 7:41 AM, "Thomas Fahrmeyer" <>

> is there a way to do the following:
> UtilityClass.fillContext(context, "", "scott");
> It should do: Look in the given context for a object named "user", then call
> setName("scott")
> That would be very cool. I wanna use it to pre-fill a form. I want to create
> a context and put all the
> inital objects like "user" into that context. Then validate the form data.
> If the form is invalid I would like to do:
> String value = request.getParameter("") // because all the form
> elements are named like the
> // Velocity context objects
> UtilityClass.fillContext(context, "", value);
> Then I use this context to display the data in the template.
> I know you are confused once again ;), but I think you can imagine what I
> wanna have.
> How can I achieve that, which classes are involved. Can I customize Velocity
> behavior.


You are close to developing a business object, but not quite there yet. :-)
The right way to do this is to have a object class: User

public class User
    setName(String name)
    String getName()

Then, what you would do is this:

User user = new User();
context.put ("user", user);

Now, if you are using Turbine's ParameterParser class, you could do
something like this:

User user = new User();
context.put("user", user);

That would use introspection to look for form fields names which match the
same method names.

The ParameterParser class is here:


Look at the setProperties() method for details. Let me also state that this
is why you should use Turbine...the code that you need to take advantage of
is already there. :-)



If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
<> | <>

View raw message