Lucas ate achei uma solução mas não gostei muito acho que da pra melhorar
@Component
@RequestScoped
public class CustomOgnlParametersProvider extends OgnlParametersProvider {
private final TypeCreator creator;
private final Container container;
private final Converters converters;
private final ParameterNameProvider provider;
private static final Logger logger = LoggerFactory.getLogger(OgnlParametersProvider.class);
private final HttpServletRequest request;
private final EmptyElementsRemoval removal;
public CustomOgnlParametersProvider(TypeCreator creator,
Container container, Converters converters,
ParameterNameProvider provider, HttpServletRequest request,
EmptyElementsRemoval removal) {
super(creator, container, converters, provider, request, removal);
// TODO Auto-generated constructor stub
this.creator = creator;
this.container = container;
this.converters = converters;
this.provider = provider;
this.request = request;
this.removal = removal;
OgnlRuntime.setNullHandler(Object.class, new ReflectionBasedNullHandler());
OgnlRuntime.setPropertyAccessor(List.class, new ListAccessor());
OgnlRuntime.setPropertyAccessor(Object[].class, new ArrayAccessor());
}
@Override
public Object[] getParametersFor(ResourceMethod method, List<Message> errors, ResourceBundle bundle) {
Object root = createRoot(method, errors, bundle);
removal.removeExtraElements();
Type[] types = method.getMethod().getGenericParameterTypes();
Object[] result = new Object[types.length];
String[] names = provider.parameterNamesFor(method.getMethod());
//JVDS
if (method.getMethod().getName().equals("adiciona")) {
names[0] = Util.extractGenericLogic(method.getResource().getType()).toLowerCase();
}
//
for (int i = 0; i < types.length; i++) {
try {
result[i] = root.getClass().getMethod("get" + Info.capitalize(names[i])).invoke(root);
} catch (InvocationTargetException e) {
throw new InvalidParameterException("unable to retrieve values to invoke method", e.getCause());
} catch (Exception e) {
throw new InvalidParameterException("unable to retrieve values to invoke method", e);
}
}
return result;
}
private Object createRoot(ResourceMethod method, List<Message> errors, ResourceBundle bundle) {
return createViaOgnl(method, errors, bundle);
}
private Object createViaOgnl(ResourceMethod method, List<Message> errors, ResourceBundle bundle) {
Class<?> type = creator.typeFor(method);
Object root;
//JVDS
try {
if (method.getMethod().getName().equals("adiciona")) {
root = Class.forName(method.getResource().getType().getName()).getDeclaredConstructor(Result.class,Validator.class,DaoGenerico.class).newInstance(null,null,null);
} else {
root = type.getDeclaredConstructor().newInstance();
}
} catch (Exception ex) {
throw new InvalidParameterException("unable to instantiate type" + type.getName(), ex);
}
//
OgnlContext context = (OgnlContext) Ognl.createDefaultContext(root);
context.setTraceEvaluations(true);
context.put(Container.class, this.container);
VRaptorConvertersAdapter adapter = new VRaptorConvertersAdapter(converters, bundle);
Ognl.setTypeConverter(context, adapter);
for (Enumeration<?> enumeration = request.getParameterNames(); enumeration.hasMoreElements();) {
String key = (String) enumeration.nextElement();
//JVDS
/*
if (method.getMethod().getName().equals("adiciona")) {
key = key.replaceFirst("obj", Util.extractGenericLogic(method.getResource().getType()).toLowerCase());
}
*/
//
String[] values = request.getParameterValues(key);
try {
if (logger.isDebugEnabled()) {
logger.debug("Applying " + key + " with " + Arrays.toString(values));
}
Ognl.setValue(key, context, root, values.length == 1 ? values[0] : values);
} catch (ConversionError ex) {
errors.add(new ValidationMessage(ex.getMessage(), key));
} catch (MethodFailedException e) { // setter threw an exception
Throwable cause = e.getCause();
if (cause.getClass().isAnnotationPresent(ValidationException.class)) {
errors.add(new ValidationMessage(cause.getLocalizedMessage(), key));
} else {
throw new InvalidParameterException("unable to parse expression '" + key + "'", e);
}
} catch (NoSuchPropertyException ex) {
// TODO optimization: be able to ignore or not
if (logger.isDebugEnabled()) {
logger.debug("cant find property for expression {} ignoring", key);
}
if (logger.isTraceEnabled()) {
logger.trace("cant find property for expression " + key + ", ignoring. Reason:", ex);
}
} catch (OgnlException e) {
// TODO it fails when parameter name is not a valid java
// identifier... ignoring by now
if (logger.isDebugEnabled()) {
logger.debug("unable to parse expression '" + key + "'. Ignoring", e);
}
}
}
return root;
}
}
no CadIndexadorController
@Resource
public class CadIndexadorController extends GenericoController<CadIndexador> {
private CadIndexador cadindexador;
public CadIndexadorController(Result result, Validator validator,
DaoGenerico daoGenerico) {
super(result, validator, daoGenerico);
// TODO Auto-generated constructor stub
}
public CadIndexador getCadindexador() {
return cadindexador;
}
public void setCadindexador(CadIndexador cadindexador) {
this.cadindexador = cadindexador;
}
}
mas acho que se na hora que sobe aplicacao ele ja codificava T = CadIndexador ficaria show de bola ai nao precisaria acho eu nem declarar entidade,getter e o setter no controller
Ve se consegue uma ideia bizarra valeu.