Hi all,

I'm quite new to Struts2 and so far I love what I see.  Currently I'm having
a problem trying to map a checkboxlist based on a set of enums to a model
object nested in my action.  Here's what I have now:

JSP:


                
                        

                        
                        
                        
                


Action:


public class CreateSimpleFoodAction {
        private FoodService foodService;
        private SimpleFoodCreationRequest foodCreationRequest = new
SimpleFoodCreationRequest();

        public CreateSimpleFoodAction() {
        }

        public String prepareNewSimpleFood() {
                return Action.SUCCESS;
        }

        public String createSimpleFood() {
                String result;

                try {
                        foodService.createSimpleFood(foodCreationRequest);
                        result = Action.SUCCESS;
                }
                catch (FoodException e) {
                        result = Action.INPUT;
                }

                return result;
        }

        public SimpleFoodCreationRequest getModel() {
                return foodCreationRequest;
        }

        public List getAvailableGroups() {
                return Arrays.asList(Group.values());
        }

        public List getAvailableNutrients() {
                return Arrays.asList(Nutrient.values());
        }

        public void setFoodService(FoodService foodService) {
                this.foodService = foodService;
        }
}


Model:


public class SimpleFoodCreationRequest implements SimpleFoodPropertyProvider
{
        private String name;
        private Group group;
        private Set nutrients = new HashSet();

        public SimpleFoodCreationRequest() {
        }

        public Group getGroup() {
                return group;
        }

        public void setGroup(Group group) {
                this.group = group;
        }

        public String getName() {
                return name;
        }

        public void setName(String name) {
                this.name = name;
        }

        public void setSelectedNutrients(Nutrient[] selectedNutrients) {
                nutrients.clear();
                for (Nutrient n : selectedNutrients) {
                        nutrients.add(n);
                }
        }

        public Nutrient[] getSelectedNutrients() {
                return nutrients.toArray(new Nutrient[0]);
        }

        public Set getNutrients() {
                return Collections.unmodifiableSet(nutrients);
        }
}


CreateSimpleFoodAction-conversion.properties:


model.group=com.opensymphony.xwork2.util.EnumTypeConverter
model.selectedNutrients=com.opensymphony.xwork2.util.EnumTypeConverter
Element_model.selectedNutrients=com.gb1.healthcheck.domain.nutrition.Nutrient


When I submit this form, the selected checkbox list items are not mapped to
my SimpleFoodCreationRequest object.  The console shows the standard message
"error setting 'model.selectedNutrients' with..."

Any ideas?

Thanks!
GB

-- 
View this message in context: 
http://www.nabble.com/Mapping-multiple-enums-to-a-nested-object-tf4505238.html#a12848740
Sent from the Struts - User mailing list archive at Nabble.com.

Reply via email to