permaculture playing cards*
The moose likes Struts and the fly likes bean:write Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "bean:write" Watch "bean:write" New topic
Author

bean:write

raj baig
Ranch Hand

Joined: Jul 11, 2006
Posts: 96
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

Joined: Feb 15, 2005
Posts: 4864
Show us the JSP that contains the text field and submit button.


Merrill
Consultant, Sima Solutions
raj baig
Ranch Hand

Joined: Jul 11, 2006
Posts: 96
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

Joined: Feb 15, 2005
Posts: 4864
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

Joined: Jul 11, 2006
Posts: 96
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

Joined: Jul 11, 2006
Posts: 96
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

Joined: Feb 15, 2005
Posts: 4864
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

Joined: Jul 11, 2006
Posts: 96
Hi Merrill,

i modified as

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

Even Setter is not calling .

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: bean:write