javax.el.PropertyNotWritableException: Illegal Syntax for Set Operation

后端 未结 4 848
攒了一身酷
攒了一身酷 2020-11-30 12:33

I\'m making a project to school in JSF and I have few problems with that.

First of all, the h:commandButton doesn\'t work properly when I want to redirect myself to

4条回答
  •  囚心锁ツ
    2020-11-30 12:58

    Look at the stack trace. Here's the most important part:

    Caused by: javax.faces.component.UpdateModelException: javax.el.PropertyNotWritableException: Illegal Syntax for Set Operation
        at javax.faces.component.UIInput.updateModel(UIInput.java:853)
        at javax.faces.component.UIInput.processUpdates(UIInput.java:735)
        at javax.faces.component.UIData.iterate(UIData.java:2001)
        at javax.faces.component.UIData.processUpdates(UIData.java:1253)
        at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
        at javax.faces.component.UIForm.processUpdates(UIForm.java:281)
        at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
        at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:1231)
        at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:78)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        ... 26 more
    

    Read from bottom to top. During update model values phase, JSF is traversing the component tree starting from UIViewRoot component (). In an UIForm component () there is an UIData component () which has an UIInput component () which needs to be processed. The updateModel() basically needs to put the submitted, converted and validated value in the model (the managed bean). However, that operation has failed because the property is not writable (i.e. the setter method cannot be found based on the EL expression syntax).

    Well, let's look at the properties of your components in general.

    
    ...
    
    ...
    
    

    Wait, that's strange. They start all with "get"! This is definitely not normal. JSF is then looking for methods like setGetId(), setGetNazwa(), etc which just doesn't make sense (and you likely also don't have, given this exception). It's expected that they represent concrete property names like "id", "nazwa", "nip", etc and not full method names.

    Thus, so in the model:

    private Long id;
    private String nazwa;
    private String nip;
    
    // Add/generate getters and setters in the following syntax:
    
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    // ...
    

    And so in the view:

    
    ...
    
    ...
    
    

    This is however already covered in a bit sane JSF book/tutorial/resource. Are you absolutely positive that you were reading the right one? Your question also shows that you're using JSF 2.0 in combination with the deprecated JSP view technology instead of its successor Facelets. Start at our JSF wiki page.

提交回复
热议问题