You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Kai Weber <ka...@glorybox.de> on 2010/03/17 00:58:44 UTC

Setting a default value for input fields

Hi,

if I have a page with an input field which I want to set to a default
value. After the form was displayed and submitted the value of the input
field should be left alone and not changed anymore. What is the
recommended way to do it?  My current solution is the following, but I
feel I miss something. For a text field preferredName I do the
following:

<input t:type="TextField" t:id="preferredName" size="30"/>

@Persist
private String preferredName;

public void setupRender() {
    if (preferredName==null) {
        // preferredName not set already, set default value
        preferredName = "DEFAULT";
    }
}

public void setPreferredName(String name) {
    this.preferredName = name;
}

public String getPreferredName() {
    return this.preferredName;
}

Regards, Kai

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Setting a default value for input fields

Posted by Jagadesh Paladugula <ja...@gmail.com>.
Hi,

Use a boolean variable to track whether the form is submitted or not. Based
on the boolean variable disable the input field.

Assign appropriate value to the boolean variable after for is submitted.

Regards,
Jagadesh

On Wed, Mar 17, 2010 at 5:28 AM, Kai Weber <ka...@glorybox.de> wrote:

> Hi,
>
> if I have a page with an input field which I want to set to a default
> value. After the form was displayed and submitted the value of the input
> field should be left alone and not changed anymore. What is the
> recommended way to do it?  My current solution is the following, but I
> feel I miss something. For a text field preferredName I do the
> following:
>
> <input t:type="TextField" t:id="preferredName" size="30"/>
>
> @Persist
> private String preferredName;
>
> public void setupRender() {
>    if (preferredName==null) {
>        // preferredName not set already, set default value
>        preferredName = "DEFAULT";
>    }
> }
>
> public void setPreferredName(String name) {
>    this.preferredName = name;
> }
>
> public String getPreferredName() {
>    return this.preferredName;
> }
>
> Regards, Kai
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Regards
Jagadesh