나는 개찰구를 처음 사용합니다. 나는 2 개의 필드를 가진 students2modules라는 테이블을 가지고 있습니다 : Stud_Username, 학생들을 모듈들과 연결시키는 Module_Code. 특정 모듈을 선택하여 학생을 등록하고 싶습니다. 사용자가 학생을 마련한다 위해 학생이 아직 등록되지 않은 모듈 만 선택하면 다음과 같습니다 이 쿼리는 드롭 다운 메뉴에서 값 대신 Module_Code에 null을 삽입하는 것으로 보입니다.
package myapp.project;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.Model;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
public class AddStud2Mod extends BasePage {
private List students =new ArrayList();
private List modules=new ArrayList();
private ModalWindow message;
private InformationPanel panel;
private DropDownChoice studChoice;
private DropDownChoice moduleChoice;
public AddStud2Mod(){
super();
Form stud2mod = new Form("addstud2mod");
add(stud2mod);
try{
DB db=new DB();
String query="select Stud_Username from students;";
System.out.println(query);
db.connect();
ResultSet rs=db.execSQL(query);
while(rs.next()){
String studentUname=rs.getString("Stud_Username");
students.add(studentUname);
}
db.close();
}
catch(Exception e){
e.printStackTrace();
}
studChoice = new DropDownChoice("studentChoice",new Model(),students);
moduleChoice = new DropDownChoice("modChoice",new Model(),modules);
studChoice.add(new AjaxFormComponentUpdatingBehavior("onchange")
{
@Override
protected void onUpdate(AjaxRequestTarget target)
{
try{
DB db=new DB();
db.connect();
String query="select distinct Module_Code from modules where Module_Code NOT IN(Select Module_Code from students2modules where Stud_Username="+"'"+getUserName()+"');";
System.out.println(query);
ResultSet rs=db.execSQL(query);
while(rs.next()){
String moduleNotRegistered =rs.getString("Module_Code");
modules.add(moduleNotRegistered);
}
moduleChoice.setChoices(modules);
}
catch(Exception e){
e.printStackTrace();
}
target.addComponent(moduleChoice);
}
});
final FeedbackPanel feedback=new FeedbackPanel("msgs");
feedback.setOutputMarkupId(true);
add(feedback);
final InvalidInputIndicator codeLabel = new InvalidInputIndicator("codeLabel",moduleChoice);
codeLabel.setOutputMarkupId(true);
stud2mod.add(codeLabel);
final InvalidInputIndicator studLabel = new InvalidInputIndicator("usernameLabel",studChoice);
studLabel.setOutputMarkupId(true);
stud2mod.add(studLabel);
AjaxButton ok=new AjaxButton("confirm"){
public void onSubmit(AjaxRequestTarget target,Form form){
try{
DB db=new DB();
db.connect();
String query= "Insert into students2modules Values('"+getUserName()+"'"+",'"+moduleChoice.getDefaultModelObjectAsString()+"')";
System.out.println(query);
db.updateSQL(query);
modules.clear();
db.close();
}
catch(Exception e){
e.printStackTrace();
}
InformationPanel.add2ModuleMessage();
message.show(target);
}
protected void onError(AjaxRequestTarget target,Form form){
target.addComponent(feedback);
target.addComponent(studLabel);
target.addComponent(codeLabel);
}
};
stud2mod.add(ok);
Button cancel=new Button("cancel"){
public void onSubmit(){
AddStud2Mod lecturer=new AddStud2Mod();
setResponsePage(lecturer);
}
};
stud2mod.add(cancel);
studChoice.setRequired(false);
studChoice.setOutputMarkupId(true);
moduleChoice.setRequired(false);
moduleChoice.setOutputMarkupId(true);
stud2mod.add(moduleChoice);
stud2mod.add(studChoice);
message=new ModalWindow("InformationDialog");
add(message);
panel=new InformationPanel(message.getContentId(),message);
message.setContent(panel);
message.setCssClassName(ModalWindow.CSS_CLASS_BLUE);
message.setTitle("Important Information");
message.setResizable(false);
message.setInitialHeight(150);
message.setInitialWidth(150);
message.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
public void onClose(AjaxRequestTarget target) {
AddStud2Mod as2mod =new AddStud2Mod();
setResponsePage(as2mod);
}
});
}
private String getUserName(){
return studChoice.getDefaultModelObjectAsString();
}
}
문제 - 더 '는 onSubmit-에 삽입 문입니다'더 Module_Code 위해 삽입받을 것으로 보인다 어떤 모듈 코드가 선택되었는지와 나는 이유를 모른다. 학생 이름은 ok이지만 모듈 코드는 삽입되지 않았습니다. 많은 도움을 주셔서 감사 드리며 큰 코드 덩어리를 유감스럽게 생각합니다 (클래스에 대한 모든 코드를 읽을 수 있도록 포함되어 있습니다).
안녕하세요. 측면 질문 : 당신은 timtabling 관리 시스템을 만들기 위해 노력하고 있습니까? yahoo dot에서 peathal에 연락하여 기존 소프트웨어 또는 Java 프레임 워크 (wicket 대 vaadin)를 선택하는 등의 경험과 정보를 공유하십시오. – Karussell