-1

You are analyzing the Facelets code of a very large JSF web application written by others (e.g. during a production incident) and you want to find the bean class that is implementing a bean, knowing its name as it comes in EL expression.

You didn't write it and the bean's name does not match any Java class in the project.

You can't assume that the class is annotated.

While there are several methods to reach to the same result, I hope this question can document the best practices to solve this problem.

NOTE: This question is not about how to enable an IDE option to do so, it is about how to deal with it, without IDE support. I have made many searches and haven't found this question in StackOverflow, in the terms expressed here.

  • What jsf version? Are you using xml or annotation based config? – Nicholas Hirras Feb 04 '18 at 13:19
  • Java EE 7, JSF 2, PF 6 – Jose Manuel Gomez Alvarez Feb 04 '18 at 13:31
  • Related to question https://stackoverflow.com/questions/19152239/when-should-you-explicity-name-a-managed-bean – Jose Manuel Gomez Alvarez Feb 04 '18 at 13:32
  • I found the class but it is not annotated... I stopped working on this project for nearly a year. But I wanted to keep this question as generic as possible, not to resolve this particular situation. In this particular situation, the XHTML refers to {msg...} and found that msg is a ResourceBundle. – Jose Manuel Gomez Alvarez Feb 04 '18 at 13:35
  • Regarding your 'note', it was totally was totally not clear to me you want to do this without an IDE!. And why on earth (and beyond) would you want to do it without an IDE??? And are you seriously going to change the running xhtml in a production environment just for this??? Weird... Sorry... – Kukeltje Feb 04 '18 at 16:41
  • It's not about why to do it without an IDE. It's about knowing how many ways are there to find an implementation class behind a bean name. The solution that I have provided is platform-independent and IDE-independent. I don't see any relationship between my original question and the "exact duplicate" referenced. – Jose Manuel Gomez Alvarez Feb 04 '18 at 19:00
  • No serious developer would do this without an IDE so your endeavour is sort of a not very useful one. And if your motivation is that it is platform independent, well, I have no idea what plarform independent is in this case (does it work on C# too?), and regarding the IDE independence, all 3 major java IDE's have code completion for this... In the end this is not a JSF problem (if you have jsp and spring beans it very identical but not 100%... still very surprised) – Kukeltje Feb 04 '18 at 19:58
  • I disagree. A serious developer needs to know how things work and not to rely blindly on IDE capacities that magically do your work! The IDE is just a tool, normally it is not installed on a server, and sometimes a support team may not even have the development environment installed and working. You have just an EAR file on a unix workstation. And you are reading logs and viewing source code with vi. – Jose Manuel Gomez Alvarez Feb 04 '18 at 22:48
  • There is a difference between **knowing** and **doing**. And I nowhere stated a dev should rely blindly on an IDE. And if a 'support team' does not have an IDE, they should refrain from editing files in the first place. At least not for fundamental things like this. – Kukeltje Feb 05 '18 at 09:23
  • So this question is about **knowing** how to find out the EJB class behind an EL expression. And if possible, without installing IDE nor editing files and redeploying code. You may not like the question but I think it is a useful one. – Jose Manuel Gomez Alvarez Feb 05 '18 at 09:31

1 Answers1

0

Print it!

(-) Requires to redeploy.

  • Edit the XHTML file to write out the class' name

<!-- #{msg.getClass().getSimpleName()} -->  
  • Redeploy the modified XHTML file

  • Reload the page

Look for Annotations

(-) Not always works

  • Search for the annotation ("@ManagedBean") across the workspace and find the annotation.

Look in Face-Config

  • Search in faces-config.xml (e.g. ResourceBundles)

IDE Support

  • Try using a good 'IDE' and do a 'find references from the xhtml page. – Kukeltje Feb 04 '18 at 14:14
  • Such as? Eclipse for instance does not seem to be able to do so. Imagine you are in charge of implementing such a feature... what would be the procedure to come up with the implementation class? – Jose Manuel Gomez Alvarez Feb 04 '18 at 14:38
  • If I rember correctly Eclipse with JBoss Tools does... Maybe give it a try. It can for sure do code-completion as the duplicate points out. – Kukeltje Feb 04 '18 at 16:11
  • As explained above, it's a question about JSF not about IDEs. – Jose Manuel Gomez Alvarez Feb 04 '18 at 19:02
  • You might be of the opinion it is a JSF issue but in my opinion it is not. In the xhtml you use EL that might resolve into many other things (CDI, EJB, Spring, whatever). So that and things that 'do not always work' are sort of unreliable and hence not a 'solution'. The downvote is not by me but I am inclined to downvote as well. Good luck finding other additional things that help to get a full picture... – Kukeltje Feb 04 '18 at 19:50
  • Well, it seems that, at the end, my guess was right and there isn't a straight-forward way to determine the bean class. I appreciate your feedback. – Jose Manuel Gomez Alvarez Feb 04 '18 at 22:59