You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Christopher Dodunski (Tapestry)" <Ch...@christopher.net.nz> on 2020/08/18 09:00:55 UTC

Making certain BeanEditForm fields 'read only'

Hi all,

I'm just wondering whether there is a simple and elegant way of making 
certain BeanEditForm fields 'read only' within the controller class, 
rather than in the view template?  In certain circumstances I wish to 
dynamically prevent users from modifying certain fields (a pretty common 
scenario).

It would be nice to inject a field component in the controller, and 
simply invoke setReadOnly() to have it display its value within the 
BeanEditForm, but grayed out and unable to be altered.  These fields are 
all 'Select' type in my case.

The Select component has a 'disabled' parameter, but I suspect a 
disabled field would behave quite differently—possibly not even 
displaying its value.

Below is an example field taken from the template.

     <p:vesselSelected>
         <div class="form-group">
             <label t:type="label" t:for="vessel"/>
             <select t:type="select" t:id="vessel" 
t:value="vesselSelected" t:model="vesselSelectModel" 
t:label="message:label.vessel"/>
         </div>
     </p:vesselSelected>

Regards,

Chris.

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


Re: Making certain BeanEditForm fields 'read only'

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, Aug 26, 2020 at 7:27 AM Christopher Dodunski (Tapestry) <
ChrisFromTapestry@christopher.net.nz> wrote:

> Thanks Thiago.
>

My pleasure to help!


> I guess it's something worth considering in the future - updating
> BeanEditor and related components to better leverage HTML5 features.
>

Which ones, specifically? And Tapestry form field components do handle
disabled="true" correctly as far as I remember, completely ignoring
disabled components when processing the form submission, so I don't think
your workaround described below is needed.

What HTML5 features do you mean?


>
> A workaround in my case was to have SelectModelFactory reduce the number
> of selectable elements down to one, making selecting something different
> impossible.  The fields of interest are synthetic properties added to
> the BeanModel, so this workaround was possible.
>
> Regards,
>
> Chris Dodunski.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

-- 
Thiago

Re: Making certain BeanEditForm fields 'read only'

Posted by "Christopher Dodunski (Tapestry)" <Ch...@christopher.net.nz>.
Hi Thiago,

A couple of years' ago I extended Tapestry's AbstractField to create a 
DateTimeField, as DateField's standard JavaScript calendar looks a 
little dated (pardon the pun).  DateTimeField leverages the HTML5 
datetime-local input type, and one of its parameters is 'boolean 
readOnly'.  I think the wheel-based date picker has a more modern feel, 
and is more mobile friendly.

I'm happy to contribute the code for this component if you think it 
might make a good form field, an optional alternative to DateField?

My original question was more about exploring the possibility of 
manipulating form field components from within the controller class, and 
whether this is a good idea or not.  I like to keep the view template as 
'dumb' as possible, free of multiple <t:if...> and suchlike.

Although I never tried it, the below may be a better approach than the 
one I took.

     <t:select ... t:disabled="disabled" t:readonly="readonly"/>

     public isDisabled() {
         return ...;
     }

     public isReadonly() {
         return ...;
     }

Regards,

Chris.

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


Re: Making certain BeanEditForm fields 'read only'

Posted by "Christopher Dodunski (Tapestry)" <Ch...@christopher.net.nz>.
Thanks Thiago.

I guess it's something worth considering in the future - updating 
BeanEditor and related components to better leverage HTML5 features.

A workaround in my case was to have SelectModelFactory reduce the number 
of selectable elements down to one, making selecting something different 
impossible.  The fields of interest are synthetic properties added to 
the BeanModel, so this workaround was possible.

Regards,

Chris Dodunski.

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


Re: Making certain BeanEditForm fields 'read only'

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Hello!

I don't think there's a way of doing that that doesn't require changing
BeanEditor (which does the heavy lifting for BeanEditForm) and one at least
one of PropertyModel and PropertyConduit.



On Tue, Aug 18, 2020 at 6:19 AM Christopher Dodunski (Tapestry) <
ChrisFromTapestry@christopher.net.nz> wrote:

> Hi all,
>
> I'm just wondering whether there is a simple and elegant way of making
> certain BeanEditForm fields 'read only' within the controller class,
> rather than in the view template?  In certain circumstances I wish to
> dynamically prevent users from modifying certain fields (a pretty common
> scenario).
>
> It would be nice to inject a field component in the controller, and
> simply invoke setReadOnly() to have it display its value within the
> BeanEditForm, but grayed out and unable to be altered.  These fields are
> all 'Select' type in my case.
>
> The Select component has a 'disabled' parameter, but I suspect a
> disabled field would behave quite differently—possibly not even
> displaying its value.
>
> Below is an example field taken from the template.
>
>      <p:vesselSelected>
>          <div class="form-group">
>              <label t:type="label" t:for="vessel"/>
>              <select t:type="select" t:id="vessel"
> t:value="vesselSelected" t:model="vesselSelectModel"
> t:label="message:label.vessel"/>
>          </div>
>      </p:vesselSelected>
>
> Regards,
>
> Chris.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

-- 
Thiago