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.
cbroussard@liquiddatainc.com - 14 Dec 2005 23:18 GMT
Looks like your courseBean & courseBeanForm isn't in sync.
try to have your courseBeanForm.setCourseBean(courseBean);
then you should have the bean:write & html:text property exposable to
your courseBean.
assuming you have
setCourseBean(CourseBean v){
courseBean = v;
}
String getCourseNumber(){
return courseBean.getCourseNumber();
}
or whatever... hopefully this helps.
http://www.binaryfrost.com
> Hi All,
>
[quoted text clipped - 96 lines]
> Thanks,
> Jill.
jill - 15 Dec 2005 14:23 GMT
Thanks cbroussard for your reply.
I am not doing what you said. I don't have setCourseBean in my
courseBeanForm. I will try that.
But one weird thing happened yesterday evening, I restarted my server
and my code started working. So the above code started working with out
making any changes.
I don't understand why? Any idea please let me know.
Thanks a lot for your help.
Jill.
cbrouss...@liquiddatainc.com wrote:
> Looks like your courseBean & courseBeanForm isn't in sync.
>
[quoted text clipped - 117 lines]
> > Thanks,
> > Jill.
jill - 15 Dec 2005 15:03 GMT
Thanks cbroussard for your reply.
I am not doing what you said. I don't have setCourseBean in my
courseBeanForm. I will try that.
But one weird thing happened yesterday evening, I restarted my server
and my code started working. So the above code started working with out
making any changes.
I don't understand why? Any idea please let me know.
Thanks a lot for your help.
Jill.
cbrouss...@liquiddatainc.com wrote:
> Looks like your courseBean & courseBeanForm isn't in sync.
>
[quoted text clipped - 117 lines]
> > Thanks,
> > Jill.
jill - 15 Dec 2005 15:03 GMT
Thanks cbroussard for your reply.
I am not doing what you said. I don't have setCourseBean in my
courseBeanForm. I will try that.
But one weird thing happened yesterday evening, I restarted my server
and my code started working. So the above code started working with out
making any changes.
I don't understand why? Any idea please let me know.
Thanks a lot for your help.
Jill.
cbrouss...@liquiddatainc.com wrote:
> Looks like your courseBean & courseBeanForm isn't in sync.
>
[quoted text clipped - 117 lines]
> > Thanks,
> > Jill.
Tim B - 15 Dec 2005 02:55 GMT
"jill" <jilljuneja@gmail.com> wrote> JSP Code - modifyCourse.jsp
> <%@ page import="com.nyiso.lc.admin.LCConstants,
> com.nyiso.lc.admin.CourseTypeBean,
[quoted text clipped - 3 lines]
> <%@ include file = "header.html" %>
> <%@ include file = "menu.jsp" %>
> <table>
> <tr>
[quoted text clipped - 4 lines]
> <bean:define id="courseBean1" name="courseBean" toScope="session"
> type="com.nyiso.lc.CourseBean"//>
you are missing this:
<%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean" %>
look in your actual html ouput. it probably has this:
<bean:write name="courseBean1" property="courseName"/>
because the bean:write tag is not being processed