private ViewState createViewState(String viewType, String componentId, ExtendedProperties viewData, EntityManager em, ComponentSpec cs) {
ViewStatePK viewStatePK = new ViewStatePK();
viewStatePK.setComponentId(componentId);
viewStatePK.setViewType(viewType);
ViewState vs = em.find(ViewState.class, viewStatePK);
if (vs == null) {
vs = new ViewState();
vs.setViewStatePK(viewStatePK);
if (cs.getViewStateCollection() == null) {
cs.setViewStateCollection(new ArrayList<ViewState>());
}
cs.getViewStateCollection().add(vs);
}
vs.setViewInfo(generateStringFromView(viewData));
return vs;
}