The problem is that the @FieldLabel component is rendered even if user.version is not null. This references the usernameField and causes it to be included in the validation delegate field tracking (or something along those lines). Try restructuring like this:

 <tr jwcid="@If" condition="ognl:user.version == null" element="tr">
<th><label jwcid="@FieldLabel" field="ognl:components.usernameField">Username</label>:</th>
   <td><input jwcid="usernameField" type="text" id="username"/></td>
 </tr>
 <tr jwcid="@Else" element="tr">
   <th>Username</th>
   <td><span jwcid="@Insert" value="ognl:user.username"/>
<input jwcid="@Hidden" type="hidden" value="ognl:user.username" id="username"/>
   </td>
 </tr>

You can make this less redundant by using messages for your field labels. Instead of hard-coding "Username" in the @Else, use an Insert component to display a message and then use the same message key in your usernameField's displayName property. Also notice that the condition attribute does not need to be specified in an Else component.

-Ryan

Matt Raible wrote:
In Tapestry 3.0, I was able to show a text field when a field wasn't
populated, then hide it when it was.

    <tr>
        <th>
            <label jwcid="@FieldLabel"
field="ognl:components.usernameField">Username</label>
        </th>
        <td style="height: 20px">
            <div jwcid="@contrib:FormConditional"
condition="ognl:user.version == null">
                <input jwcid="usernameField" type="text" id="username"/>
            </div>
            <div jwcid="@contrib:FormConditional"
condition="ognl:user.version != null">
                <span jwcid="@Insert" value="ognl:user.username"/>
                <input jwcid="@Hidden" type="hidden"
value="ognl:user.username" id="username"/>
            </div>
        </td>
    </tr>

    <component id="usernameField" type="ValidField">
        <binding name="value" expression="user.username"/>
        <binding name="validator" expression="beans.requiredValidator"/>
        <message-binding name="displayName" key="user.username"/>
    </component>

In Tapestry 4.0, I've translated to the following for the new DTD and
deprecated components:

    <tr>
        <th>
            <label jwcid="@FieldLabel"
field="ognl:components.usernameField">Username</label>
        </th>
        <td style="height: 20px">
            <div jwcid="@If" condition="ognl:user.version == null">
                <input jwcid="usernameField" type="text" id="username"/>
            </div>
            <div jwcid="@Else" condition="ognl:user.version != null">
                <span jwcid="@Insert" value="ognl:user.username"/>
                <input jwcid="@Hidden" type="hidden"
value="ognl:user.username" id="username"/>
            </div>
        </td>
    </tr>

    <component id="usernameField" type="TextField">
        <binding name="value" value="user.username"/>
        <binding name="validators" value="validators:required"/>
        <binding name="displayName" value="message:user.username"/>
    </component>

However, when the field is hidden (the @Else logic executes), I get a
validation error:

You must enter a value for Username.

Is it possible to make the HTML in the @Else block have the same
componentId as usernameField?

Thanks,

Matt

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to