Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- page for insert entity Body that share the id of entity Heart .
- <ui:composition template="/template.xhtml">
- <ui:define name="title">
- <h:outputText value="#{bundle.CreateBodyTitle}"></h:outputText>
- </ui:define>
- <ui:define name="body">
- <h:panelGroup id="messagePanel" layout="block">
- <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
- </h:panelGroup>
- <h:form>
- <h:panelGrid columns="2">
- <h:outputLabel value="#{bundle.CreateBodyLabel_id}" for="id" />
- <h:inputText id="id" value="#{bodyController.selected.id}" title="#{bundle.CreateBodyTitle_id}" />
- <h:outputLabel value="#{bundle.CreateBodyLabel_heart}" for="heart" />
- <h:selectOneMenu id="heart" value="#{bodyController.selected.heart}" title="#{bundle.CreateBodyTitle_heart}" >
- <f:selectItems value="#{heartController.itemsAvailableSelectOne}"/>
- </h:selectOneMenu>
- </h:panelGrid>
- <br />
- <h:commandLink action="#{bodyController.create}" value="#{bundle.CreateBodySaveLink}" />
- <br />
- <br />
- <h:commandLink action="#{bodyController.prepareList}" value="#{bundle.CreateBodyShowAllLink}" immediate="true"/>
- <br />
- <br />
- <h:link outcome="/index" value="#{bundle.CreateBodyIndexLink}"/>
- </h:form>
- </ui:define>
- </ui:composition>
- -------------------------
- i get the following expcetion when hi psush the link createBody
- object is of type java.lang.String; expected type: mauro.entity.Heart
- viewId=/body/Create.xhtml
- location=/home/utente_javaee7/NetBeansProjects/progetti_nuovnetbeans/Study_relations_JPA/build/web/body/Create.xhtml
- phaseId=RENDER_RESPONSE(6)
- Caused by:
- java.lang.IllegalArgumentException - object is of type java.lang.String; expected type: mauro.entity.Heart
- at mauro.jsf.HeartController$HeartControllerConverter.getAsString(HeartController.java:225)
- ------------------------------------------------------------------------------
- the class HeartControllerConverter
- @FacesConverter(forClass = Heart.class)
- public static class HeartControllerConverter implements Converter {
- @Override
- public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
- if (value == null || value.length() == 0|| value.isEmpty()) {
- return null;
- }
- HeartController controller = (HeartController) facesContext.getApplication().getELResolver().
- getValue(facesContext.getELContext(), null, "heartController");
- return controller.ejbFacade.find(getKey(value));
- }
- java.lang.Long getKey(String value) {
- java.lang.Long key;
- key = Long.valueOf(value);
- return key;
- }
- String getStringKey(java.lang.Long value) {
- StringBuilder sb = new StringBuilder();
- sb.append(value);
- return sb.toString();
- }
- @Override
- public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
- if (object == null) {
- return null;
- }
- if (object instanceof Heart) {
- Heart o = (Heart) object;
- return getStringKey(o.getId());
- } else {
- throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + Heart.class.getName());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment