Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help! How retain form values if it contain errors after submit button 1

Status
Not open for further replies.

jollyplay

Programmer
Dec 16, 2003
90
0
0
Hello,

I am new to Struts. I need to retain form values after
submitting the button, if the form contain errors. Any
need to change in struts-config.xml? or programatically i do it with session. Tell me the easy way. Please help me.
Thanks in advance.


With regards,
balachandar.
 
Hi,

You can do it either way. In struts-config.xml for that action mapping you can set the scope as session insted of request. So that the action mapping is stored in the session. If not you can store the form into a session in the action class and can get the form with values when ever required from the session.

Cheers,
Venu
 
Hello,

Thank u for ur reply.

I tried in this way, as u told and own myself.


In struts-config.xml

<form-bean name=&quot;AssignBookBean&quot;
type=&quot;com.ui.AssignBookBean&quot;/>

<action input=&quot;/view/AssignBook.jsp&quot; name=&quot;AssignBookBean&quot;
path=&quot;/view/AssignBookAtion&quot; scope=&quot;session&quot; type=&quot;com.ui.AssignBookAction&quot;>
<forward name=&quot;success&quot; path=&quot;/view/BookList.jsp&quot;/>
<forward name=&quot;BookList&quot; path=&quot;/view/BookList.jsp&quot;/>
</action>

In JSP
------
<html:html>
.
.

<html:form action=&quot;/view/AssignBookAction&quot; name=&quot;assignbook&quot; type=&quot;com.ui.AssignBookBean&quot;>
<html:text property=&quot;bookname&quot; size=&quot;27&quot;/>
</html:form>
'.
.
</html:html>


but, still it is not working. Can u give example source link or code regarding this?.
Thanks in advance,


With regards,
balachandar.
 
The configuration looks ok. May be something wrong in your form bean. Can you show me the code of your com.ui.AssignBookBean?
 
Hi,

In struts-config.xml form-bean name=&quot;&quot; should be equal to the name in the html:form name in jsp.

In AssignBook.jsp change the html:form tag name.

<html:form action=&quot;/view/AssignBookAction&quot; name=&quot;AssignBookBean&quot; type=&quot;com.ui.AssignBookBean&quot;>


Cheers,
Venu
 
Hello,

Thank u.

I did, as u told and i also including <html:form scope=request--- > and in struts-config.xml in action mapping, i changed the scope=request.

Now it is working fine.

if we give scope=session then what is the problem
i am facting is, all the time it retain the values in the
form (unnecessary) whether it contain error or not. First time only it does not have values.

<html:form action=&quot;/view/AssignBookAction&quot; scope=&quot;request&quot; name=&quot;AssignBookBean&quot; type=&quot;com.ui.AssignBookBean&quot;>

<form-bean name=&quot;AssignBookBean&quot;
type=&quot;com.ui.AssignBookBean&quot;/>

<action input=&quot;/view/AssignBook.jsp&quot; name=&quot;AssignBookBean&quot;
path=&quot;/view/AssignBookAtion&quot; scope=&quot;request&quot; type=&quot;com.ui.AssignBookAction&quot;>
<forward name=&quot;success&quot; path=&quot;/view/BookList.jsp&quot;/>
<forward name=&quot;BookList&quot; path=&quot;/view/BookList.jsp&quot;/>
</action>


Hello all, thank u for ur support.



With regards,
balachandar.




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top