Hello again, 

I am still trying to implement my dynamic selectModel.

What i did so far is:

TML
<t:select t:id="featureMenu" value="featureValue0"
model="standardFeatureSelectModels.get('0')" />
<t:select t:id="featureMenu2" value="featureValue1"
model="standardFeatureSelectModels.get('1')" />

JAVA

list: standardFeatureSelectModels is 

//this method gets the groups features and generates for them the
selectModels
public List<SelectModel> getStandardProfileFeatureSelectModelsForGroup(Group
group){
   ArrayList <SelectModel> selectModelList = new ArrayList<SelectModel>();
                
   BaseFeature bf;

//dont care about the groups features now, just take two features as
example:
                
  bf = featureService.findBaseFeatureByKey("Age");
  selectModelList.add(featureService.getSelectModelForBaseFeature(bf,
currentLocale));        
                
  bf = featureService.findBaseFeatureByKey("Relationship");
  selectModelList.add(featureService.getSelectModelForBaseFeature(bf,
currentLocale));
                
  return selectModelList;
}

where getSelectModelForBaseFeature is just a method to generate a localized
select model (see at the bottom).

..and this works..  

but there are two things i still need to handle (and I have actually no
clear idea how i could do that)

the list is (should be) dynamic so i need to iterate through
standardFeatureSelectModels.get('0')"  to
standardFeatureSelectModels.get('n')" - i just need to use t:type="Loop" but
as its my first implemenation, i am happy with the
model="standardFeatureSelectModels.get('0')" approach.

things to handle:

i *need to store the selected values*. what i read in the docs is that the
valueEncoder is responsible for that. But, as my optionModel has already the
key, o = new OptionModelImpl(key); i would expect that i dont need a
valueEncoder, right?  all i want to do at the end (onFormSubmit) is to
collect all selected keys and store them. 

as the featureValues are dynamic

value="featureValue0"
value="featureValue1"
and so on

i need to store them into a list / but how can i do that?

is this the right approach?  i hope, that i am clear. 


getSelectModelForBaseFeature method:

        public SelectModel getSelectModelForBaseFeature(BaseFeature bf, Locale
locale){
                List<String> list = bf.getBaseFeatureItemKeysAsList();
                List<OptionModel> optionModels = new ArrayList<OptionModel>();
                
                if (list != null && !list.isEmpty()){
                        for (int i = 0; i < list.size();i++){
                                String key = list.get(i);
                                OptionModel o;
                                if (locale != null){
                                        
                                        BaseFeatureItem item = 
bf.getBaseFeatureItem(key);
                                        
                                        String locKey = 
item.getLocalizedKey(locale.getLanguage());
                                        
                                        if (locKey != null){
                                                o = new OptionModelImpl(locKey, 
key);
                                        }else{
                                                o = new OptionModelImpl(key);
                                        }
                                        
                                                
                                }else {
                                                o = new OptionModelImpl(key);
                                }
                                optionModels.add(o);
                        }
                        
                        return new SelectModelImpl(null, optionModels); 
                }
                return null;
        }



--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Dynamic-OptionModel-Implementation-How-To-tp5719875p5719907.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to