I am new to tapestry just creating my first application.
I have a form where I am creating an "Object" consisting of 2 other objects, Customer and Country.
<t:beaneditform t:id="createMyObject" t:object="anewobject" rt:submitlabel="Create Object">
<p:customer>
<t:label for="Customer"/>
<t:select t:id="customer" value="aCustomer" model="aCustomerSelectModel" encoder="customerEncoder"/>
</p:customer>
<p:country>
<t:label for="Country"/>
<t:select t:id="country" value="aCountry" model="aCountrySelectModel" encoder="countryEncoder"/>
</p:country>
In my javaclass I have
@Property
private Customer aCustomer;
@Property
private Country aCountry;
@Property
private ObjectBean aNewObject;
public New()
{
// create a SelectModel from the list of customers
aCustomerSelectModel = aSelectModelFactory.create(aCustomers, "name");
aCountrySelectModel = aSelectModelFactory.create(aCountries, "name");
}
and in my ObjectBean I have 2 attributes, country and customer defined as Strings with corresponding getters and setters.
private String aCustomer; private String aCountry;
My CustomerEncoder looks like the following
public class CustomerEncoder implements ValueEncoder<Customer>, ValueEncoderFactory<Customer>
{
@Override
public String toClient(Customer pCustomer)
{
// return the given object's ID
return String.valueOf(pCustomer.getId());
}
@Override
public Customer toValue(String id)
{
// find the color object of the given ID in the database
return new Customer("John", "Smith");
}
// let this ValueEncoder also serve as a ValueEncoderFactory
@Override
public ValueEncoder<Customer> create(Class<Customer> type)
{
return this;
}
void onSubmitFromCreateCustomization()
{
String vCustomer = aNewObject.getCustomer();
String vCountry = aNewObject.getCountry();
}
When I create a new Object my customer and country becomes null. What am I doing wrong, Should my ObjectBean have Objects instead of String like Customer and Country? Is my Encoder wrong or is there anything else. If I try with having just a primitive String instead of an Object that needs Encoders the value is submitted.
All help and comments are welcome!