Thanks for helping! Your prompting is very valuable for me.
------------------------------------------------------
-Here is my BackingBean:
------------------------------------------------------
package reportingtool.actions;
import com.sun.jsfcl.app.AbstractPageBean;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.faces.model.SelectItem;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import reportingtool.*;
/**
* This class is primarily intended for automating of processing JSF (JSP) forms &
* values
* @author aburachi
*/
public class SubmitReport extends AbstractPageBean {
private String projectName;
private String projectStatus;
private String week;
private java.sql.Clob repContent;
private String projReportAddNotes;
//the 2 vars highlighted are used in relity
private ArrayList<SelectItem> loggedUserProjects;
private ArrayList<SelectItem> projectStatuses;
private ArrayList<SelectItem> weeks;
public ArrayList<SelectItem> getLoggedUserProjects() {
return loggedUserProjects = extractUserProjectsFromDB();
}
public ArrayList<SelectItem> getProjectStatuses() {
return projectStatuses = extractAllProjectStatusesFromDB();
}
public ArrayList<SelectItem> getWeeks() {
return weeks = extractWeeksFromDB();
}
public void setLoggedUserProjects(ArrayList<SelectItem> loggedUserProjects) {
this.loggedUserProjects = loggedUserProjects;
}
public void setProjectStatuses(ArrayList<SelectItem> projectStatuses) {
this.projectStatuses = projectStatuses;
}
public void setWeeks(ArrayList<SelectItem> weeks) {
this.weeks = weeks;
}
public SubmitReport() {}
public String getProjReportAddNotes() {
return projReportAddNotes;
}
public void setProjReportAddNotes(String projReportAddNotes) {
this.projReportAddNotes = projReportAddNotes;
}
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public String getProjectStatus() {
return projectStatus;
}
public void setProjectStatus(String projectStatus) {
this.projectStatus = projectStatus;
}
public String getWeek() {
return week;
}
public void setWeek(String week) {
this.week = week;
}
public java.sql.Clob getRepContent() {
return repContent;
}
public void setRepContent(java.sql.Clob repContent) {
this.repContent = repContent;
}
public static ArrayList<SelectItem> extractUserProjectsFromDB() {
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
Integer usrIdStoredInSession = (Integer)Contexts.getSession().getAttribute("userID_stored");
List userProjectsList = session.createQuery(
"FROM Project as p where p.user = " + usrIdStoredInSession).
list();
ArrayList<SelectItem> usrProjectsSelItems = new ArrayList<SelectItem>(userProjectsList.size());
for (int i =0; i < userProjectsList.size(); i++) {
usrProjectsSelItems.add( new SelectItem(userProjectsList.get(i)) );
}
return usrProjectsSelItems;
}
public static ArrayList<SelectItem> extractAllProjectStatusesFromDB() {
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
List allProjectStatuses = session.createQuery("FROM ProjectStatus as ps")
.list();
ArrayList<SelectItem> projStatusesSelItems = new ArrayList<SelectItem>(allProjectStatuses.size());
for (int i = 0; i < allProjectStatuses.size(); i++) {
projStatusesSelItems.add( new SelectItem(allProjectStatuses.get(i)) );
}
return projStatusesSelItems;
}
public static ArrayList<SelectItem> extractWeeksFromDB() {
//TODO: consider & implement
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
//get curWeekNumbInYear
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
int aWeek = cal.get(Calendar.WEEK_OF_YEAR);
// currently I extract from DB 2 PREVIOUS weeks => later it should be corrected.
// Here JOIN is needed => check if for current week in WeeklyReport Table
// weekly_rep_send_date is null (it means WeeklyReport, i.e.Email has not
// yet been sent
List weeksList = session.createQuery("FROM Week as w WHERE w.weekId >= '" +
(aWeek - 2) + "' AND w.weekId <= '" + aWeek + "'" ).list();
ArrayList<SelectItem> recentWeeksSelItems = new ArrayList<SelectItem>(weeksList.size());
for (int i = 0; i < weeksList.size(); i++) {
recentWeeksSelItems.add(new SelectItem(weeksList.get(i)) );
}
return recentWeeksSelItems;
}
public String submitReport() {
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
WeeklyProjectReport wProjReport = new WeeklyProjectReport();
wProjReport = _initWeeklyProjectReportInstanceFields(wProjReport);
return "submit_success";
}
/**
* @param projName, extracted from JSF (exacter JSP's) SelectItem element
* @return
*/
public Project getProjectByItsName () {
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
List queriedProj = session.createQuery("FROM Project as p WHERE p.projName = '" +
this.projectName + "'").list();
System.out.println(queriedProj.size());
Project projectInst = (Project)queriedProj.get(0);
return projectInst;
}
/**
* @param projStatusName, extracted from JSF (exacter JSP's) SelectItem element
* @return
*/
public ProjectStatus getProjectStatusByItsName() {
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
List queriedProjStatus = session.createQuery("FROM ProjectStatus as ps WHERE " +
"ps.projStatusName = '" + this.projectStatus + "'").list();
ProjectStatus projectStatusInst = (ProjectStatus)queriedProjStatus.get(0);
return projectStatusInst;
}
public Week getWeekByItsBorders() {
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
List queriedWeek = session.createQuery("FROM Week as w WHERE w.weekId = '" +
DateHelper.getWeekIdByItsBorders(this.week) + "'").list();
Week weekInstance = (Week)queriedWeek.get(0);
return weekInstance;
}
/**
* Method called only before persisting WeeklyProjectReport instance to DB.
* @param wProjReport is instance, who's fields are to be initialized with values
* from JSF forms
*/
private WeeklyProjectReport _initWeeklyProjectReportInstanceFields(WeeklyProjectReport wProjReport) {
wProjReport.setWProjRepContent(repContent);
wProjReport.setWProjRepNotes(projReportAddNotes );
//projectName is contained in JSF form as SelectItem. SelectItems(projectNames)
//are inserted there from DB
wProjReport.setProject( getProjectByItsName());
//same exactly as projectName(see above)
// wProjReport.setProjectStatus( getProjectStatusByItsName());
// wProjReport.setWeek(this.getWeekByItsBorders());
return wProjReport;
}
}
----------------------------------------
-here is my jsp page:
----------------------------------------
<%--
Document : submit1
Created on : 16.08.2009, 19:15:25
Author : aburachi
--%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<f:view>
<html>
<head>
<title>Submitting Your project activities report</title>
</head>
<body>
<h:form>
Project: |
<!--
<option>Gplus Adapter SAP ICI MultiChannel</option>
-->
<!--in JSF instead of mixing Java code with HTML(for JSP) we do the following:-->
<h:selectOneMenu id="projectName" value="#{SubmitReport.projectName}"
styleClass="common-dropdown">
<f:selectItems value="#{SubmitReport.loggedUserProjects}"/>
</h:selectOneMenu>
|
|
|
weekly project status: |
<h:selectOneMenu id="projectStatus" value="#{SubmitReport.projectStatus}"
styleClass="common-dropdown">
<f:selectItems value="#{SubmitReport.projectStatuses}"/>
</h:selectOneMenu>
|
|
|
through: |
<!--
<td>
<%
//reportingtool.DateHelper.getPreviousWeeksStartEndDate()
%>
</td>
-->
<h:selectOneMenu id="week" value="#{SubmitReport.week}">
<f:selectItems value="#{SubmitReport.weeks}"/>
</h:selectOneMenu>
|
|
|
|
|
|
Type in Your report:
<h:inputTextarea id="repContent" value="#{SubmitReport.repContent}" required="true"
styleClass="input" rows="22" cols="75"/>
Additional notes:
<!--textarea rows="5" cols="75" name="ReportAddNotes"></textarea-->
<h:inputTextarea id="projReportAddNotes"
value="#{SubmitReport.projReportAddNotes}" required="true"
styleClass="input" rows="5" cols="75"/>
<h:commandButton value="Submit" id="SubmitCommand" action="#{SubmitReport.submitReport}"
/>
</h:form>
</body>
</html>
</f:view>
-----------------------------------
-and here's part of faces-config.xml:
-------------------------------------
<managed-bean>
<managed-bean-name>SubmitReport</managed-bean-name>
<managed-bean-class>reportingtool.actions.SubmitReport</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
Thank You very much for trying to help me.