tags:

views:

396

answers:

1

Hi, I'm new to JBoss Seam. I'd like to know how do I instantiate a class without a no-arg constructor in JBoss Seam.

I have to instantiate JsonPrimitive (from Google Gson framework) that has just constructors which receive arguments.

How the regular code would be:

import com.google.gson.JsonPrimitive;
...
JsonPrimitive jsonPrimitive = new JsonPrimitive(myobject.toString())

Trying to transport the code to Seam:

import com.google.gson.JsonPrimitive;
..
@In(create=true)
JsonPrimitive jsonPrimitive

But this kind of thing in Seam(shown above) will not help me. I have to pass an argument in the constructor to instantiate the class.

How could I tell Seam to use an argument in the constructor when instantiating an object to be injected?

Thanks!

A: 

You should be able to use the factory annotation:

@Factory("jsonPrimitive")
public void loadJsonPrimitive()
{
    jsonPrimitive = new JsonPrimitive(myobject.toString())
}

See the Seam documentation for @Factory

mtpettyp
Also look at @UnWrap
Damo