Hello Fellow Developers,
I have been stuck on this problem for a week and half now, i thought i could
solve it without troubling you folks, however i need your help to clarify a
few ideas and to get it working properly.
I have a multi-page form and within the form there is an mailing address
form(with typical , street_name, city, country,etc fields). I would like to
utilize the same functionality as the struts example Mail Reader
Application's subscription Form (i.e. Add, Delete, Edit). However in my
application there is no user logged into the session. But i am using session
to span through 7 screens.
My question is how can i incorporate the subscription(example) form into my
form without using the user_key. Is it possible to write the information the
user enters into a session(rather than the xml file), and then allow the
user to edit/delete that particular information?
I have tried to take out all references to the user constants but i get
compilation erros. I am a newbie and will be grateful if you could provide
me with a good place to start or modify the following code and point out
what i would need to do to achieve the above.
EditSubscriptionAction.java
package org.apache.struts.webapp.example;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Locale;
import java.util.Vector;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.util.MessageResources;
/**
* Implementation of <strong>Action</strong> that populates an instance of
* <code>SubscriptionForm</code> from the currently specified subscription.
*
* @author Craig R. McClanahan
* @version $Revision: 1.3 $ $Date: 2001/07/16 00:44:51 $
*/
public final class EditSubscriptionAction extends Action {
// --------------------------------------------------------- Public
Methods
/**
* Process the specified HTTP request, and create the corresponding HTTP
* response (or forward to another web component that will create it).
* Return an <code>ActionForward</code> instance describing where and
how
* control should be forwarded, or <code>null</code> if the response has
* already been completed.
*
* @param mapping The ActionMapping used to select this instance
* @param actionForm The optional ActionForm bean for this request (if
any)
* @param request The HTTP request we are processing
* @param response The HTTP response we are creating
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet exception occurs
*/
public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// Extract attributes we will need
Locale locale = getLocale(request);
MessageResources messages = getResources();
HttpSession session = request.getSession();
String action = request.getParameter("action");
if (action == null)
action = "Create";
String host = request.getParameter("host");
if (servlet.getDebug() >= 1)
servlet.log("EditSubscriptionAction: Processing " + action +
" action");
// Is there a currently logged on user?
User user = (User) session.getAttribute(Constants.USER_KEY);
if (user == null) {
if (servlet.getDebug() >= 1)
servlet.log(" User is not logged on in session "
+ session.getId());
return (servlet.findForward("logon"));
}
// Identify the relevant subscription
Subscription subscription = null;
if (action.equals("Create")) {
subscription = new Subscription();
subscription.setUser(user);
} else {
subscription = user.findSubscription(host);
}
if (subscription == null) {
if (servlet.getDebug() >= 1)
servlet.log(" No subscription for user " +
user.getUsername() + " and host " + host);
return (mapping.findForward("failure"));
}
session.setAttribute(Constants.SUBSCRIPTION_KEY, subscription);
// Populate the subscription form
if (form == null) {
if (servlet.getDebug() >= 1)
servlet.log(" Creating new SubscriptionForm bean under key "
+ mapping.getAttribute());
form = new SubscriptionForm();
if ("request".equals(mapping.getScope()))
request.setAttribute(mapping.getAttribute(), form);
else
session.setAttribute(mapping.getAttribute(), form);
}
SubscriptionForm subform = (SubscriptionForm) form;
subform.setAction(action);
if (servlet.getDebug() >= 1)
servlet.log(" Populating form from " + subscription);
try {
PropertyUtils.copyProperties(subform, subscription);
subform.setAction(action);
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
if (t == null)
t = e;
servlet.log("SubscriptionForm.populate", t);
throw new ServletException("SubscriptionForm.populate", t);
} catch (Throwable t) {
servlet.log("SubscriptionForm.populate", t);
throw new ServletException("SubscriptionForm.populate", t);
}
// Forward control to the edit subscription page
if (servlet.getDebug() >= 1)
servlet.log(" Forwarding to 'success' page");
return (mapping.findForward("success"));
}
}
so just a simple standalone jsp with ADD/EDIT/DELETE links will be more than
enough for me to get started.
Also if anybody knows of any links where i can find more information, i will
me more than grateful.
Thanking you in advance!
it_med
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>