使用PrimeFaces

时间:2017-11-04 14:54:04

标签: jsf primefaces

我已经查看了多个答案,但是当我尝试保存我的角色时,我仍然得到一个Nullpoint。 分数位于连接列中。所以我的selectOneMenu不设置值,所以我现在变量。有人可以帮助我理解我做错了什么。 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         私人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);
}

英雄:

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

分数:

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

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

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

错误代码:

    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)

这个小项目的github是https://github.com/NicklasRohman/Superhero

0 个答案:

没有答案