Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Struts - bean:write or html:text - not getting bean value - Please help

Reply
Thread Tools

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

 
 
jill
Guest
Posts: n/a
 
      12-14-2005
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.silverl n.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_S TP%>"
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.

 
Reply With Quote
 
 
 
 
cbroussard@liquiddatainc.com
Guest
Posts: n/a
 
      12-14-2005
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


jill wrote:
> 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.silverl n.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_S TP%>"
> 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.


 
Reply With Quote
 
 
 
 
Tim B
Guest
Posts: n/a
 
      12-15-2005

"jill" <> wrote> JSP Code - modifyCourse.jsp
>
> <%@ page import="com.nyiso.lc.admin.LCConstants,
> com.nyiso.lc.admin.CourseTypeBean,
> com.nyiso.lc.admin.CourseBean,com.nyiso.lc.silverl n.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


 
Reply With Quote
 
jill
Guest
Posts: n/a
 
      12-15-2005
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.
>
> 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
>
>
> jill wrote:
> > 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.silverl n.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_S TP%>"
> > 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.


 
Reply With Quote
 
jill
Guest
Posts: n/a
 
      12-15-2005
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.
>
> 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
>
>
> jill wrote:
> > 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.silverl n.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_S TP%>"
> > 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.


 
Reply With Quote
 
jill
Guest
Posts: n/a
 
      12-15-2005
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.
>
> 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
>
>
> jill wrote:
> > 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.silverl n.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_S TP%>"
> > 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
struts indexed form elements not getting into form bean apaeth@fortdearborn.com Java 1 01-07-2006 09:29 PM
To bean or not to bean Steven T. Hatton C++ 61 09-10-2004 07:14 AM
Simple Struts question: how can I add the value of a bean variable to arg0 of the bean:message tag? Thomas P. Fuller Java 1 08-17-2004 01:42 AM
Mr. Bean Complete Bean NOT complete!! Waterperson77 DVD Video 5 12-10-2003 05:22 PM
To bean or not to bean... Benjamin Stewart Java 0 06-30-2003 12:34 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57