-
1. Re: Map, new-Operator and In
oguzyalcin.oguzhanyalcin.gazi.edu.tr Mar 20, 2009 9:41 AM (in response to nimo22)Could you please try the code below. Maybe seam tries to create an instance using ...myMap=new Map<String,String>; ...so in this situation it is impossible to create an instance.
@In(required=false, create=true) @Out(required=false) private HashMap<String, String> myMap;
-
2. Re: Map, new-Operator and In
nimo22 Mar 20, 2009 10:13 AM (in response to nimo22)I have tried it with HashMap
@In(required=false, create=true) @Out(required=false) private HashMap<String, String> myMap;
but the same failure occurs:
Caused by: javax.el.PropertyNotFoundException: /mySite.xhtml @111,79 value="#{myMap['test']}": Target Unreachable, identifier 'myMap' resolved to null
I solved it via new-Operator even Seam does not
allow
to use it. -
3. Re: Map, new-Operator and In
buckmin.erdem.agaoglu.gmail.com Mar 20, 2009 10:29 AM (in response to nimo22)First of all, i am not much of a expert but @In(required=false, create=true) seems a little weird. By required=false you tell seam that if there is no var named myMap in any context, then it is not a problem. By create=true you tell seam if there is no var myMap, then it should try to create it.
i don't know the exact order but i think seam tries to create because of create=true but since there is no component definition for "myMap" it cant and gives no problem because of required=false. hence you get el exception.
i often use @Factory for non-javabean non-ejb context variable initialization. so if you have
@Factory("myMap")
public void initMyMap(){
myMap = new HashMap<String, String>();
// population of that map, or whatever
}
or
@Factory("myMap")
public Map<String, String> initMyMap(){
// create map as you'd like or simply
return new HashMap<String, String>();
}
seam will now how to initialize myMap. -
4. Re: Map, new-Operator and In
nimo22 Mar 20, 2009 10:58 AM (in response to nimo22)I have done that also with a Factory all the time (which works), but I wanted to be conform with SEAM which does not
allow
the new-Operator. -
5. Re: Map, new-Operator and In
buckmin.erdem.agaoglu.gmail.com Mar 20, 2009 11:15 AM (in response to nimo22)it only applies to @Name defined javabeans and ejbs. it is not restricted anyway, but if you create them with new-operator, seam is not able to manage them efficiently (you have to @Out them which will probably overwrite any configuration around @Name definition). but since List and Map like objects are not defined anywhere seam provides @Factory and @Unwrap components for that matter. more information.