Sure, no problem.
InputOrInsert.html:
<span jwcid="@Conditional" condition="ognl:inputMode == 'edit'">
<span jwcid="@Conditional" condition="ognl:!isDate(value)">
<span jwcid="@TextField" value="ognl:value"
size="ognl:size">Edit
mode, string</span>
</span>
<span jwcid="@Conditional" condition="ognl:isDate(value)">
<span jwcid="@DatePicker" value="ognl:value">Edit mode,
date</span>
</span>
</span>
<span jwcid="@Conditional" condition="ognl:inputMode == 'edit'" invert="true">
<span jwcid="@Insert" value="ognl:value">View mode, never mind the
type</span>
</span>
InputOrInsert.page:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE component-specification
PUBLIC "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
<component-specification
class="myproject.component.InputOrInsert"
allow-informal-parameters="no"
allow-body="no">
<parameter name="inputMode"
type="java.lang.String"
required="no"
default-value="'edit'"
direction="in"/>
<!-- "size" is just for TextField, whenever I want to
make a larger one... -->
<parameter name="size"
type="java.lang.String"
required="no"
default-value="'20'"
direction="in"/>
<parameter name="value"
type="java.lang.Object"
required="yes"
direction="auto"/>
</component-specification>
InputOrInsert.java:
package myproject.component;
import org.apache.tapestry.BaseComponent;
import java.util.*;
public class InputOrInsert extends BaseComponent
{
public boolean isDate(Object obj) {
if (obj!= null &&
obj.getClass().getName().equals("java.util.Date"))
return true;
return false;
}
}
a usage example:
<span jwcid="@InputOrInsert" inputMode="ognl:inputMode"
value="ognl:somevariable" size="50">whatever</span>
As you can see, I'm defining the inputMode as a variable in my page,
so I can control at runtime whether I want to allow input or just
display values, page-wise. The "size" variable of the component is
only there because I needed to send the @TextField different sizes,
but it has a default value of 20 and thus can safely be ignored.
Also, I couldn't get OGNL to work with something like
ognl:value.class.name, so I had to create the java file and determine
the class type from there.
My guess is that Trails uses a lot of code like this. Anyone know about this?
Hope it helps,
Dario
On 4/25/06, Mark <[EMAIL PROTECTED]> wrote:
> Hi Dario,
>
> Would you mind posting your code?
>
> MARK
>
> > Well... maybe I didn't explain myself very well. The thing is that I
> > wanted a component that could act as an input of some type or as an
> > @Insert, depending on the context and some parameters. I just coded
> > it, I called it @InputOrInsert, and does exactly what I described. I
> > had a little difficulty catching the type of the object to bind to the
> > component, in order to display a DatePicker when it is of type
> > java.util.Date, but it's working now.
> >
> > Thanks,
> >
> > Dario
> >
> >
> > On 4/25/06, Shing Hing Man <[EMAIL PROTECTED]> wrote:
> >
> >> In case you did not know, the InsertText component (in
> >> T3) has a parameter disabled.
> >> On the confirmation page, you could just set the
> >> disabled parameter to true. Note that, the value of a
> >> disabled InsertText will be ignored when the form is
> >> submitted. Please see the document for more details
> >>
> >> http://jakarta.apache.org/tapestry/3.0.4/doc/ComponentReference/TextField.html
> >>
> >> Shing
> >>
> >>
> >> --- Darío Vasconcelos <[EMAIL PROTECTED]>
> >> wrote:
> >>
> >>
> >>> I'm wondering what is the best and more elegant way
> >>> to solve a problem
> >>> that I guess we've all faced: there's an input form
> >>> that has 20+
> >>> fields, that on submit needs to go to a
> >>> "confirmation" page, which
> >>> shows the same 20+ fields to the user, so he can
> >>> review his inputs and
> >>> go back or commit them.
> >>>
> >>> The obvious way to do it is to create two .html
> >>> pages that are almost
> >>> the same but one with @Insert fields and the other
> >>> one with
> >>> @TextFields, but I don't want to do that because the
> >>> number of fields
> >>> and the final HTML design will surely change often.
> >>>
> >>> I also don't want to fill my .html with
> >>> @Conditionals for each field,
> >>> there should be a better option. If only there was a
> >>> component called
> >>> @InsertOrTextField that, depending on the value of
> >>> a, say, "inputMode"
> >>> parameter, would display an @Insert, @DatePicker, or
> >>> a @TextField.
> >>>
> >>> I'm using TP3. Do you think I should try to code my
> >>> @InsertOrTextField
> >>> component or am I not seeing another obvious
> >>> solution?
> >>>
> >>> Regards,
> >>>
> >>> Dario
> >>>
> >>>
> >>> --
> >>> Times have not become more violent. They have just
> >>> become more televised.
> >>> Marilyn Manson
> >>>
> >>>
> >>>
> >> ---------------------------------------------------------------------
> >>
> >>> To unsubscribe, e-mail:
> >>> [EMAIL PROTECTED]
> >>> For additional commands, e-mail:
> >>> [EMAIL PROTECTED]
> >>>
> >>>
> >>>
> >> Home page :
> >> http://uk.geocities.com/matmsh/index.html
> >>
> >>
> >>
> >> ___________________________________________________________
> >> To help you stay safe and secure online, we've developed the all new
> >> Yahoo! Security Centre. http://uk.security.yahoo.com
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >>
> >>
> >
> >
> > --
> > Times have not become more violent. They have just become more televised.
> > Marilyn Manson
> >
> > ---------------------------------------------------------------------
> > 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]
>
>
--
Times have not become more violent. They have just become more televised.
Marilyn Manson
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]