0

将 ejb 实体导入 Tapestry 项目在“生成的 sorces (jax-ws)”中看起来像这样

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.datatype.XMLGregorianCalendar;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "money", propOrder = {
    "moneyAmount",
    "moneyCurrency",
    "moneyDate",
    "moneyFinishDate",
    "moneyIO",
    "moneyId",
    "moneyName",
    "moneyNextDate",
    "moneyNumber",
    "moneyPurpose",
    "moneyRenewal",
    "moneyTs"
})
public class Money {
    protected Double moneyAmount;
    protected String moneyCurrency;
    @XmlSchemaType(name = "dateTime")
    protected XMLGregorianCalendar moneyDate;
    @XmlSchemaType(name = "dateTime")
    protected XMLGregorianCalendar moneyFinishDate;
    protected MoneyIO moneyIO;
    protected Integer moneyId;
    protected String moneyName;
    @XmlSchemaType(name = "dateTime")
    protected XMLGregorianCalendar moneyNextDate;
    protected Integer moneyNumber;
    protected String moneyPurpose;
    protected MoneyNextTimeType moneyRenewal;
    @XmlSchemaType(name = "dateTime")
    protected XMLGregorianCalendar moneyTs;

    // Getters and Setters for above
    ...
}

所有 XMLGregorianCalendar 都是 ejb 模块中的日期

在挂毯页面类中:

@ejb
statefullEjbMoney

@Persist
@Property
List<Money> mylist

void onPrepareForRender() {
  mylist=statefullEjbMoney.findAll();
}

在我的模板中,我有:

 <table t:type="grid" t:source="mylist"
                   t:rowsPerPage="10" t:pagerPosition="both"
                   t:exclude="moneyId,moneyIO,moneyNextDate,moneyFinishDate,cliClientId"
                   t:reorder="moneyName,moneyPurpose,moneyAmount,moneyCurrency,moneyDate">
                [Grid here]
            </table>

glassfish 日志中的堆栈跟踪是:

Render queue error in SetupRender[Expenses:grid.columns]: Bean editor model for logic.ws.Money does not contain a property named 'moneyDate'.
org.apache.tapestry5.ioc.internal.util.TapestryException: Bean editor model for logic.ws.Money does not contain a property named 'moneyDate'. [at classpath:org/apache/tapestry5/corelib/components/Grid.tml, line 6]
    ...
Caused by: org.apache.tapestry5.ioc.util.UnknownValueException: Bean editor model for logic.ws.Money does not contain a property named 'moneyDate'.
    at org.apache.tapestry5.internal.beaneditor.BeanModelImpl.get(BeanModelImpl.java:160)
    at org.apache.tapestry5.internal.beaneditor.BeanModelImpl.reorder(BeanModelImpl.java:223)
    at org.apache.tapestry5.internal.beaneditor.BeanModelUtils.reorder(BeanModelUtils.java:107)
    at org.apache.tapestry5.internal.beaneditor.BeanModelUtils.modify(BeanModelUtils.java:51)
    at org.apache.tapestry5.corelib.components.Grid.getDataModel(Grid.java:523)
    at org.apache.tapestry5.corelib.components.GridColumns.setupRender(GridColumns.java:112)
    at org.apache.tapestry5.corelib.components.GridColumns.setupRender(GridColumns.java)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$SetupRenderPhase.invokeComponent(ComponentPageElementImpl.java:179)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$AbstractPhase.invoke(ComponentPageElementImpl.java:138)
    ... 84 more

如果有人知道出了什么问题,请分享?

4

3 回答 3

2

例外情况是 Bean Editor Model 没有名为 的属性moneyDate,我一直认为这有点不清楚。

解释一下,Tapestry 不知道 anXMLGregorianCalendar是什么,所以当 Tapestry 为您的网格创建 Bean 模型时,它会忽略它。

快速解决方案

解决此问题的快速方法是在您的Money实体上提供返回标准 JDKCalendar的 getter,并在您的网格中显示这些属性。

所以在你的实体中:

public class Money {
  @XmlSchemaType(name = "dateTime")
  protected XMLGregorianCalendar moneyDate;

  public Calendar getMoneyDataCalendar() {
    return moneyDate.toGregorianCalendar();
  }
  ...
}

