You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by George Christman <gc...@cardaddy.com> on 2013/09/17 21:04:22 UTC

Looping the textfield component with dynamic entity properties

Hello,

I have a form with a gazillion fields on it that all increment with a
numeric. example

timesheet.tsHours01
timesheet.tsHours02
etc

I'd like to dynamically loop this, but have failed to fully get it working.
What I've tried thus far.

<div><t:textfield t:id="empId"  value="timeSheetEntity.empId"/>

<t:Loop source="tsWhours" value="tsWhour" >
     <div class="col-xs-15"><div><t:textfield t:id="tsWhour2"
id="${tsWhour.id}" value="tsWhour.property"/></div></div>
</t:Loop>


    @Property
    private List<TimeSheetEntity> timeSheetEntity;

    @Property
    private List<TsWhour> tsWhours;

    @Property
    private TsWhour tsWhour;

    public void onPrepareFromForm() {
        this.timeSheetEntity =
timeSheetService.getCreateOrUpdate(timeSheetEntity);

        tsWhours = new ArrayList<TsWhour>();
        tsWhours.add(new TsWhour(timeSheetEntity, "TsWhours01"));
        tsWhours.add(new TsWhour(timeSheetEntity, "TsWhours02"));
        tsWhours.add(new TsWhour(timeSheetEntity, "TsWhours03"));
    }

    public class TsWhour {

        private TimeSheetEntity timeSheetEntity;
        private String id;

        private BigDecimal property;

        public TsWhour() {
        }

        public TsWhour(TimeSheetEntity timeSheetEntity, String id) {
            this.timeSheetEntity = timeSheetEntity;
            this.id = id;
        }

        public BigDecimal getProperty() {
            try {
                Method method = TimeSheetEntity.class.getMethod("get" +
id);
                return (BigDecimal) method.invoke(timeSheetEntity);
            } catch (NoSuchMethodException ex) {

Logger.getLogger(TimeSheet.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SecurityException ex) {

Logger.getLogger(TimeSheet.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {

Logger.getLogger(TimeSheet.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalArgumentException ex) {

Logger.getLogger(TimeSheet.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InvocationTargetException ex) {

Logger.getLogger(TimeSheet.class.getName()).log(Level.SEVERE, null, ex);
            }
            return null;
        }

        public void setProperty(BigDecimal value) {
            System.out.println(value);
        }

        public TimeSheetEntity getTimeSheetEntity() {
            return timeSheetEntity;
        }

        public void setTimeSheetEntity(TimeSheetEntity timeSheetEntity) {
            this.timeSheetEntity = timeSheetEntity;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

    }


I'm able to get the page to load, but when I save it fails. If possible, I
would rather not specify the datatype as a bigdecimal to keep it completely
dynamic.




-- 
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York

Re: Looping the textfield component with dynamic entity properties

Posted by Lance Java <la...@googlemail.com>.
Not sure exactly what you're doing but you might find the map: binding
prefix useful from tapestry-stitch

http://tapestry-stitch.uklance.cloudbees.net/mapbindingdemo

Re: Looping the textfield component with dynamic entity properties

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 17 Sep 2013 16:19:11 -0300, George Christman  
<gc...@cardaddy.com> wrote:

> Hi Thiago,

Hi!

> I just realized I forgot to put the exception.

:P

> It was failing
> with the following exception on submit. The values loaded without issue  
> on page render.
> An exception has occurred processing this request.
> Could not find a coercion from type java.lang.String to type
> org.healthresearch.etss.pages.employee.TimeSheet$TsWhour.

This means you haven't provided a Translator for TimeSheet.TsWhour nor  
Tapestry could provide one by itself. In addition, never, never ever use  
classes nested into pages, components and mixins outside of them  
(including passing instances of them to other components, as it's the case  
here) due to Tapestry's live class reloading, which also ends up changing  
the inner classes too.

-- 
Thiago H. de Paula Figueiredo

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


Re: Looping the textfield component with dynamic entity properties

Posted by George Christman <gc...@cardaddy.com>.
Hi Thiago, I just realized I forgot to put the exception. It was failing
with the following exception on submit. The values loaded without issue on
page render.

An exception has occurred processing this request.
Could not find a coercion from type java.lang.String to type
org.healthresearch.etss.pages.employee.TimeSheet$TsWhour.



On Tue, Sep 17, 2013 at 3:13 PM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Tue, 17 Sep 2013 16:04:22 -0300, George Christman <
> gchristman@cardaddy.com> wrote:
>
>  Hello,
>>
>
> Hi!
>
>
>  I'm able to get the page to load, but when I save it fails.
>>
>
> Define "it fails". It's too vague.
>
>
>  If possible, I would rather not specify the datatype as a bigdecimal to
>> keep it completely dynamic.
>>
>
> In Tapestry, usually the best way of dealing with dynamic forms is to use
> BeanEditor coupled with some BeanModel handling, very probably implementing
> a PropertyModel. This way, you can define the datatype for each field with
> any logic you want.
>
> --
> Thiago H. de Paula Figueiredo
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<us...@tapestry.apache.org>
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York

Re: Looping the textfield component with dynamic entity properties

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 17 Sep 2013 16:04:22 -0300, George Christman  
<gc...@cardaddy.com> wrote:

> Hello,

Hi!

> I'm able to get the page to load, but when I save it fails.

Define "it fails". It's too vague.

> If possible, I would rather not specify the datatype as a bigdecimal to  
> keep it completely dynamic.

In Tapestry, usually the best way of dealing with dynamic forms is to use  
BeanEditor coupled with some BeanModel handling, very probably  
implementing a PropertyModel. This way, you can define the datatype for  
each field with any logic you want.

-- 
Thiago H. de Paula Figueiredo

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