0

I have looked on multiple answers to this but I still get a Nullpoint when i try to save my character. The fraction is in a joincolumn. So my selectOneMenu don't set the value so mutch I now. Can someone help me understand what I'm doing wrong. index.xhtml:

            <p:outputLabel value="Faction" />
            <p:selectOneMenu id="factionmenu" value="#
            {heroBean.newHero.fraction}" converter="fractionConverter" 
            converterMessage="Fail to Convert" validatorMessage="Fail to 
            validade">
            <f:selectItems value="#{heroBean.fractions}" var="fraction"
            itemLabel="#{fraction.fractionname}" itemValue="#fraction}" />
            </p:selectOneMenu>

HeroBean: @EJB private HeroFacade heroEJB; @EJB private FractionFacade fractionEJB;

    private List<Hero> heros;
    private List<Fraction> fractions;

    Hero newHero;

    public void createNewHero() {
    newHero = new Hero();

    System.out.println("CreateNewHero");
}

public void saveNewHero() {
    System.out.println("trying to make heroEJB");

    heroEJB.create(newHero);
    heros.add(newHero);
}

Hero:

    @ManyToOne
@JoinColumn(name = "fractionid", referencedColumnName = "fractionid", nullable = false)
private Fraction fraction;

Fraction:

    @Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int fractionid;

@Column(name = "fractionname")
private String fractionname;        

@OneToMany(mappedBy="fraction")
private List<Hero> hero;

Error code:

    Caused by: javax.el.PropertyNotFoundException: /index.xhtml @96,149 
    value="#
    {heroBean.newHero.fraction.hero}": Target Unreachable, 'null' returned 
    null at com.sun.faces.facelets.el.TagValueExpression.setValue
    (TagValueExpression.java:133)
   at javax.faces.component.UIInput.updateModel(UIInput.java:832)
   ... 40 more
 Caused by: javax.el.PropertyNotFoundException: Target Unreachable, 'null' 
   returned null
   at com.sun.el.parser.AstValue.getTarget(AstValue.java:192)
   at com.sun.el.parser.AstValue.setValue(AstValue.java:226)
   at com.sun.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:294)
   at org.jboss.weld.el.WeldValueExpression.setValue
   (WeldValueExpression.java:64)
   at com.sun.faces.facelets.el.TagValueExpression.setValue
  (TagValueExpression.java:131)

My github for this small project is https://github.com/NicklasRohman/Superhero

foxyblue
  • 2,859
  • 2
  • 21
  • 29
Rohman
  • 11
  • 3
  • Please post code as an [mcve] inline. See also http://www.stackoverflow.com/tags/jsf/info. And please, please, please post a stacktrace. Otherwise you stand a chance of the question being closed and duplicted as http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it – Kukeltje Nov 04 '17 at 15:04
  • This is not a 'nulpoint'(er exception) but a PropertyNotFound Exception. Post that in google (or in stackoverflow) and search for it. Lots and lots of info. Start by finding out **what** is null... And by tagging it PrimeFaces, you indirectly state it works with a plain jsf `h:selectOneMenu`... Does it? – Kukeltje Nov 04 '17 at 15:19
  • thanks will look in to it. I haven't used plain jsf for this prodject. – Rohman Nov 04 '17 at 15:25
  • No problem not using it, but it helps to narrow things down... – Kukeltje Nov 04 '17 at 15:29

0 Answers0