Java 接缝问题:无法通过反射设置字段值
我的Seam代码有问题,我似乎不知道我做错了什么。这是堆栈跟踪的摘录:Java 接缝问题:无法通过反射设置字段值,java,seam,Java,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 我正在尝试将URL上的参数集传递到我的一个bean中。为此,我在my pages.xml中设置了以下内容: <p
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中。为此,我在my 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>
@Name(“presenceHome”)
@作用域(ScopeType.CONVERSATION)
公共类PresenceHome扩展EntityHome实现可序列化{
@在
私人客户道客户道;
@In(必需=false)
私人长期存在ID;
@In(必需=false)
私人长客户ID;
私人客户;
//接下来是getter、setter和其他方法,它们返回上面定义的正确类型
}
最后,我用来将一页链接到下一页的链接如下所示:
@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。因此,参数被传递,它可以很容易地转换为长类型。但出于某种原因,它不是。我以前在其他项目中也做过类似的事情,现在已经成功了。我只是看不出什么东西现在不起作用
如果我从我的页面声明中删除元素,我就可以很好地访问页面
那么,有人有什么想法吗?试试:
...
…我们的代码做了一些类似的事情,但是Java类中的customerId属性是字符串:
您可以尝试使用属性编辑器 将其放入与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);
}
}
}
您想向pages.xml文件添加转换器。像这样:
<param name="customerId"
value="#{presenceHome.customerId}"
converterId="javax.faces.Long" />
有关更多详细信息,请参见seam附带的seampay示例