You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Thomas Cucchietti <th...@gmail.com> on 2010/02/23 16:31:38 UTC
[T5]Access to values of select subcomponents
Hi everybody,
I'm facing a very annoying problem on one of my custom components.
Actually, it's a component (MonthDateField) made itself of two select
components, like shown in its template :
<span id="${controlname}" class="monthdatafield">
<label for="month" class="date-label">${monthLabel}</label>
<t:select t:id="month" blankoption="never" value="month"
model="monthModel"/>
<label for="year" class="date-label">${yearLabel}</label>
<t:select t:id="year" blankoption="never" value="year"
model="yearModel"/>
</span>
In the processSubmission method of my component java class, I want to
retrieve the values of those 2 select subcomponents.
I first wrote it like this :
//Values retrieved
String month = request.getParameter("month");
String year = request.getParameter("year");
SimpleDateFormat sdf = new SimpleDateFormat("MM-yyyy");
String value = month+"-"+year;
//The value is stored in tracker
tracker.recordInput(this, value);
So far, so good : it works perfectly when I make a test with one
monthdatefield component.
But I notice a strange behavior while using 2 MonthDateField components on
the same page. The reason is simple :
In the code above, i retrieve the values of the first MonthDateField only,
for which the select components ids are "month" and "year".
For the second one, the select subcomponents ids are "month_0" and "year_0".
How can I do to retrieve the values for each of the MonthDateField?
- I can't use dynamic ids (like <select t:id="${elementName}-month" ...)
- I tried to use the properties "month" and "year" of my MonthDateField
class as they are needed for the value parameter of the select
subcomponents, but they stay null....
- I tried to inject my select subcomponents using @InjectComponent and to
get the ids with the getClientId() method but same thing, they are always
null
I begin to desperate to find a solution to this problem...
Does somebody have an idea ?
Thanks in advance,
Thomas CUCCHIETTI.
Re: [T5]Access to values of select subcomponents
Posted by Thomas Cucchietti <th...@gmail.com>.
Thiago,
Once more, thanks for your (extremely) quick answer :)
Indeed, It was a lot easier following your advice!
In case it can help somebody, here is the final template :
<span id="${controlname}" class="monthdatafield">
<label for="${controlName}-month"
class="date-label">${monthLabel}</label>
<select id="${controlName}-month" name="${controlName}-month">
<t:loop source="monthModel" value="month">
<t:if test="selectedMonth">
<option selected="yes">${month}</option>
<p:else>
<option>${month}</option>
</p:else>
</t:if>
</t:loop>
</select>
<label for="${controlName}-year"
class="date-label">${yearLabel}</label>
<select id="${controlName}-year" name="${controlName}-year">
<t:loop source="yearModel" value="year">
<t:if test="selectedYear">
<option selected="yes">${year}</option>
<p:else>
<option>${year}</option>
</p:else>
</t:if>
</t:loop>
</select>
</span>
And the corresponding code in MonthDateField.java :
@Override
protected void processSubmission(String elementName) {
//Values retrieved
String month = request.getParameter(getControlName()+"-month");
String year = request.getParameter(getControlName()+"-year");
SimpleDateFormat sdf = new SimpleDateFormat("MM-yyyy");
String value = month+"-"+year;
//The value is stored in tracker
tracker.recordInput(this, value);
.....
}
public boolean isSelectedMonth(){
String input = tracker.getInput(this);
if ((input != null)&&(input.substring(0, 2).equals(month))) {
return true;
}
return false;
}
public boolean isSelectedYear(){
String input = tracker.getInput(this);
if ((input != null)&&(input.substring(3).equals(year))) {
return true;
}
return false;
}
Have a nice day !
Thomas CUCCHIETTI.
2010/2/23 Thiago H. de Paula Figueiredo <th...@gmail.com>
> On Tue, 23 Feb 2010 12:31:38 -0300, Thomas Cucchietti <
> thomas.cucchietti@gmail.com> wrote:
>
> Hi everybody,
>>
>
> Hi!
>
>
> I'm facing a very annoying problem on one of my custom components.
>> Actually, it's a component (MonthDateField) made itself of two select
>> components, like shown in its template :
>>
>
> Why don't you use two ordinary HTML select tags instead of relying in the
> Select component? It's easy and you won't have the problems you're having
> now. ;)
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and instructor
> Owner, software architect and developer, Ars Machina Tecnologia da
> Informação Ltda.
> http://www.arsmachina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
Re: [T5]Access to values of select subcomponents
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, 23 Feb 2010 12:31:38 -0300, Thomas Cucchietti
<th...@gmail.com> wrote:
> Hi everybody,
Hi!
> I'm facing a very annoying problem on one of my custom components.
> Actually, it's a component (MonthDateField) made itself of two select
> components, like shown in its template :
Why don't you use two ordinary HTML select tags instead of relying in the
Select component? It's easy and you won't have the problems you're having
now. ;)
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da
Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org