Why cdi OWB injection do not works only by servlet url ?
My java beans below.
@WebServlet( urlPatterns = {"/tarifas"})
public class Tarifas extends HttpServlet {
/**
* Atributo '<code>serialVersionUID</code>' do tipo long
*/
private static final long serialVersionUID = 1L;
@javax.inject.Inject
private TarifaBean tarifaBean; -> This injection do not works, when access
by servlet url tarifas
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
try {
tarifaBean.setSession(request.getSession());
request.setAttribute("valorTarifa", tarifaBean.getValorUnitario());
getServletContext().getRequestDispatcher("/WEB-INF/pages/tarifas.jsp").forward(request,
response);
} catch (GrowUpException e) {
throw new ServletException(e);
// getServletContext().getRequestDispatcher("error.jsp").forward(request,
response);
}
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@javax.inject.Named(value="tarifaBean")
@javax.enterprise.context.SessionScoped
public class TarifaBean implements Serializable {
/**
* Atributo '<code>serialVersionUID</code>' do tipo long
*/
private static final long serialVersionUID = 1L;
@javax.inject.Inject
private GrowUpFacadeAdapter facade; -> This injection works fine, when
access by jsf page.
private Double valorUnitario;
public TarifaBean() {}
/**
* @return the valorUnitario
* @throws GrowUpException
*/
public Double getValorUnitario() throws Exception {
if (valorUnitario==null)
valorUnitario = buscarValorPedido();
return valorUnitario;
}
/**
* @return
*/
private Double buscarValorPedido() throws Exception {
VariavelDTO var = (VariavelDTO) facade.executarComando(session,
GCS.MAPA_VARIAVEL,
GCS.BUSCAR_VALOR_UNITARIO);
if (!isCodigoValido(var))
throw new IllegalArgumentException("Não foi possível encontrar o valor
Unitário do pedido.");
return var.getValorAsDouble();
}
}
--
Atenciosamente,
Felipe Pina