Persisting input fields

Posted on 2005-04-17
Last Modified: 2010-04-01
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?

Question by:dale77011299
    LVL 29

    Expert Comment

    Can you post the relevant code for the getting and setting of the variables?

    Author Comment

    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>
    LVL 29

    Accepted Solution

    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.

    Author Comment

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    After several days of searching and hunting for limited documentation, I wanted to share this guide to hopefully save someone the hassle of trying to figure this out on their own. I have tested this on Xendesktop 7.1 and PS 4.5 running simultaneous…
    If you're not part of the solution, you're part of the problem.   Tips on how to secure IoT devices, even the dumbest ones, so they can't be used as part of a DDoS botnet.  Use PRTG Network Monitor as one of the building blocks, to detect unusual…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now