Clone wiki

AspectFaces / 7.6.Multiple-instances

Sometimes you need to produce form from multiple instances of different classes. For such case you need to consider how to transform it. There are two possible ways, with collate true and collating false (default). The collate is in the AF Context and defines how to process fields (a1,a2,a3,b1,b2,b3 versus a1,b1,a2,b2,a3,b3).

Example classes to process

public class Address {

 @UiOrder(1)
 public String getAddressLine1() { return addressLine1; }
 @UiOrder(2)
 public String getAddressLine2() { return addressLine2; }

 ...
}

public class Contact {

 @UiOrder(1)
 public String getPhone() { return phone; }
 @UiOrder(2)
 public String getSkype() { return skype; }

 ...
}

For JSF OnDemand you need to set collate option in JSF Handler, as is explained in 7.1. Aspect Faces Context.

Information passing to the context through the JSFHandler

public class CustomHandler extends DefaultAFGeneratorHandler {

  protected final TagAttribute collate;

  public CustomHandler(ComponentConfig config, int afCacheTime) {
    super(config, afCacheTime);
    this.collate = this.getAttribute("collate");
  }

  @Override
  protected void hookAddToAFContext(Context context) { 
    if (collate != null) Boolean.parseBoolean(collate.getValue());
    else afContext.setCollate(false); 
  }
}

And use in the JSF

Generate view via Aspect Faces

<!-- Dual Form generated via AspectFaces -->
<af:ui instance="#{bean.instance.address},#{bean.instance.contact}" collate="true" edit="true"/>

Updated