0

i'm writing a small project for me. It should be able to save some attributes to a database. This is my xhtml snippet:

        <h:outputText value="#{desk_messages.map['label.storeId']}" />
        <p:inputNumber minValue="1"   value="#{boxController.entity.store.id}"/>

My Java Code therefore:

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = Box.FK_STORE, referencedColumnName = "id", nullable = false)
@Index(name = "IDX_Box_Store")
public Store getStore() {
    return this.store;
}

public void setStore(final Store store) {
    this.store = store;

    this.markHashCodeComputationAsNeeded();
}

If i'm executing this, my JBoss throwing the PropertyNotFoundException with the Text: Target Unreachable 'store' returned null. I think it should working, can somebody help me please?

1 Answers1

0

It seems like store is null so you cant access to store.id, try to debug and check the content of your store.

EDIT: Try something like this:

 public void recoverEmptyObjects(){
        if(store == null ) 
          {store = new Store();}
 }
DMC19
  • 627
  • 1
  • 12
  • 30
  • I can't see any variables in the Debug Mode. I dont know why – sportsbettor May 30 '17 at 11:07
  • Which IDE are you using? Try to solve the debug problem searching in Google, then try to see if the store is null. – DMC19 May 30 '17 at 11:14
  • Now it works. But yes the store is null. – sportsbettor May 30 '17 at 11:15
  • That is why you are getting that problem. You can't access to an attribute of a null object. – DMC19 May 30 '17 at 11:17
  • Yes i understand this. But i dont know why it is null. The field has an value in it if i'm trying to save it. – sportsbettor May 30 '17 at 11:20
  • As I can see, you are trying to fill the "id" value of the store, but the store is null. You must initialize your store object and then, you can try to assign a value to the store id. – DMC19 May 30 '17 at 11:25
  • This is not an answer but a comment. – Kukeltje May 30 '17 at 11:27
  • And how i have to do it? sorry but i'm dont know how to do it. I think that i'm already initialized the object store with the get and set methods?! – sportsbettor May 30 '17 at 11:29
  • Check the edit of this answer. Into your object called entity, implement a method who check if the store is null. If store is null, you make a new Store(). Now, you store is not null and you can access to id attribute. – DMC19 May 30 '17 at 11:37
  • Yes, but i think that the set and get methods should already do this, or not? – sportsbettor May 30 '17 at 11:42
  • Check this: https://stackoverflow.com/questions/2036970/how-do-getters-and-setters-work – DMC19 May 30 '17 at 11:47