Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accepting java parameters on controllers without conversion to java.lang.String #13

Merged
merged 1 commit into from
Dec 7, 2012
Merged

Accepting java parameters on controllers without conversion to java.lang.String #13

merged 1 commit into from
Dec 7, 2012

Conversation

gregoriokusowski
Copy link
Contributor

By checking the parent of each instance variable class on the controller, we can
be sure if it's a Rjb::Rjb_JavaClass or Rjb::Rjb_JavaProxy instance.
Example cases like Rjb::Java_lang_String or Rjb::Java_util_HashMap will also be
as they are.
I'm not sure if we can receive a Rjb::Rjb_JavaBridge, but it will work too.

The example present on the specs shows how java parameters can be used.

    title = (Rjb::import 'java.lang.String').new("The Beatles")
    @parameter_that_is_a_java_class = (Rjb::import 'java.util.HashMap').new
    @parameter_that_is_a_java_class.put("title", title)
<parameter name="parameter_that_is_a_java_class" class="java.util.Map"/>
...
<textFieldExpression><![CDATA[$P{parameter_that_is_a_java_class}.get("title")]]></textFieldExpression>

I chose to not convert every Hash to a java.util.HashMap because it can grow up easily if we use a recursive approach. I'll add later a snippet to the wiki or readme with a simple conversion tool.
Improvements and suggestions will be appreciated.

…ang.String.

By checking the parent of each instance variable class on the controller, we can
be sure if it's a Rjb::Rjb_JavaClass or Rjb::Rjb_JavaProxy instance.
Example cases like Rjb::Java_lang_String or Rjb::Java_util_HashMap will also be
as they are.
I'm not sure if we can receive a Rjb::Rjb_JavaBridge, but it will work too.
msaraiva added a commit that referenced this pull request Dec 7, 2012
…eters

Accepting java parameters on controllers without conversion to java.lang.String
@msaraiva msaraiva merged commit acd4161 into fortesinformatica:master Dec 7, 2012
@msaraiva
Copy link
Contributor

msaraiva commented Dec 7, 2012

This solves issue #12.

Thanks Kusowski!

@plentz
Copy link
Contributor

plentz commented Dec 7, 2012

I was talking with @gregoriokusowski earlier today and we discussed that this isn't really the best solution for the user. we thought in iterating over all controller's instance variables(ignoring those with @_ since it's used by rails[1] - something like what is done here), and checking class types - if it's an array or an hash, we convert to java's corresponding type, everything else is passed as a string(as it's done today). that way, the user will be able to use

@my_hash = {baz: "zinga!"}
@my_array = ["A","B","C", "easy as", 1, 2, 3, "or simple as", "do re mi"]

which we think is way better then the solution explained in the initial post. what you guys think? cc @msaraiva @rodrigomaia

[1]

1.9.3p327 :002 > x = FooController.new
1.9.3p327 :003 > x.instance_variables
 => [:@_routes, :@_action_has_layout, :@_headers, :@_status, :@_request, :@_response]

@msaraiva
Copy link
Contributor

msaraiva commented Dec 7, 2012

I don't like the idea of having any Java related code in the controllers. I will probably not use it. But the feature itself is nice. Whatever solution we find to convert the data from ruby to java must face the problem of recursion and custom types. So I agree we should have a solution that convert arrays and hashes automatically (we just need to define how deep in the structure). That will cover the 95% of all the use. However, we can keep the current solution in case the user find himself among the other 5%.
It sounds reasonable. Right?

@plentz
Copy link
Contributor

plentz commented Dec 25, 2012

@msaraiva 100% agree. So we try to do our best converting ruby objects to java and if we can't the user still have the workaround.

About the deepness, any suggestion? I can't imagine a case where we can't go all the way in all the levels that the object have, since we're going to do it just in the current controller instance variables. Am I right?

@ionosphere
Copy link

Hi, do you ever have this case ?

Work*
*
def index
@animal = Animal.all
respond_with @animal

end

*Don't Work

def index
@animal = Animal.all

respond_to do |format|
format.xml { render xml: @animal, :include => [ :father , :mother,
:race] }
format.pdf { render pdf: @animal }
format.html
end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants