Avatar billede fredand Forsker
06. juli 2009 - 17:00 Der er 5 kommentarer og
1 løsning

How to fill in a form with struts when returning to it?

Hello!

I think I'm missing something fundamental in Struts, but I can't figure out what.

What I want to acomplish is that a form should be filled in with values from previous submit.

To illustrate this I got this silly example:

Suppose the following, a user fills in a form with the following textfields:
car brand: "Ford Mustang"
number: 1
The user submits the form
A page is shown:
Ford Mustang with number 1 created

Now the user is supposed to submit 100 "Ford Mustang".

Then it would be great if the user after the submit could return to the form with the previous submitted data already filled in and just change the number 1 to 2, submit the next one and so on.

To return to the previous form I need a link. I also hope that that link can use javascript history.back();

So if any one got any experience about this with Struts, please let me know.

Best regards
Fredrik
Avatar billede arne_v Ekspert
06. juli 2009 - 17:17 #1
You create the input text filed using either Struts or JSTL tag.

You specify a default value using value attribute and EL.

The action sets a bean in the request with the data referrede to by EL.
Avatar billede fredand Forsker
06. juli 2009 - 17:50 #2
Hello Arne!

Thanks for fast reply (very fast!)

Correct me if I'm wrong when I then say that this should work:

My form (if PersonForm exist in session then dispaly the value of personnr):
<html:text name="PersonForm" property="personnr"/>

My struts-config.xml
<form-bean     
  name="PersonForm"
  type="myapp.PersonForm"/>   

<action    path="/PersonQueryInput"
  type="myapp.PersonQueryAction"
  name="PersonForm"
  scope="request"
  validate="false">
  <forward name="PersonQuery" path="/personQuery.jsp"/>
</action>

My code executed before going to /PersonQueryInput:
session.setAttribute("PersonForm", personForm);

In my PersonForm there is a private member personnr with a public method getPersonnr returning a String.

Am I out of track or do I closing in?

Best regards
Fredrik
Avatar billede arne_v Ekspert
06. juli 2009 - 18:18 #3
I think you are somewhere between in the right direction and very close depending on exactly how the functionality is expected to be.

I don't remember Struts that well, but I don't think you want to use the form bean or session object for this.
Avatar billede fredand Forsker
09. juli 2009 - 09:25 #4
Hello!

Thanks for your help!

I do insist that you should give a svar so I can reward you.

It seems like I had to solve it with using the session.

I never got it to work with just using the request.

How ever right now everything works as it should, accept one thing, see my next topic:
"How to tell from what request user comming from (in this situation)?"

So all this might "back fire".

Hope you have time to look at that topic as well.

Best regards
Fredrik
Avatar billede arne_v Ekspert
09. juli 2009 - 18:14 #5
svar
Avatar billede arne_v Ekspert
09. juli 2009 - 18:15 #6
I have seen the other question.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester