Guest User

Untitled

a guest
Jan 16th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. page for insert entity Body that share the id of entity Heart .
  2.  
  3. <ui:composition template="/template.xhtml">
  4. <ui:define name="title">
  5. <h:outputText value="#{bundle.CreateBodyTitle}"></h:outputText>
  6. </ui:define>
  7. <ui:define name="body">
  8. <h:panelGroup id="messagePanel" layout="block">
  9. <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
  10. </h:panelGroup>
  11. <h:form>
  12. <h:panelGrid columns="2">
  13. <h:outputLabel value="#{bundle.CreateBodyLabel_id}" for="id" />
  14. <h:inputText id="id" value="#{bodyController.selected.id}" title="#{bundle.CreateBodyTitle_id}" />
  15. <h:outputLabel value="#{bundle.CreateBodyLabel_heart}" for="heart" />
  16. <h:selectOneMenu id="heart" value="#{bodyController.selected.heart}" title="#{bundle.CreateBodyTitle_heart}" >
  17. <f:selectItems value="#{heartController.itemsAvailableSelectOne}"/>
  18. </h:selectOneMenu>
  19. </h:panelGrid>
  20. <br />
  21. <h:commandLink action="#{bodyController.create}" value="#{bundle.CreateBodySaveLink}" />
  22. <br />
  23. <br />
  24. <h:commandLink action="#{bodyController.prepareList}" value="#{bundle.CreateBodyShowAllLink}" immediate="true"/>
  25. <br />
  26. <br />
  27. <h:link outcome="/index" value="#{bundle.CreateBodyIndexLink}"/>
  28. </h:form>
  29. </ui:define>
  30. </ui:composition>
  31.  
  32. -------------------------
  33.  
  34. i get the following expcetion when hi psush the link createBody
  35.  
  36. object is of type java.lang.String; expected type: mauro.entity.Heart
  37.  
  38. viewId=/body/Create.xhtml
  39. location=/home/utente_javaee7/NetBeansProjects/progetti_nuovnetbeans/Study_relations_JPA/build/web/body/Create.xhtml
  40. phaseId=RENDER_RESPONSE(6)
  41.  
  42. Caused by:
  43. java.lang.IllegalArgumentException - object is of type java.lang.String; expected type: mauro.entity.Heart
  44. at mauro.jsf.HeartController$HeartControllerConverter.getAsString(HeartController.java:225)
  45.  
  46.  
  47. ------------------------------------------------------------------------------
  48.  
  49. the class HeartControllerConverter
  50.  
  51. @FacesConverter(forClass = Heart.class)
  52. public static class HeartControllerConverter implements Converter {
  53.  
  54. @Override
  55. public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
  56. if (value == null || value.length() == 0|| value.isEmpty()) {
  57. return null;
  58. }
  59. HeartController controller = (HeartController) facesContext.getApplication().getELResolver().
  60. getValue(facesContext.getELContext(), null, "heartController");
  61. return controller.ejbFacade.find(getKey(value));
  62. }
  63.  
  64. java.lang.Long getKey(String value) {
  65. java.lang.Long key;
  66. key = Long.valueOf(value);
  67. return key;
  68. }
  69.  
  70. String getStringKey(java.lang.Long value) {
  71. StringBuilder sb = new StringBuilder();
  72. sb.append(value);
  73. return sb.toString();
  74. }
  75.  
  76. @Override
  77. public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
  78. if (object == null) {
  79. return null;
  80. }
  81. if (object instanceof Heart) {
  82. Heart o = (Heart) object;
  83. return getStringKey(o.getId());
  84. } else {
  85. throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + Heart.class.getName());
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment