Persisting input fields

I'm looking for some assistance in modifying an existing jsp page to add some new persistent input fields. Just understanding what is going on under the hood is a bit of a challenge.

First the observed  user experience with what I've done so far. My input form comes up with some fields. I have added my new fields to the form, if and only if certain conditions are true based on a database query on a id passed into this form - call this form "info1". Info1 has some functionality that you choose items displayed on it by moving to another page (call it select1), selecting one of many items, then you return to info1. Problem is - my new fields get blown away after this workflow. When the user is returned to info1 after selecting a new item any data they have entered is missing. The question becomes - how do I get my new input fields to survive the detour into the select1 page?

A few more relevant technical details, so far as I have discovered the so far:

session is disabled for the page by an @include in info1

The database query that determines whether my new fields are displayed is performed in a @included jsp (call it Include1). Currently I'm setting a boolean variable in this jsp, if my fields should be displayed. Existing fields on info1 are either pulled from the database (initial case) or by using "request.getParameter" (after select1).

The form element in info1 posts to a intermediate processing jsp, which then redirects using jsp:forward to select1

select1 posts back to info1 (I think) with the item selected.

info1 grabs existing field data using request.getParameter, my new fields are nowhere to be seen...

An existing input field that works (its data survives the select process) on info1 looks like this in the jsp:

<INPUT type=text name="shippingInstr"> <%=shippingInstr%> </INPUT>

shippingInstr is set in Include1, using a database query in the initial case and a getParameter call after the select.

So given this workflow - display info1, post to intermediate, redirect to select1, post to info1. How do I ensure that data entered into my new input fields on info1 is repopulated when the user returns from the select1 page?

Who is Participating?
bloodredsunConnect With a Mentor Commented:
If you're using an @ inlclude, your  jsp is included at compile time whereas if you use jsp:include, your jsp is included at run-time. This may be one cause.

The other cause may be that you are not persisting the request infomation correcttly. As information stored in the request is only available to dynamically incldued jsps and any jsps where you ahve forwarded the information (via a jsp:forward or a RequestDispatcher() ) you may be missing re-entering the information between requests.

I can't comment more with out seeing the rest of the code as the code you've shown so far looks fine.


request.getParameter("shippingInstr"); //retrieves from the request parameters, e.g. those set by a form
(cast_required)request.getAttribute("shippingInstr");  //retrieves from the request object

so make sure you are calling the correct one.
Can you post the relevant code for the getting and setting of the variables?
dale77011299Author Commented:
Here are the relevant lines from Include1 which set the shippingInstr field. This field persists correctly after the item selection page.

   String shippingInstr             = "";
   shippingInstr          = request.getParameter("shippingInstr"); // retrieve from request scope?
   shippingInstr          = scart.getShippingInstructions(); // retrieve from database

And here's the snippet from Info1

<TD class="prompt">
<TEXTAREA name = "shippingInstr" rows=3 cols=30 ><%= shippingInstr %></TEXTAREA>
dale77011299Author Commented:
The file is being included using @include, so it's compile time.

I have managed to get something working now. I'll describe what was happening, steps 5 & 6 are what makes this work.

1. Info1 includes Include1 using @include
2. Include1 pulls the shippingInstr input field value from the database and stores it in the java variable shippingInstr
3. Info1 defines a TEXTAREA tag with <%= shippingInstr %>
4. Info1 posts to Select1
5. NEW! - Select1 includes Include2
6. NEW! -Include2 generates a new hidden field like so:
<INPUT type="hidden" name="shippingInstr" value=<%=request.getParameter("shippingInstr")%>
7. Select1 posts to Info1
8. Info1 includes Include1 using @include
9. Include1 sets the java variable shippingInstr using request.getParameter("shippingInstr")

So the Select1 page makes hidden fields so that it can pass these back to the Info1 page, after I added similar hidden fields for my new fields, everything seems to be working now.

What is your opinion on this architecture? Is there a better way to do this? Anyway, since yours is the only reply to my question you get the points for being helpful.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.