• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

newbie problem - populating Action form

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
This is probably a really simple problem, and only seems insoluble because I'm tired from programming for too long in a row, but...
I have an ActionForm, which I use to pre-populate a form in a JSP page. I expected that the ActionFormwould then use the data in the html form (suitably modified by the user input) and the newly populated form would then be passed back to the Action. However, what actually happens is that while the form is pre-populated properly, when I hit submit the reset method is called, and the Action gets an empty ActionForm. Here are the relevant code snippets. Does anyone have any suggestions?
JSP fragment:
<html:form action="saveMessageBody.do" >
MessageText: <html:textarea rows="4" cols="40" property="messageText"/><br>
<html:hidden property ="messageBodyId" />
<html:hidden property ="jobID" />
<html:submit property="submit" value="Submit"/>
</html:form>
struts-config.xml
<form-bean name="messagebodyForm"
type="au.com.apwd.wireless.data.MessageBodyData"/>
...
<forward name="/do/editAMessage"
contextRelative="true"
path="/do/editAMessage"
redirect="false"/>

<forward name="/do/saveMessageBody"
contextRelative="true"
path="/do/saveMessageBody"
redirect="false"/>
...
<action path="/editAMessage"
type="au.com.apwd.wireless.web.actions.EditAMessageAction"
input="/viewAJob.do"
name="messagebodyForm"
scope="session">

<forward name="login" path="/login.jsp"/>
<forward name="success" path="/pages/admin/editAMessage.jsp"/>
<forward name="failure" path="/pages/error.jsp"/>
</action>
<action path="/saveMessageBody"
type="au.com.apwd.wireless.web.actions.SaveMessageBodyAction"
input="/editAMessage.do"
name="messagebodyForm"
scope="session">

<forward name="login" path="/login.jsp"/>
<forward name="success" path="/do/viewAJob"/>
<forward name="failure" path="/pages/error.jsp"/>
</action>
There isn't anything at all interesting about the Action (hjust mutators and reset(...)) or the ActionForm, so I omit them.
Any thoughts at all?
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first thing I notice, and I'm not sure if this has anything to do with your problem, is that you have some problems with your struts-config.xml.
First off, are you using extension mapping or path mapping? Your struts-config.xml has a mix of both. It looks like you are predominantly using path mapping (ie /do/actionName as opposed to actionName.do). Whatever the url-pattern is that you've specified in web.xml is what you need to stick with. Let's assume for now that you are using path mapping.
Your global forwards need to be fixed. You need to drop the "/do/" part of the "name" attribute. For example:
<forward name="saveMessageBody"
In your action mappings, the format for the input attribute of the <action> tags is wrong. The input attribute should refer to the jsp form, if any, that serves as the input to this action. So your action mapping might look something like...
<action path="/saveMessageBody"
type="au.com.apwd.wireless.web.actions.SaveMessageBodyAction"
input="/edit.jsp"
name="messagebodyForm"
scope="session">
Just a stylistic note, looking at the local forwards in a couple of your action mappings, I would probably factor out "login" and "failure" and make them global forwards.
Finally, if you are using path mapping, you need to fix your <html:form> so that the value for the action attribute is exactly equal to the path attribute of the corresponding <action> element. This is also true if you are using extension mapping, although in that case you could optionally add the extension if you wanted to.
<html:form action="/saveMessageBody">
Once you make these changes, see if things work.
HTH
 
Alister Pate
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that Jason.
I had no end of problems trying to get all that to work. I always have horrible difficulty with any path related things, and it's always a crisis when I have to try to build things in a hurry to keep clients happy. Ho hum. Still, at least I will have comprehensively mastered struts after this.
I'll try your suggestions, and I'll report back.
 
Alister Pate
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I've done what you suggested. Thanks for the help - I see now I wasn't making a distinction between "page" and "forward" attributes on my links and form actions - which was a bit dim. I can only say in mitigation that I've been rushing to get this done.
However, this hasn't really solved my problem. The form still isn't being populated by the time it gets to my action. It is being read OK, so the form is pre-populated, but when it gets sent back to my acton, the reset method has been called, so it is empty. I'm currently repopulating the form from the parameters in the request, which does work - but I thought struts was supposed to do this for me?
 
Alister Pate
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see I've left off the html form. Here it is
<html:form action="/saveMessageBody">
MessageText: <html:textarea rows="4" cols="40" property="messageText"/><br>
<html:hidden property ="messageBodyId" />
<html:hidden property ="jobID" />
<html:submit property="submit" value="Submit"/>
</html:form>
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic