0

初めてのアプリケーションを作成したばかりのタペストリーです。

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 を持つ必要がありますか? 私のエンコーダーが間違っていますか、それとも他に何かありますか? エンコーダーを必要とするオブジェクトの代わりにプリミティブな文字列だけを使用しようとすると、値が送信されます。

すべてのヘルプとコメントは大歓迎です!

4

1 に答える 1

0

あなたの質問に「コメント」して、いくつかのことについて尋ねることはできませんが(私は評判が悪いのではないかと思います!)、あなたのシナリオは明確ではないので、ここに私が役立つと思うものがあります. 次の 2 点に注意する必要があります。

  1. beaneditor が含まれているフォームの準備イベントで、新しいオブジェクトとそれに関連付けられているオブジェクト (顧客と国) を初期化します。

    @OnEvent(component="your-form-id",value=EventConstants.PREPARE)

  2. Tapestry5 の 5.4 より前のバージョン (http://tapestry.apache.org/release-notes-54.html) では、ポスト メカニズムの後にリダイレクトが実装されているため、リクエスト データが失われるため、ページ変数の一部を@Persistして保持する必要があります。 1 つのフォーム送信とその応答の間の値です。

于 2012-05-25T17:35:06.280 に答える