3
votes

I change setter method return type to an object for ease eg: obj.setValue(newVal).setName(newName).setId(newId);

but after this change tomcat gives

javax.el.PropertyNotFoundException:

    /WEB-INF/flows/materialorder/newOrder.xhtml @99,182 
value="#{materailOrdService.mofEntity.nmExplanation.value}": 
Property 'value' not writable on type tr.com.hydron.softexpert.order.model.MainFormEntity$MofField

To get rid of this exception I changed modifier from private to public but still getting the same error. So I have two questions;

  1. Does jsf need setter for modifying the object even if it's modifier is public?
  2. Does setter method return type have to be void for jsf modifying an object value?

Here is my object class

public static class MofField implements Serializable{

    private static final long serialVersionUID = 1L;
    public Object value;
    ...    


    public Object getValue() {
        return value;
    }
    public MofField setValue(Object value) {
        this.value = value;
        return this;
    }       
    ...     
}

edit: here is my xhtml code:

<p:inputTextarea valueChangeListener="#{materailOrdService.onExplanationChange}"  value="#{materailOrdService.mofEntity.nmExplanation.value}" rows="3" cols="38" >
    <p:ajax event="valueChange" global="false" immediate="true" partialSubmit="true" process="@this"  />
</p:inputTextarea>
1
Changing a property declaration from private to public without its getter method does not make it to be accessed by EL like #{bean.value} because this EL, in this example, refers to the corresponding getter method getValue() and not the field value itself. If you are using input components, you will need both a getter and a setter for a field complying the Java bean specification where a setter method cannot have a return type or otherwise, it cannot be said to be a write-only method.Tiny
This looks like an answer could you please post it as an answerIsmail Sahin
I always leave answers to experts which I am not :)Tiny
@Tiny I don't consider myself an expert at all, but note that answering is a good way to learn. If my answer is incorrect, people will prove me wrong, then that mean I learned something new.Jean-François Savard

1 Answers

5
votes

Does jsf need setter for modifying the object even if it's modifier is public?

Short answer : Yes.

By convention, each field of a Bean should be private and be accessed/mutated by there respective getters and setters.

Changing the field to public won't change anything, as when you type in the field name in your EL code, the server will search for the setFieldName(param) or getFieldName or isFieldName if your field is a boolean.

Does setter method return type have to be void for jsf modifying an object value?

Yes, the server will search void a signature containing void. Try it and see.