初めてのアプリケーションを作成したばかりのタペストリーです。
Customer と Country という 2 つのオブジェクトで構成される「オブジェクト」を作成するフォームがあります。
<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>
私のjavaclassには
@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");
}
私のObjectBeanには、対応するゲッターとセッターを持つ文字列として定義されたcountryとcustomerの2つの属性があります。
プライベート文字列 aCustomer; プライベート文字列 aCountry;
私の CustomerEncoder は次のようになります
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();
}
新しいオブジェクトを作成すると、顧客と国が null になります。私の ObjectBean は、Customer や Country のように String ではなく Object を持つ必要がありますか? 私のエンコーダーが間違っていますか、それとも他に何かありますか? エンコーダーを必要とするオブジェクトの代わりにプリミティブな文字列だけを使用しようとすると、値が送信されます。
すべてのヘルプとコメントは大歓迎です!