我有以下JSF表格:
...
<p:column>
<h:outputText value="Image Id:" style="font-weight:bold; padding-right:10px" />
</p:column>
<p:column>
<h:outputText value="#{syncCenterBean.selectedCRImageData.imId}" />
</p:column>
</p:row>
....
<p:row>
<p:column>
<h:outputText value="Image Type" style="font-weight:bold; padding-right:10px" />
</p:column>
<p:column>
<p:selectOneMenu id="imtype" value="#{syncCenterBean.cRImageType}" converter="#{imageTypeConvert}">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{syncCenterBean.cRImageTypeList}" var="cRImageType" itemValue="#{cRImageType.imTypeId}" itemLabel="#{cRImageType.imTypeName}" />
</p:selectOneMenu>
</p:column>
</p:row>
...
所有这些都在选择数据表的一行时加载的对话框中。我有两个相关的 Hibernate 实体,如下所示:
CRImageData
@Entity
@Table(name = "imageviewer_crimagedata")
public class CRImageData implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@Column(name = "ImId")
private Long imId;
@Column(name = "ImName")
private String imName;
@Column(name = "ImTypeId")
private Long imTypeId;
@Column(name = "ImPatientId")
private String imPatientId;
@Column(name = "ImStatus")
private String imStatus;
@Column(name = "imFormat")
private String imFormat;
@ManyToOne
@JoinColumn(name="ImTypeId",insertable=false,updatable=false)
private CRImageType cRImageType;
和 CRImageType
@Entity
@Table(name = "imageviewer_crimagetype")
public class CRImageType implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@Column(name = "ImTypeId")
private Long imTypeId;
@Column(name = "ImTypeName")
private String imTypeName;
@Column(name = "ImTypeDescription")
private String imTypeDescription;
@ManyToMany(cascade = {CascadeType.ALL})
@JoinTable(name="imageviewer_imtype_variable",
joinColumns={@JoinColumn(name="ImTypeId")},
inverseJoinColumns={@JoinColumn(name="VarId")})
private Set<CRVariable> crvariables = new HashSet<CRVariable>();
@OneToMany(mappedBy="cRImageType")
private Set<CRImageData> cRImageData;
我为 selectOneMenu 使用以下转换器:
@ViewScoped
@ManagedBean(name = "imageTypeConvert")
@FacesConverter(forClass=CRImageType.class,value="imageTypeConvert")
public class ImageTypeConvert implements Converter {
@ManagedProperty(value="#{syncCenterBean}")
private SyncCenterBean syncCenterBean;
FacesContext context = FacesContext.getCurrentInstance();
SyncCenterBean mybean = (SyncCenterBean) context.getExternalContext().getSessionMap().get("syncCenterBean");
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value{
Long imTypeId = Long.parseLong(value.trim());
List<CRImageType> cRImageTypeList = mybean.getcRImageTypeList();
for (CRImageType cRImageType:cRImageTypeList) {
if(cRImageType.getImTypeId().compareTo(imTypeId)==0){
return cRImageType;
}
}
return null;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
System.out.println("!!!!!! (2) Into getAsString");
return Long.toString(((CRImageType) value).getImTypeId());
}
public SyncCenterBean getSyncCenterBean() {
return syncCenterBean;
}
public void setSyncCenterBean(SyncCenterBean syncCenterBean) {
this.syncCenterBean = syncCenterBean;
}
}
最后是我的 BackBean:
@ManagedBean(name = "syncCenterBean")
@ViewScoped
public class SyncCenterBean implements Serializable {
@PostConstruct
public void init(){
cRImageTypeList = getImageTypesDB();
cRImageType = new CRImageType();
cRImageDataList = populateImageOnlyToDataWarehouseList(getImageDataSOAP());
cRImageDataListLocal = getImageDataDB();
}
...
但是当我尝试加载数据表时,出现以下错误:
javax.portlet.faces.BridgeException: javax.faces.FacesException: com.forth.actions.ImageTypeConvert
at com.liferay.faces.bridge.BridgePhaseRenderImpl.execute(BridgePhaseRenderImpl.java:98)
at com.liferay.faces.bridge.BridgeImpl.doFacesRequest(BridgeImpl.java:99)
...
Caused by: java.io.NotSerializableException: com.forth.actions.ImageTypeConvert
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
at java.util.HashMap.writeObject(HashMap.java:1001)
有什么想法我一直在做错吗?