6

我的 Seam 代码有问题,我似乎无法弄清楚我做错了什么。它让我很头疼:) 这是堆栈跟踪的摘录:

Caused by: java.lang.IllegalArgumentException: Can not set java.lang.Long field com.oobjects.sso.manager.home.PresenceHome.customerId to java.lang.String

我正在尝试将我的 URL 上的参数集传递给我的一个 bean。为此,我在 pages.xml 中进行了以下设置:

<page view-id="/customer/presences.xhtml">
  <begin-conversation flush-mode="MANUAL" join="true" />
  <param name="customerId" value="#{presenceHome.customerId}" />
  <raise-event type="PresenceHome.init" />
  <navigation>
    <rule if-outcome="persisted">
      <end-conversation />
      <redirect view-id="/customer/presences.xhtml" />
    </rule>
  </navigation>
</page>

我的 bean 是这样开始的:

@Name("presenceHome")
@Scope(ScopeType.CONVERSATION)
public class PresenceHome extends EntityHome<Presence> implements Serializable {
  @In
  private CustomerDao customerDao;

  @In(required = false)
  private Long presenceId;

  @In(required = false)
  private Long customerId;

  private Customer customer;

  // Getters, setters and other methods follow. They return the correct types defined above
}

最后,我用来将一个页面链接到下一个页面的链接如下所示:

<s:link styleClass="#{selected == 'presences' ? 'selected' : ''}"
    view="/customer/presences.xhtml" title="Presences" propagation="none">
    <f:param name="customerId" value="#{customerId}" />
    Presences
</s:link>

这一切似乎工作正常。当我将鼠标悬停在页面中的上述链接上时,我得到一个以“?customerId=123”结尾的 URL。所以参数被传递了,它可以很容易地转换为 Long 类型。但由于某种原因,它不是。我之前在其他项目中做过类似的事情,然后它就起作用了。我只是看不出它现在不起作用。

如果我从我的页面声明中删除该元素,我可以正常进入页面。

那么,有人有什么想法吗?

4

4 回答 4

7

您想将转换器添加到 pages.xml 文件。像这样:

<param name="customerId" 
      value="#{presenceHome.customerId}" 
converterId="javax.faces.Long" />

有关更多详细信息,请参阅 seam 提供的 seampay 示例。

于 2008-10-01T16:51:50.100 回答
0

试试: <f:param name="customerId" value="#{customerId.toString()}" /> ……

于 2008-10-01T10:53:21.583 回答
0

我们的代码执行了类似的操作,但Java 类中的customerId属性为String

private String customerId;

public String getCustomerId() {
    return customerId;
}

public void setCustomerId(final String customerId) {
    this.customerId = customerId;
}
于 2008-10-01T12:19:51.687 回答
0

您可以尝试使用属性编辑器。

将其放入与 bean 相同的包中:

import java.beans.PropertyEditorSupport;

public class PresenceHomeEditor extends PropertyEditorSupport {
    public void setAsText(final String text) throws IllegalArgumentException {
        try {
            final Long value = Long.decode(text);
            setValue(value);
        } catch (final NumberFormatException e) {
            super.setAsText(text);
        }
    }
}
于 2008-10-01T12:41:00.997 回答