Will Norris wrote:
>
> I remember seeing a component in some other framework
> that would allow you to have a form that could be toggled to a read-
> only state. This is not just making the input boxes disabled, but
> rather converting them to be normal text output (so you don't have to
> make an entirely separate page to have someone review their form
> inputs).
If you want the toggle to be performed without refreshing the client, you'll
have to do it in Javascript. If, on the other hand, you want a conditional
render on some criteria, there are a couple of ways to do this. The first,
easiest, but most cumbersome way would be to wrap each form value in an @If
component, where condition=true would render a @TextField, while a
condition=false would render an Insert. For example:
<span jwcid="@If" condition="ognl: registeredUser == true">
<input jwcid="@TextField" value="ognl: firstName" />
</span>
<span jwcid="@Else">
<span jwcid="@Insert" value="ognl: firstName" />
</span>
This would require you to wrap each and every field with an if/else, which
could be cumbersome on a page with a lot of different fields. The second
way to do this would be to create your own TextField component that takes
whatever condition you're testing for and renders either a form field, or
just the form value. It would look something like this:
ToggleField.java:
---
public abstract class ToggleField extends BaseComponent {
/*
* Note, you can define your parameters here using the @Parameter annotation,
or in the JWC file.
* I prefer the JWC file.
@Parameter
public abstract Boolean getCondition();
@Parameter
public abstract String getValue();
*/
}
ToggleField.jwc:
---
<?xml version="1.0"?>
<!DOCTYPE component-specification PUBLIC "-//Apache Software
Foundation//Tapestry Specification 4.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">
<component-specification class="ToggleField" allow-body="yes">
<parameter name="condition" required="yes" />
<parameter name="value" required="yes" />
</component-specification>
ToggleField.html:
---
<span jwcid="@If" condition="ognl:condition">
<input jwcid="@TextField" value="ognl:value" />
</span>
<span jwcid="@Else">
<span jwcid="@Insert" value="ognl:value" />
</span>
Usage (inline in an HTML file)
---
<span jwcid="@ToggleField" condition="ognl: registeredUser == true"
value="ognl: firstName" />
Please forgive any syntactical errors, but that's the basic jist.
--
View this message in context:
http://www.nabble.com/toggle-form-display-tf2088143.html#a5843782
Sent from the Tapestry - User forum at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]