Struts - bean:write or html:text - not getting bean value - Please help

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.
 
C

cbroussard

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
 
T

Tim B

jill said:
<%@ 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"//>


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
 
J

jill

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.
 
J

jill

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.
 
J

jill

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,690
Latest member
MacGyver

Latest Threads

Top