Hi,
I just started developing with JBoss AS 7 and EJB and I wasn't sure if I should put this question in the beginners corner. If that would be better, maybe somebody can move it there.
I created an Entity-Bean 'Auction' which contains some String-fields and two fields that contain entities too.
@Named @Entity public class Auction { @Id @GeneratedValue private Long id; @ManyToOne private User creator; @ManyToOne private Town town; private String mandatory; private String optional;
// getters and setters...
Now I want to create a new Auction-Bean and persist it, but I always get a NullPointerException.
Here the Frontendcode:
<h:selectOneListbox id="name" value="#{newAuction.creator.id}" size="1">
<f:selectItems var="item" itemLabel="#{item.name}" itemValue="#{item.id}" value="#{userManager.users}" />
</h:selectOneListbox>
<h:selectOneListbox id="town" value="#{newAuction.town.id}" size="1">
<f:selectItems var="item" itemLabel="#{item.name}" itemValue="#{item.id}" value="#{townManager.towns}" />
</h:selectOneListbox>
<h:inputText
id="mandatory"
value="#{newAuction.mandatory}" />
<h:inputText
id="optional"
value="#{newAuction.optional}" />
<h:commandButton
id="register"
action="#{auctionManager.addAuction()}"
value="Register" />
But now I get an Exception like this:
value="#{newAuction.creator.id}": Target Unreachable, 'creator' returned null
I do understand that the field 'creator' is not initialized when I try to set the id, but how do I do it then? I just want to put the Bean that's already initialised (for showing the combo-box) in there.
It's kinda hard to google this stuff, I tried
any help is really appreciated.
Thanks, Mati