In Eclipse, auto-complete for JSF / EL only works for legacy @ManagedBean
or CDI beans (@Named
), at least when using the JBoss tools plugin.
See also: EL proposals / autocomplete / code assist in Facelets with Eclipse or Eclipse autocomplete (content assist) with facelets (jsf) and xhtml or Content Assist for JSF2 + CDI (weld) beans + Eclipse Helios
=> Summing-up:
- install JBoss tools JSF + CDI (http://download.jboss.org/jbosstools/oxygen/stable/updates/, JBoss Web and Java EE / JBoss Tools JSF + Visual Page Editor + Contexts and Dependency Injection Tools);
- in project properties: remove Project Facets/"JavaServer Faces" so the very slow Eclipse JSF-autocompleter will not be used, activate CDI / CDI support.
But there is no support when using Spring, i.e. @Controller
or @Component
.
Typically, you should use CDI beans with full support for all JSF scopes now, but you may have your reasons or an existing project may use Spring.
See also: Moving JSF Managed Beans to Spring beans or https://www.beyondjava.net/blog/integrate-jsf-2-spring-3-nicely/
So, how to support JSF/EL auto-complete for Spring web beans?
I digged into the JBoss tools implementation and a small change makes Spring users happy.
:-)
There is a solution based on the JSF tools (first) and an alternative based on the CDI tools (afterwards).
The following is based on jbosstools-4.5.2.Final using the plugin file
org.jboss.tools.jsf_3.8.200.v20170908-0911.jar
But the changes should be the same or very similar for other versions (the relevant source files have their last changes back in Dec 2011 or Sept 2012).
The class
org.jboss.tools.jsf.jsf2.bean.model.impl.AbstractMemberDefinition
has to be extended in the methodsgetManagedBeanAnnotation()
andisAnnotationPresent()
:If
@ManagedBean
is not found, then also look for@Controller
(which should be used in Spring, so@Service
etc. is not offered in JSF). But this may easily be adjusted, see comments in the following source. Additionally, Spring uses thevalue
annotation attribute instead ofname
- this is solved via a wrapper class.I offer the two compiled classes (main + one inner class) here for direct download:
AbstractMemberDefinition.class + AbstractMemberDefinition$1.class
I promise a trustworthy compile with just above changes (i.e. without any malicious code or similar, you may check via a decompile with CFR, Procyon, aged JAD or Eclipse-ECD) - you may use them directly or perform the compile by yourself (BTW: Does stack overflow offer file attachments?)
Installation:
eclipse_home\plugins\org.jboss.tools.jsf_3.8.200.v20170908-0911.jar
(e.g. as *.jar_orig).
org.jboss.tools.jsf_3.8.200.v20170908-0911.jar\org\jboss\tools\jsf\jsf2\bean\model\impl
(e.g. via Total Commander or another tool supporting zip/jar handling; you may even use JDKs jar tool). Note: theA...$1.class
is a new file.Go to a JSF page and Type Ctrl+Space after
#{
to get a list of beans. Member auto-completion works, too (after#{beanName.
), even recursive.Even Ctrl+click or F3 on the bean name works!
Note: the first auto-completion call needs some seconds for the initial bean disovery.
BTW: For this, there is no need to activate CDI support for the project! (Build is quicker then because no CDI Builder is active.)
Alternatively, you may extend the JBoss tools CDI feature to discover Spring beans. It works the same and additionally they will be listed with Ctrl+Alt+Z (toolbar button Open CDI Named Bean).
Note: I did not check if there are any side effects if the non-CDI Spring beans are discovered as CDI beans!
For this, the file
org.jboss.tools.cdi.internal.core.impl.definition.AbstractMemberDefinition
has to be extended in the methodgetNamedAnnotation()
:You have to copy the compiled class (download: CDI-AbstractMemberDefinition.class) into
plugins\org.jboss.tools.cdi.core_1.8.201.v20171221-1913.jar\org\jboss\tools\cdi\internal\core\impl\definition
CDI support has to be active for the project.
Maybe someone working for the JBoss tools project may include this in the offical plugin.
Best would be to offer a preferences String, that allows to add arbitrary annotations - maybe even a project specific setting. This would then be a generic solution and no "offical Spring support" which might have political acceptance issues.
See https://issues.jboss.org/browse/JBIDE-25748