How to display a custom property using facelet expression language?
For example:
<h:outputText value="#{contact.customTypeProperty}" />
where customTypeProperty is of type CustomClass, and I want to display the String returned by its toString()?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That should already be the default behaviour. You don’t need to change anything on the given code example, assuming that the
toString()method is properly implemented on theCustomClass. However, if it returns HTML, you’d need to addescape="false"to the output text to prevent JSF from auto-escaping it (which it does in order to prevent XSS attacks on user-controlled input):This is however not necessarily the best practice. You should control the presentation in the view side, not in a
toString()in the model side. For example, assuming thatCustomClasshas in turn two propertiesfooandbarand you’d like to present it in a table:If you did this to avoid code repetition, then you should actually be using an include file or a tag file. See also When to use <ui:include>, tag files, composite components and/or custom components?