J
jill
Hi All,
I am newbie to Struts.
I am writing a simple application, in which in the JSP page, if I use
bean in scripplet it works fine. For example <%=
courseBean.getCourseName%> works fine and gives me result.
If I replace this pice of code with bean write or html: text nothing
comes.
I have tried putting bean in session, used bean:define tag but nothing
works.
Here is my example code
Struts Config File
<action path="/modifyCourse"
type="com.nyiso.lc.admin.ModifyCourseAction" name="courseFormBean"
scope="request">
<forward name="success" path="/public-html/modifyCourse.jsp" />
</action>
JSP Code - modifyCourse.jsp
<%@ page import="com.nyiso.lc.admin.LCConstants,
com.nyiso.lc.admin.CourseTypeBean,
com.nyiso.lc.admin.CourseBean,com.nyiso.lc.silverln.LCDAO,
java.util.ArrayList" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ include file = "header.html" %>
<%@ include file = "menu.jsp" %>
<table>
<tr>
<td class="title2"><BR>Course Editor</td>
</tr>
</table>
<bean:define id="courseBean1" name="courseBean" toScope="session"
type="com.nyiso.lc.CourseBean"//>
<html:form action="maintainCourse.do?action=<%=LCDAO.UPDATE_STP%>"
focus="courseName" >
<TABLE CELLPADDING="2" CELLSPACING="2" BORDER="0">
<TR>
<TD CLASS="paragraphbold" ALIGN="Right">Course Name</TD>
<TD CLASS="paragraph">
<INPUT TYPE="hidden" NAME="courseID" SIZE="30" CLASS="paragraph"
value="">
<html:text property="courseName" size="30" maxlength="100"/>
<bean:write name="courseBean1" property="courseName"/>
<bean:write name="courseBean1" property="CourseName"/>
</TD>
</TR>
</html:form>
<%@ include file = "footer.html" %>
public class ModifyCourseAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
HttpSession session = request.getSession();
CourseFormBean courseFormBean = (CourseFormBean) form;
if(session.getAttribute(Constants.DATA_SOURCE) == null){
SilverDB mySilverDB = new SilverDB();
session.setAttribute(Constants.DATA_SOURCE, mySilverDB);
}
CourseTypeDAO courseTypeDAO = new CourseTypeDAO(request);
ArrayList arrCourseTypeBean =
(ArrayList)courseTypeDAO.hydrate(LCDAO.SELECT_ALL_STP, null);
request.setAttribute(LCConstants.ARRAY_COURSE_TYPE_BEAN,
arrCourseTypeBean);
CourseDAO courseDAO = new CourseDAO(request);
CourseBean courseBean = (CourseBean)
courseDAO.hydrate(LCDAO.SELECT_SINGLE_STP, courseFormBean);
session.setAttribute("courseBean", courseBean);
return (mapping.findForward(LCConstants.ACTION_SUCCESS));
}
}
I don't know why my course Bean using tags is empty and if I use
request.getAttribute and then use coursebean.get..., gives me value.
What am I missing.
Any help is very much appreciated.
Thanks,
Jill.
I am newbie to Struts.
I am writing a simple application, in which in the JSP page, if I use
bean in scripplet it works fine. For example <%=
courseBean.getCourseName%> works fine and gives me result.
If I replace this pice of code with bean write or html: text nothing
comes.
I have tried putting bean in session, used bean:define tag but nothing
works.
Here is my example code
Struts Config File
<action path="/modifyCourse"
type="com.nyiso.lc.admin.ModifyCourseAction" name="courseFormBean"
scope="request">
<forward name="success" path="/public-html/modifyCourse.jsp" />
</action>
JSP Code - modifyCourse.jsp
<%@ page import="com.nyiso.lc.admin.LCConstants,
com.nyiso.lc.admin.CourseTypeBean,
com.nyiso.lc.admin.CourseBean,com.nyiso.lc.silverln.LCDAO,
java.util.ArrayList" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ include file = "header.html" %>
<%@ include file = "menu.jsp" %>
<table>
<tr>
<td class="title2"><BR>Course Editor</td>
</tr>
</table>
<bean:define id="courseBean1" name="courseBean" toScope="session"
type="com.nyiso.lc.CourseBean"//>
<html:form action="maintainCourse.do?action=<%=LCDAO.UPDATE_STP%>"
focus="courseName" >
<TABLE CELLPADDING="2" CELLSPACING="2" BORDER="0">
<TR>
<TD CLASS="paragraphbold" ALIGN="Right">Course Name</TD>
<TD CLASS="paragraph">
<INPUT TYPE="hidden" NAME="courseID" SIZE="30" CLASS="paragraph"
value="">
<html:text property="courseName" size="30" maxlength="100"/>
<bean:write name="courseBean1" property="courseName"/>
<bean:write name="courseBean1" property="CourseName"/>
</TD>
</TR>
</html:form>
<%@ include file = "footer.html" %>
public class ModifyCourseAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
HttpSession session = request.getSession();
CourseFormBean courseFormBean = (CourseFormBean) form;
if(session.getAttribute(Constants.DATA_SOURCE) == null){
SilverDB mySilverDB = new SilverDB();
session.setAttribute(Constants.DATA_SOURCE, mySilverDB);
}
CourseTypeDAO courseTypeDAO = new CourseTypeDAO(request);
ArrayList arrCourseTypeBean =
(ArrayList)courseTypeDAO.hydrate(LCDAO.SELECT_ALL_STP, null);
request.setAttribute(LCConstants.ARRAY_COURSE_TYPE_BEAN,
arrCourseTypeBean);
CourseDAO courseDAO = new CourseDAO(request);
CourseBean courseBean = (CourseBean)
courseDAO.hydrate(LCDAO.SELECT_SINGLE_STP, courseFormBean);
session.setAttribute("courseBean", courseBean);
return (mapping.findForward(LCConstants.ACTION_SUCCESS));
}
}
I don't know why my course Bean using tags is empty and if I use
request.getAttribute and then use coursebean.get..., gives me value.
What am I missing.
Any help is very much appreciated.
Thanks,
Jill.