You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Vjeran Marcinko <vj...@tis.hr> on 2004/01/21 08:55:05 UTC
Initial form field value
Hi folks.
I'm not using Intake to handle form fields, because I have some requirements
that it doesn't fit into. Nevertheless, I use standard way of handling form
fields :
<input type="text" name="url" value="$data.parameters.url">
I'm using value="$data.parameters.url", thus field value would be populated
with previous value in case of reviewing form page due to validation
exception. Everything works fine except I dunno how to set elegantly initial
field value ? In case above, I would like to be 'http://' value since it is
URL field. Can somebody point me the way ?
Regards,
Vjeran
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org
RE: Initial form field value
Posted by David Demner <tu...@demner.com>.
Hi Vjeran,
What do you mean by elegant?
An if statement will work, but certainly not elegant.
---
#if ("$!data.Parameters.Url" == "")
#set ($url = "http://")
#else
#set ($url = "$data.Parameters.Url")
#end
<input type="text" name="url" value="$url">
---
Alternately, you can stuff it into the context from the underlying java
class:
--- blah.java ---
package com.whatever;
// Velocity Stuff
import org.apache.velocity.context.Context;
import org.apache.commons.lang.StringUtils;
// Turbine Stuff
import org.apache.turbine.util.RunData;
import org.apache.turbine.modules.screens.VelocityScreen;
public class blah extends VelocityScreen {
public void doBuildTemplate(RunData data, Context context) {
// the context object has already been setup for you!
context.put("url",
StringUtils.defaultString(data.getParameters().get("Url"), "http://"));
}
}
--- blah.vm ---
<input type="text" name="url" value="$url">
---
Not elegant either unless you are already using an underlying class and can
just add the one line.
Good luck,
David
-----Original Message-----
From: Vjeran Marcinko [mailto:vjeran@tis.hr]
Sent: Tuesday, January 20, 2004 11:55 PM
To: turbine-user@jakarta.apache.org
Subject: Initial form field value
Hi folks.
I'm not using Intake to handle form fields, because I have some requirements
that it doesn't fit into. Nevertheless, I use standard way of handling form
fields :
<input type="text" name="url" value="$data.parameters.url">
I'm using value="$data.parameters.url", thus field value would be populated
with previous value in case of reviewing form page due to validation
exception. Everything works fine except I dunno how to set elegantly initial
field value ? In case above, I would like to be 'http://' value since it is
URL field. Can somebody point me the way ?
Regards,
Vjeran
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org