0

I've seen a lot of examples online of code where a method is called with a "f:ajax" tag but the name of the method gets shortened in the tag when the method name starts with "get". I haven't been able to find the reason for this. Below is an example of what I mean.

For instance, in the xhtml file "sayWelcome" is called:

...
<h:commandButton value="Welcome Me">
    <f:ajax execute="name" render="output" />
</h:commandButton>
<h:outputText id="output" value="#{helloBean.sayWelcome}" />
...

but the method in the bean is called "getSayWelcome":

public String getSayWelcome(){
       return  name;
}

Why does the "get" get dropped from the method name in the "f:ajax" tag?

1 Answer 1

1

The JavaBeansSpecification defines the naming convention for the properties adding the get and set before the functions that acts as properties, see this article for more info.

The expression language that use JSF also complains the JavaBeans properties name convention you can check this in this article, refer to the Referring to Object Properties Using Value Expressions section.

So in conclusion when the EL (Expression language) finds a sentence as <h:outputText id="output" value="#{helloBean.sayWelcome}" /> it will try to call a getter or the setter function for the sayWelcome property, it depends if it need to assign the value (setter) or get the value (getter).

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you @César-Loachamin, that's the info I was looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.