Navin -
Thanks very much for the reply.
You can use templates for components too (similar to page
templates), by extending the component class from "BaseComponent".
Then you just add an HTML with the same name as the component and
that's all.
Sorry if original post is confusing.
I'm ok with using templates on components (BaseComponent, etc), I think.
Except for a specific case where I'm not sure when/how the component
would perform it's primary task.
An example of this might be a "Date Chooser" component -- where the
generated HTML is 3 popups for YYYY / MM / DD .. and the caller
binding passes in/out a Date object. eg,
FooPage.html
~~~~~~~~~~~~~~~~
..
<span jwcid="@DateChooser" date="startDate" />
..
<span jwcid="@DateChooser" date="endDate" />
..
~~~~~~~~~~~~~~~~
If I pretend I'm the DateChooser component, and the application
accepts a form submit from FooPage..
My question is:
When do I call this.setDate() ?
I don't know what guarantees the behavior of DateInput.java (below).
Maybe that's what I'm missing? Something simple like call setDate()
(or equivalent) in the set'er of the last form bound ivar(?), eg.
DateInput.setYear(). I suppose that seems kind of cheezy vs. a
notification or something more formal .. which is why I'd be
surprised if that was the trick, but I could definitely work with that.
If I don't call ~setDate() in the last set'er for the last input
bound ivar .. then when is the appropriate time to call it?
I don't have the app in front of me at the minute .. :-/
But maybe something like PageEndRenderListener ? by implementing
pageEndRender() - and checking for isRewinding() ?
http://tapestry.apache.org/tapestry4/tapestry/apidocs/org/apache/
tapestry/event/PageEndRenderListener.html
And you can use the "InvokeListener" component part of the core
Tapestry framework. Just add this component in your custom
component's template at the point where you want the listener
invoked. The parameters for this component are very much similar to
the DirectLink component. I think this will serve your purpose.
Sorry - I wasn't more clear about 'listener' -doh!
eg. - ?
<form jwcid="@shared:SimpleForm"
listener="ognl:listeners.castBallotAction" stateful="ognl:false"
focus="ognl:false">
I think you're just reminding me about form's listener & the .java's
action method .. eg. castBallotAction() .. I guess what's important
here is that the "Date Chooser" call setDate() before the action
method is invoked. (Or better - at what point is the
DateChooser.date available to the Page ?)
I hope this is more clear.
Ok, Thanks-Matt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
package ws.sundraw.tapestry.components;
import java.util.Calendar;
import org.apache.tapestry.BaseComponent;
import org.apache.tapestry.IBinding;
import org.apache.tapestry.form.IPropertySelectionModel;
/**
* Implements a component that accepts date input and is rendered
* as three HTML <select> elements, for day, month and year.
* Months are shown by their names (January, February etc.) and are
* automatically localized according to the preferred locale of the
page
* where the component is used
*
* @author Alexander Kolesnikov (www.sundraw.ws)
* @version 1.0
*
**/
public abstract class DateInput extends BaseComponent {
private int d, m, y;
private Calendar c;
protected void initialize() {
d = m = 1;
y = 2000;
c = null;
}
public IPropertySelectionModel getDaysModel() {
return new DayModel();
}
public IPropertySelectionModel getMonthsModel() {
return new LocalizedMonthsModel(getPage().getLocale());
}
public IPropertySelectionModel getYearsModel() {
return new YearModel();
}
public int getDay() {
c = readDate();
d = c.get(Calendar.DATE);
return d;
}
public void setDay(int day) {
d = day;
}
public int getMonth() {
m = c.get(Calendar.MONTH) + 1;
return m;
}
public void setMonth(int month) {
m = month;
}
public int getYear() {
y = c.get(Calendar.YEAR);
return y;
}
public void setYear(int year) {
y = year;
c.set(y, m - 1, d);
upDate(c);
}
public Calendar readDate() {
return (Calendar)getDateBinding().getObject("date",
Calendar.class);
}
public void upDate(Calendar c) {
getDateBinding().setObject(c);
}
public abstract IBinding getDateBinding();
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]