I would like implement this call below using CDI OWB. http://wiki4.caucho.com/Java_EE_Servlet/JSP_tutorial:_Building_a_simple_listing_in_JSP
2014-06-13 23:48 GMT-03:00 Felipe Pina <[email protected]>: > 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 > -- Atenciosamente, Felipe Pina
