You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Russell John-Baptiste <rj...@yahoo.com> on 2012/09/04 22:52:22 UTC

Binding an array and accessing elements of that array in a template

Sorry if this was answered or shown else where but i'm not seeing it.

I have an array called MonthlyBills[12] in my page class.

In my template, how can I reference each index?

<t:textfield t:id="jan" size="3" value="MonthlyBills[0]"/>
<t:textfield t:id="feb" size="3" value="MonthlyBills[1]"/>
<t:textfield t:id="mar" size="3" value="MonthlyBills[2]"/>
...etc.

does not work.

Cheers.

Re: Binding an array and accessing elements of that array in a template

Posted by trsvax <tr...@gmail.com>.
If you make a method in your page class

public String monthlyBill(Integer index) {
    return monthlyBill[index];
}

I think you can this in the tml file


<t:textfield t:id="jan" size="3" value="monthlyBill(0)"/> 





--
View this message in context: http://tapestry.1045711.n5.nabble.com/Binding-an-array-and-accessing-elements-of-that-array-in-a-template-tp5716045p5716046.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Binding an array and accessing elements of that array in a template

Posted by RJB III <rj...@yahoo.com>.
You guys were right...[of course]...

Thanks a million.

Here's my abbreviated final solution:


JAVA:

    @Property
    private Integer index= 0;


    @Persist
    @Property
    Integer year;


    @Property
    private Integer[] funDays = new Integer[13];

    public Integer getFunDay() {
        return funDays[index];
    }

    public void setFunDay(Integer value) {
        funDays[index] = value;
    }

  public String month(Integer num) {
        String month = "invalid";
        DateFormatSymbols dfs = new DateFormatSymbols();
        String[] months = dfs.getMonths();
        if (num >= 0 && num <= 11) {
            month = months[num];
        }
        return month.substring(0, 3);
    }

    public Boolean getDisplayTr() {
        //Logic needed to format information in billableDays in a 3 by 4
table.
        return (index == 3 || index == 7);
    }


TML:

<t:form t:id="ChangeFunDays" t:autofocus="true">

    

        	
            <label for="${month(index)}">${month(index)}</label>
            <t:textfield value="funDay"/>
            <t:if test="DisplayTr">
                

            </t:if>
        
    


    

        	
            <t:submit t:id="submit" value="Save"/>
        
    

</t:form>



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Binding-an-array-and-accessing-elements-of-that-array-in-a-template-tp5716045p5716127.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Binding an array and accessing elements of that array in a template

Posted by Michael Prescott <mi...@gmail.com>.
Also, a Loop will let you do something like:

<t:loop source="MonthlyBills" value="monthlyBill">
  <t:textfield size="3" value="monthlyBill"/>
</t:loop>

With a property:

@Property
private int /* or whatever */ monthlyBill;

Michael

On 4 September 2012 16:52, Russell John-Baptiste <rj...@yahoo.com> wrote:

> Sorry if this was answered or shown else where but i'm not seeing it.
>
> I have an array called MonthlyBills[12] in my page class.
>
> In my template, how can I reference each index?
>
> <t:textfield t:id="jan" size="3" value="MonthlyBills[0]"/>
> <t:textfield t:id="feb" size="3" value="MonthlyBills[1]"/>
> <t:textfield t:id="mar" size="3" value="MonthlyBills[2]"/>
> ...etc.
>
> does not work.
>
> Cheers.