2008-10-01 67 views
6

我遇到了我的Seam代码问题,我似乎无法弄清楚我做错了什么。它做我的头:)这里的堆栈跟踪的摘录:Seam问题:无法通过反射设置字段值

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

我试图让我的网址传递到我的豆子中的一个参数集。要做到这一点,我有我的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> 

我的豆开始是这样的:

@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类型。但由于某种原因,事实并非如此。我之前在其他项目中做过类似的事情,现在已经有效了。我只是看不到它现在没有工作。

如果我从我的页面声明中删除元素,我可以很好地理解页面。

那么,有没有人有任何想法?

回答

7

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

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

查看seapay示例,了解更多详细信息。

0

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

0

我们的代码有类似的功能,但在Java类客户ID财产作为字符串

private String customerId; 

public String getCustomerId() { 
    return customerId; 
} 

public void setCustomerId(final String customerId) { 
    this.customerId = customerId; 
} 
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); 
     } 
    } 
}