Name property in #ManagedBean annotation is not available - eclipse

I am trying to make my first JSF application with help of youtube tutorial video. (eclipse/JSF2.0 Dynamic web project). In the first class created, I have to add the below line
#ManagedBean (name = "userRegistration")
But, when I did the same, eclipse shows an error on "name" keyword and giving suggestion to replace it with "value".
#ManagedBean (value = "userRegistration")
But it is not working as expected and threw below error.
/FirstPage.xhtml #10,66 value="#{userRegistration.name}": Target Unreachable, identifier 'userRegistration' resolved to null
Can anyone please help me here?

#ManagedBean(name="userRegistration") is correct. You can avoid (name="userRegistration") part if your java class is UserRegistration. Check if you have imported proper class: java.faces.bean.ManagedBean

Piggy backing on previous answer, I just had this problem as well. Make sure you have the correct import. There are 2 imports that have the #ManagedBean annotation.
javax.annotation.ManagedBean & javax.faces.bean.ManagedBean
javax.annotation.ManagedBean does not have the attribute name, or eager for that matter.
I noticed that if I just annotated my bean class with #annotation that it would import the javax.annotation.ManagedBean class and not the faces one that I wanted.

Related

Eclipse fails to auto-suggest Jackson class

What is causing Eclipse to NOT recognize and consequently not offer any suggestion on an import of JsonParser.Feature as shown in the picture below:
Manually adding the static import of com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_SINGLE_QUOTES (commented in the picture above), however, works fine.
Would it be the case that something is eclipsing the file on the classpath, and if so - what is Eclipse's strategy on resolving those conflicts? Or is it something else?
Thank you in advance.
You cannot use JsonParser class to access Feature since it is not a static member of the class. Instead you can directly use the Feature class :
mapper.configure(Feature.ALLOW_SINGLE_QUOTES, true);
I can suggest 2 workarounds:
Use AutoComplete (Ctrl + Space) to suggest classes:
Add . to class Name (JsonParser.) and then remove it (JsonParser) it will suggest all JsonParser classes:

Ribbon: Unable to set default configuration using #RibbonClients(defaultConfiguration=...)

The #RibbonClients annotation allows us to customise the Ribbon configuration per client. This process is described in the documentation at http://projects.spring.io/spring-cloud/spring-cloud.html#_customizing_the_ribbon_client
This is all fine. I tried to use the same approach to override the default configuration that should be applied to all my clients. So I defined the following configuration class and made sure it is considered by the component scan:
#Configuration
#RibbonClients(defaultConfiguration = MyDefaultRibbonConfig.class)
public class MyRibbonAutoConfiguration {
}
Unfortunately, it turns out that MyDefaultRibbonConfig is not taken into account when building the ribbon client's application context. A quick look and trace at RibbonClientConfigurationRegistrar let me think my #RibbonClients(default=...) annotation is unconditionally overridden by the one provided by org.springframework.cloud.netflix.ribbon.eureka.RibbonEurekaAutoConfiguration.
However, it works if the #RibbonClients annotation is set on a inner class instead of a top-level class:
#Configuration
public class MyRibbonAutoConfiguration {
#Configuration
#RibbonClients(defaultConfiguration = MyDefaultRibbonConfig.class)
static class SubConfig {
}
}
This is a side-effect the strategy followed by RibbonClientConfigurationRegistrar to give a name to the discovered configuration beans:
registerClientConfiguration(registry,
"default." + metadata.getEnclosingClassName(),
attrs.get("defaultConfiguration"));
The configuration for annotations declared on a top-level class are then registered with a bean name set to default.null.defaultConfiguration - so the next one overrides the previous (not sure the order is predictable though).
This behaviour looks strange to me. Did I miss something? Should I proceed differently?
This was an issue in SpringCloud-Netflix 1.0.1. See https://github.com/spring-cloud/spring-cloud-netflix/issues/374 for more information.

StructureMap cannot find GenericRepository

In MVC 2 I am working on something and have ran into a snag. I got my repository put instead of putting in the same class the interface is I have it same project as the EDMX file.
Initializing StructureMap is what's killing me at this point. Here's where I'm initizing StructureMap (in Global.asax.cs.)
ObjectFactory.Initialize(x =>
{
x.ForRequestedType<IUnitOfWorkFactory>()
.TheDefaultIsConcreteType<EFUnitOfWorkFactory>()
.CacheBy(InstanceScope.HttpContext);
x.ForRequestedType(typeof(IRepository<>))
.CacheBy(InstanceScope.HttpContext)
.TheDefaultIsConcreteType(typeof(GenericRepository<>));
});
The Namespace for this project is GpdsCreationTaxidermy.Data (which is the same Namespace as my GenericRepository.cs). I would post the code for this file but I dont believe that is the problem here. In my Global.asax I import the proper Namespace
using GodsCreationTaxidermy.Data;
The error I'm getting is:
Error 3 The type or namespace name
'GenericRepository' could not be found
(are you missing a using directive or
an assembly reference?)
Also attached is an image showing this particular projects layout
Can someone help with this issue, or what I'm doing wrong here
EDIT I have even tried adding GodsCreationTaxidermy.Data to the file name and still no luck.
Thanks for sending the files :-)
It looks like the definition of GodsCreationTaxidermy.Data has changed.
This is what I did to fix the problem:
Remove these references from GodsCreationTaxidermy.Data.Repository Class Library:
GodsCreationTaxidermy.Data
GodsCreationTaxidermy.Data.Repository
Remove these references from GodsCreationTaxidermy.Data Class Library:
GodsCreationTaxidermy
GodsCreationTaxidermy.Data
Remove the reference to GodsCreationTaxidermy.Data in the GodsCreationTaxidermy MVC project and re-add the reference, choosing GodsCreationTaxidermy.Data from the Project tab
Hopefully that'll get the GenericRepository working :-)
I did notice that the following line no longer works though:
EFUnitOfWorkFactory.SetObjectContext(() => new GodsCreationTaxidermyEntities());
GodsCreationTaxidermyEntities doesn't seem to exist in GodsCreationTaxidermy.Data any more. Does that cause you an issue?
Try this:
.TheDefaultIsConcreteType(typeof(GodsCreationTaxidermy.Data.GenericRepository<>));
Possibly remove <> after GenericRepository. Has GodsCreationTaxidermy.Data been added to the MVC site as a reference?

