I am able to get the current page’s url in jsf from back-end bean using HttpServletRequest. But is there a way to get the current page’s title also?
Share
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.
No, that’s not directly possible. It only appears in flavor of a HTML
<title>tag in the HTTP response associated with the HTTP request. You could theoretically parse the view file using a XML parser and extract the<title>element from it, but that’s plain clumsy.Better do it the other way round. Variables which are of interest for the controller belongs in the model anyway, not (hardcoded) in the view. Make title a property of the model and display it in EL like so:
You could have a mapping of pages based on their URL, or better, their JSF view ID which has the syntax
/path/filename.xhtml. If you hold them in aMap<String, Page>, then you should be able to get the page’s title as follows