2

I have a command object associated with a spring form controller:

public class PluginInstance {
  private Set<PluginParameter> pluginParameters = new HashSet<PluginParameter>();
  ... some other string/long properties and getter setters...
}

the PluginParameter also have a Set in it which contain the values

public class PluginParameter {
  private String parmName;
  private Set<PluginParmvalue> pluginParmvalues = new HashSet<PluginParmvalue>();
  ...some other string/long properties and getter setters...
}

(Normally the pluginParmvalues will contain only one value, a list have been used for future expandability)

In the spring form I binding the values as

<form:input path="pluginParameters[${itemsRow.index}].pluginParmvalues[0].parmValue" />

but the thing is that there can be a form:select(to present multiple predefined options to the user) or form:input (user can input any value). This has to be decided from another object

public class PluginConfigParm {
  private String parmName;
  private ArrayList<String> choices;
  ...getter setters and other properties
}

where I have to compare the name of PluginConfigParm.paramName with PluginParameter.paramName when they match and PluginConfigParm.choices.size() > 0 then form:select will be shown populated with the values from PluginConfigParm.choices otherwise form:input will be shown.

The question is simple: How can I do that. Any help will be highly appreciated.

Muhammad Imran Tariq
  • 22,654
  • 47
  • 125
  • 190
  • Didn't you just ask this question? http://stackoverflow.com/questions/6819616/bind-a-set-in-a-spring-form – matt b Jul 25 '11 at 18:39
  • the problem is same but there are two possible solutions I am thinking, please help me if you understand my problem, I am messing it up badly. – Muhammad Imran Tariq Jul 25 '11 at 18:46

3 Answers3

1

By using List<> instead of Set<> in controller. Problem solved. May be Set<> has no getter/setter that can be bind with spring form.

So <form:input path="pluginParameters[${itemsRow.index}].pluginParmvalues[0].parmValue" /> and List<> in controller makes my life easier.

Muhammad Imran Tariq
  • 22,654
  • 47
  • 125
  • 190
0

The Set is not an indexed collection so I could not work by using this syntax

pluginParameters[${itemsRow.index}].pluginParmvalues[0].parmValue
andrewsi
  • 10,807
  • 132
  • 35
  • 51
0

eg:

class person{
set name<string> = new HashSet<String>()
}


<input type="hidden" path="person.name" name="person.name" value="<%=valueStr%>"/>
take valueStr = "hello, world"

by giving it as comma seperated values.. set works

Its working for me

falsetru
  • 357,413
  • 63
  • 732
  • 636