RailsSon
RailsSon

Reputation: 20637

JRuby Array to Java Array

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

Upvotes: 2

Views: 2804

Answers (1)

DigitalRoss
DigitalRoss

Reputation: 146221

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
>> 

Upvotes: 3

Related Questions