Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bean:write

 
raj baig
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i have a form with a text field "userid" and a button "submit".
when i click submit it will go to a actionform and to a jsp,where i want
to display the value using struts tags. But i am not able to display.


my strtus-config.xml


<form-bean
name="myFormBean"
type="a.b.UserBean" />

<action path="/executeMyForm" name="myFormBean"
forward="/succ.jsp"/>

my suc.jsp:

<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/tags/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tags/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tags/struts-logic.tld" prefix="logic" %>
<html:html>
<bean:message key="user.name"/>
<bean efine id="myform" name="myFormBean" type="a.b.UserBean"/>
<bean:write name="myform" property="userId" />
</html:html>

I am getting me the value of bean:message only not the value of form value.

If i am wrong please let me know how to dispply the form text value using
struts tags.

Thanks in Advance,
Raj.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us the JSP that contains the text field and submit button.
 
raj baig
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

This is my JSP

<html:html>
<head><title>Submit example</title></head>
<body>
<h3>Example Submit Page</h3>

<html:form action="executeMyForm.do" >
Enter User Id <html:text property="userId" /><br/>
<input type="submit" name="userId"value="submit" />
</html:form>
</body>
</html:html>
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try removing the <bean:define> tag and just specifying <bean:write name="myFormBean" property="userId" />.
[ March 16, 2007: Message edited by: Merrill Higginson ]
 
raj baig
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Merrill,
I removed <bean efine> and added <bean:write name="myFormBean" property="userId" />

But not able to display the value. any more guess.


Regards,
Raj.
 
raj baig
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Merrill,
i tried by putting sop in the UserBean class. Observed setter is not calling any where. in tomcat console it is calling only getters not setter.

from userbean constructor
from user bean reset
from user bean getter
from userbean constructor
from user bean getter
from user bean getter
from userbean constructor
from user bean getter
from user bean getter
from user bean getter
from user bean getter
from userbean constructor
from user bean getter
from user bean getter


my form bean

 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I see the problem. It's with the following statement:

By giving your submit button the same name as the property on your <html:text> tag, you're overwriting it. Just use <html:submit value="submit" />
[ March 20, 2007: Message edited by: Merrill Higginson ]
 
raj baig
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Merrill,

i modified as

<html:text property="userId" /><br/>
<html:submit value="submit" />

Even Setter is not calling .

 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your action mapping is also wrong.

It should be something like:

This also means that you must write class that extends org.apache.struts.actionAction named UserAction.

Given the number of errors you're making, it seems like it might be a good idea to take a step back and go through some tutorials to help you get a better grasp on Struts. You'll find a number of good ones in the Struts Wiki.
[ March 20, 2007: Message edited by: Merrill Higginson ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic