Po ta retornando NULL…
Não consigo gravar no banco o id_alunos e id_projetos…
Quando eu coloco na mão o id_alunos ele grava, o getId_alunos que está retornando null!
[code]type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
br.com.scb.dao.ProjetosDAO.adiciona(ProjetosDAO.java:76)
br.com.scb.action.CadastraProjetosAction.execute(CadastraProjetosAction.java:24)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255)
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:510)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
[/code]
JSP
[code]<%@ page language=“java” contentType=“text/html; charset=UTF-8” pageEncoding=“UTF-8”%>
<%@ taglib uri="/struts-tags" prefix=“s” %>
<%@ taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core” %>
<%@ taglib prefix=“fmt” uri=“http://java.sun.com/jsp/jstl/fmt” %>
SCB - Painel de Administração
<%@ include file="header.jsp" %>
<%@ include file=“top.jsp” %>
<%@ include file="menu.jsp" %>
<!--MELHORAR A VALIDAÇÃO AQUI-->
<div class="success message">
<s:if test="hasActionMessages()">
<s:actionmessage/>
</s:if>
</div>
<jsp:useBean id="dao" class="br.com.scb.dao.ProfessoresDAO" />
<jsp:useBean id="dao_alunos" class="br.com.scb.dao.AlunosDAO" />
<!-- Content -->
<div class="content">
<div class="title"><h5>Projetos</h5></div>
<div class="widget first">
<div class="head"><h5 class="iList">Cadastrar Projetos</h5></div>
<div class="rowElem dualBoxes">
<h6>Componentes do Projeto</h6><br />
<div class="floatleft w40">
<s:form action="cadastraProjetos" method="post" id="valid" styleClass="mainForm">
<s:select id="box1View" cssClass="multiple" cssStyle="height:200px;" list="%{#attr.dao_alunos.lista}" listKey="id_alunos" listValue="nome" name="id_alunos" multiple="true" size="%{#attr.dao_aluno.lista.size()}"></s:select>
<s:submit value="Cadastrar" styleClass="basicBtn submitForm mb22"></s:submit>
</s:form>
<br/>
</div>
<div class="fix"></div>
</div>
<!--FIM COMPONENTE-->
<!--input type="submit" value="Cadastrar" class="basicBtn submitForm mb22" / -->
<div class="fix"></div>
</div>
</div>
<div class="fix"></div>
<%@ include file=“footer.jsp” %>
[/code]
Quando exibo o html a parte do form está assim:
<div class="floatleft w40">
<form id="valid" name="valid" action="/scb/cadastraProjetos.action" method="post" styleClass="mainForm">
<table class="wwFormTable">
<tr>
<td class="tdLabel"></td>
<td
><select name="id_alunos" size="2" id="box1View" class="multiple" style="height:200px;" multiple="multiple">
<option value="15">Thiago</option>
<option value="16">Andrei Ribeiro</option>
</select>
<input type="hidden" id="__multiselect_box1View" name="__multiselect_id_alunos" value="" />
</td>
</tr>
<tr>
<td colspan="2"><div align="right"><input type="submit" id="valid_0" value="Cadastrar" styleClass="basicBtn submitForm mb22"/>
</div></td>
</tr>
</table></form>
<br/>
</div>
CadastraProjetosAction.java
package br.com.scb.action;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import com.opensymphony.xwork2.ActionSupport;
//import br.com.scb.modelo.Projetos;
import br.com.scb.modelo.Componentes;
import br.com.scb.dao.ProjetosDAO;
public class CadastraProjetosAction extends ActionSupport {
private static final long serialVersionUID = -5817485575269317513L;
private Componentes componentes;
@Action( value="cadastraProjetos", results = {
@Result(name="ok", location="/cadastrar-projetos.jsp")
})
public String execute(){
new ProjetosDAO().adiciona(componentes);
addActionMessage("Projeto cadastrado com sucesso!");
return "ok";
}
public Componentes getComponentes() {
return componentes;
}
public void setComponentes(Componentes componentes) {
this.componentes = componentes;
}
}
ProjetosDAO.java
[code]package br.com.scb.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import br.com.scb.jdbc.ConnectionFactory;
import br.com.scb.modelo.Componentes;
import br.com.scb.modelo.Projetos;
public class ProjetosDAO {
private final Connection connection;
public ProjetosDAO(){
connection = new ConnectionFactory().getConnection();
}
//ADICIONAR Projetos
public void adiciona(Componentes componentes) {
String sql = "INSERT INTO componentes_projetos (id_alunos, id_projetos) values (?,?)";
PreparedStatement stmt;
//Projetos projetos = new Projetos();
try {
stmt = connection.prepareStatement(sql);
stmt.setInt(1, componentes.getId_alunos());
stmt.setInt(2, 1);
stmt.execute();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
[/code]