然后在您的网格中使用它:

<table t:type="grid" t:source="mylist" t:rowsPerPage="10" t:pagerPosition="both"
  t:exclude="moneyId,moneyIO,moneyNextDate,moneyFinishDate,cliClientId"
  t:reorder="moneyName,moneyPurpose,moneyAmount,moneyCurrency,moneyDateCalendar">

  [Grid here] Note 'moneyDate' changed to 'moneyDateCalendar' above [/Grid here]

</table>

长解决方案

如果您计划显示大量XMLGregorianCalendars,那么(更复杂的)解决方案是告诉 Tapestry XMLGregorianCalendars 以及如何显示它们。

首先告诉 Tapestry 通过将XMLGregorianCalendar其添加到您的 Module 类来添加到 Bean 模型:

@Contribute(DefaultDataTypeAnalyzer.class)
public static void contributeDefaultDataTypeAnalyzer(MappedConfiguration<Class<?>, String> config) {
  config.add(XMLGregorianCalendar.class, "xmlGregorianCalendar");
}

现在告诉 Tapestry 如何显示新的"xmlGregorianCalendar". 添加到您的模块类:

@Contribute(BeanBlockSource.class)
public static void contributeDisplayBlocksForGrid(Configuration<BeanBlockContribution> config) {
  config.add(new DisplayBlockContribution("xmlGregorianCalendar", "DisplayBlocks", "xmlGregorianCalendar"));
}

您现在必须创建一个DisplayBlocks使用 id 组件调用的页面xmlGregorianCalendar

public class DisplayBlocks {

  @Inject
  private Locale locale;

  @Property
  @Environmental
  private PropertyOutputContext context;

  private final DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);

  public DateFormat getDateFormat(){
    return dateFormat;
  }

  public Date getCalendarDate() {
    XMLGregorianCalendar calendar = (XMLGregorianCalendar) context.getPropertyValue();        
    if (calendar == null)
        return null;        
    return calendar.getTime();
  }
}
<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd">

  <t:block id="xmlGregorianCalendar">
    <t:output value="calendarDate" format="dateFormat"/>
  </t:block>

</t:container>

有关更多信息,请查看 Tapestry 源代码并了解 Tapestry 如何配置自身。特别看:

org.apache.tapestry5.services.TapestryModule.contributeDefaultDataTypeAnalyzer()    
org.apache.tapestry5.services.TapestryModule.provideDefaultBeanBlocks()
org.apache.tapestry5.corelib.pages.PropertyDisplayBlocks
于 2013-05-18T11:27:31.927 回答
0

我做了一些最小的改变来使它工作

描述如下。

Appmodule.java 添加了以下方法

public static void contributeDefaultDataTypeAnalyzer(MappedConfiguration<Class<?>, String> config) {
    config.add(XMLGregorianCalendar.class, "XMLGregorianCalendar");
}

@Contribute(BeanBlockSource.class)
public static void contributeDisplayBlocksForGrid(Configuration<BeanBlockContribution> config) {
    config.add(new DisplayBlockContribution("XMLGregorianCalendar", "DisplayBlocks", "XMLGregorianCalendar"));
}

在方法contributeDefaultDataTypeAnalyzer 上没有@Contribute

显示块.java

public class DisplayBlocks {

    @Inject
    private Locale locale;
    @Property
    @Environmental
    private PropertyOutputContext context;
    private final DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);

    public DateFormat getDateFormat() {
        return dateFormat;
    }

    public Date getCalendarDate() {
        XMLGregorianCalendar date = (XMLGregorianCalendar) context.getPropertyValue();
        Calendar calendar = date.toGregorianCalendar();
        if (calendar == null) {
            return null;
        }
        return calendar.getTime();
    }

XMLGregorianCalendar 到 context.getPropertyValue(); 比日历

显示块.tml

<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd">

    <t:block id="XMLGregorianCalendar">
        <t:output value="calendarDate" format="dateFormat"/>
    </t:block>

</t:container>

将块 ID 更改为 XMLGregorianCalendar

于 2013-05-19T09:53:37.883 回答
0

我收到这样的错误并到达此页面。从错误中可以清楚地看出,您应该轻松地为您的属性添加一个公共 getter。

于 2021-12-24T08:23:11.810 回答