Namespace or type specified in project level imports does not contain a public member

I have an ASP.NET 3.5 web application project in which I'm trying to implement a searchable gridview. I originally started the project as a web site and converted it to a web application. After conversion, my class ended up in the folder Old_App_Code and is called SearchGridView.vb.
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Drawing.Design
<Assembly: TagPrefix("MyApp.WebControls", "SearchGridView")>
Namespace MyApp.WebControls
#Region "TemplateColumn"
Public Class NumberColumn
Implements ITemplate
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
End Sub
End Class
#End Region
<ToolboxData("<{0}:SearchGridView runat=server></{0}:SearchGridView>")> _
<ParseChildren(True, "SearchFilters")> _
Public Class SearchGridView
Inherits GridView
The class file continues, but this is the first part of it.
Unfortunately, I receive the error message
Warning 1 Namespace or type specified in the project-level Imports 'MyApp.WebControls' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases. DielWebProj
In web.config, I included a namespace tag for MyApp.WebControls and I included an imports tag in the .aspx page as well.
Can anyone shed light as to why this error is being raised and how I would remedy it?
Thanks,
Sid
I have a broadly similar problem to you. I have a website project using a custom control, inheriting from GriView, in the app_code folder. I was recieving the very same error, but noted that it happened only after I would add a second class or module to app_code, and would disappear if I removed it.
So the workaround I have at the moment is to just leave my custom control as the sole occupant of app_code.
One option might be to make the control part of its own project and add it as a reference to the we site/app?
I'll update this if I can find a decent solution.
EDIT:
Well, in my case it was because the control I was using was written in C#, whereas the rest of the project, and classes I added to app_code, were in VB.
The app_code folder is compiled to a single assembly, so classes of different languages cannot share it, unless you create seperate sub-folders and do some config file jiggerypokery. More details here

XmlSerializer can't find EntityObject even though its referenced

I hope that someone can help me with this problem that I've been having with XmlSerializer.
I've already looked through this thread: http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/551cee76-fd80-48f8-ac6b-5c22c234fecf/
The error I am getting is:
System.InvalidOperationException: Unable to generate a temporary class (result=1).
error CS0012: The type 'System.Data.Objects.DataClasses.EntityObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
I've made sure that my unit test has a reference to System.Data.Entity, so it is able to compile at least. I've also in the app.config made an assembly binding to System.Data.Entity.
Here's my rough class structure
[Serializable]
[XmlRoot(Namespace = XmlSupport.MyNamespace, ElementName = XmlSupport.WantToSerialize)]
[XmlInclude(typeof(WantToSerializeBaseClass)]
[XmlInclude(typeof(EntityObject)]
[XmlInclude(typeof(MyEntityObjectSubClass)]
public class WantToSerialize : WantToSerializeBaseClass, IXmlSerializable (I've tried putting this on the baseclass and the current class)
{
// methods and classes
// I've included XmlIncludes for all the classes that this class has a reference too
// even though in the WriteXml it just uses .NET base classes
}
The WantToSerializeBaseClass makes use of some generics, but I've decorated it with XmlIncludes for (EntityObject, and any other classes it makes reference to as well).
the calling code:
var serializerWrite = new XmlSerializer(typeof (WantToSerialize), XmlSupport.ITNNamespace);
fails
However if I do:
var serializerWrite = new XmlSerializer(typeof (WantToSerialize), new Type[] {typeof(EntityObject)});
it is succesfull.
Any thoughts would be most helpful.
UPDATED
I've tracked the problem down to a method in the WantToSerializeBaseClass
public abstract void ConvertFromEntity<TtoCopy>(TtoCopy toCopy) where TtoCopy : MyEntityObjectSubClass;
Where MyEntityObjectSubClass is a subclass of EntityObject, that adds a few methods that I want on my entity objects. The MyEntityObjectSubClass looks like this:
[Serializable]
[XmlInclude(typeof(EntityObject))]
public abstract class MyEntityObjectSubClass : EntityObject, IMyEntityObjectSubClass
Again any thoughts would be great
If you don't have any code that requires a reference at compile time then that reference won't be included in the built assembly. You can use a tool like Reflector to check whether the reference is making it into your assembly.
One thing you can try is adding a static method to WantToSerialize that creates the XmlSerializer. The assembly containing WantToSerialize must already have a good reference to EntityObject, so this should solve the problem.
I have this same problem too (in VB). what I found is that you can use the generic parameter, but it errors because the type MyEntityObjectSubClass is in another assembly. If you remove the type restriction on the generic parameter it will work fine.
I believe this to be an error in the framework itself. I've submitted a feedback ticket to microsoft. I attached a VB.net
I ended up removing the generic code and it worked fine.
I realize this is an older question but for posterity's sake set the CopyLocal parameter on the .dll reference to True.