views:

165

answers:

1

Hey,

I am making a site in JRuby on Rails, I am using some Java classes as well.

I have a select form element which passes user selections to the controller.

The selections are passed like so:

Parameters: {"options"=>["Option One", "Option Two"]}

The Java method that I am using requires the options selected to be a String[] (Java String Array?)

I have tried using:

params[:options].to_java(:string)

This does not seem to work. Can someone point out what I am doing wrong and what I need to do convert the options to a Java String Array?

Thanks

Eef

+1  A: 

params[:options] is a different key from params["options"], perhaps you really want params["options"]?

With that change, your code seems to work in jirb:

$ jirb --simple-prompt
>>  {"options"=>["Option One", "Option Two"]}["options"].to_java :string
=> [Ljava.lang.String;@107f742
>>
DigitalRoss
when you hit the submit button I have generally accessed anything passed to the controller with params, params[:options], I will your solution a try, thanks.
Eef