JSP Navigation + Passing values

Posted on 2006-06-05
Last Modified: 2011-09-20
I am a relatively newbie with JSP, JavaScript, Struts, Tiles and am having a problem passing a value between screens.

The first part of what I am doing works fine but it is the second part that I am struggling with.

[B]Part 1[/B]
I have a JSP that displays a list of users in a multi column table - it is populated via the logic:iterate tag.

I have a Javascript function that allows me to select a particular row in the table and a 'Next' button with a call to a function for URL rewriting onclick="return fnEditUser()

  function fnEditUser() {

The relates to a Struts ActionClass where I use request.getParameter to return the userId before using this Id to look up the database for particular information.  This information is then populated into an editable table where a users details can be edited or deleted.  I have the edit working but it is the delete that I am having problems with.

Part 2
When I press delete I need a way of retaining the userId that I passed from the first screen as I want to display a confirmation screen with some of the user details.

Do I have to write a new function to rediscover what the userId is or can I get this information from request.parameter or the Action form somehow.

If I have onclick="window.location=''" on the Delete button I can't query the Form or request.parameter in the following Action Class.

I hope that this is not too vague and is on the correct forum.
Question by:Coulac
    LVL 10

    Expert Comment

    I suggest you use session scope for your form bean. This you can configure using
    the action tag in your struts-config.xml.

    Next, if you are using parameters, the value will be lost once you reach your action
    method. To retain the value you can either have an attribute for userid in your ActionForm
    itself or can set the parameter again in your action before forwarding.

    LVL 3

    Accepted Solution

    By default, the scope of a form bean is "session". So assuming you have not modified your struts-config.xml to make the scope as "request", the form bean will be available on the session.

    So if you are using the same form for both edit and delete, you can get the id from the ActionForm itself.

    If, however, the forms are different for edit and delete Actions, you can save the id in the session once you do the database lookup. So when the user clicks on delete button, you can pick the id from the session.

    Author Comment

    I managed to solve this by the following code --> long userId = new Long(request.getParameter("userId")).longValue();  My scope is request as this is the standard for this project.  I can move the id from via url rewriting.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
    Local Continuous Replication is a cost effective and quick way of backing up Exchange server data. The following article describes the steps required to configure Local Continuous Replication. Also, the article tells you how to restore from a backup…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    730 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

    15 Experts available now in Live!

    Get 1:1 Help Now