Hi Adam,

The action has a 
SimpleFoodCreationRequest getModel()
 method which should expose the request object to the JSP.  However you are
right that it doesn't have any setter, but is it really necessary since all
bindings are done on the nested request object?

Thanks,
GB


Adam Hardy-3 wrote:
> 
> Guillaume,
> 
> I don't see a Food getter and setter on your action.
> 
> Guillaume Bilodeau on 23/09/07 18:48, wrote:
>> 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:
>          [s:form action="createSimpleFood.go" method="post"
> namespace="/nutrition"]
>              [s:textfield key="food.name" name="model.name" /][br/]
>              [s:select key="food.group" name="model.group"
> list="availableGroups" /]
>              [s:checkboxlist key="food.nutrients"
> name="model.selectedNutrients"
> list="availableNutrients" /]
>              [s:submit key="nutrition.foods.simpleFoods.create.submit" /]
>          [/s:form]
> 
>> 
>> 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
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

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

Reply via email to