Return-Path: Delivered-To: apmail-struts-user-archive@www.apache.org Received: (qmail 93123 invoked from network); 18 Dec 2007 05:50:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Dec 2007 05:50:33 -0000 Received: (qmail 15853 invoked by uid 500); 18 Dec 2007 05:50:13 -0000 Delivered-To: apmail-struts-user-archive@struts.apache.org Received: (qmail 15827 invoked by uid 500); 18 Dec 2007 05:50:13 -0000 Mailing-List: contact user-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Struts Users Mailing List" Reply-To: "Struts Users Mailing List" Delivered-To: mailing list user@struts.apache.org Received: (qmail 15816 invoked by uid 99); 18 Dec 2007 05:50:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Dec 2007 21:50:13 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [216.182.86.132] (HELO phaea.greywether.com) (216.182.86.132) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Dec 2007 05:49:50 +0000 Received: (qmail 743 invoked from network); 18 Dec 2007 05:26:32 -0000 Received: from unknown (HELO Gary-Affonsos-iMac.local) (gary@greywether.com@70.89.113.254) by phaea.greywether.com with ESMTPA; 18 Dec 2007 05:26:32 -0000 Message-ID: <47675D99.8090609@greywether.com> Date: Mon, 17 Dec 2007 21:41:45 -0800 From: Gary Affonso User-Agent: Thunderbird 2.0.0.6 (Macintosh/20070807) MIME-Version: 1.0 To: Struts Users Mailing List Subject: Re: Exception Handling keeping user input References: <43A08EA5DEE4F045ADADB4E3AB87E8C352BFAA@orion.pulsar.be> In-Reply-To: <43A08EA5DEE4F045ADADB4E3AB87E8C352BFAA@orion.pulsar.be> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org To follow up on my previous post, here's some code from a "showForm" action that does exactly what I described... public void prepare() { if(session.get(SignUpFormBean.SESSION_KEY) == null) { // they're here for the first time. do nothing (leave the signUpFormBean model object null) } else { // they're returning because they've already failed a submission log.debug("retrieving SignUpFormBean from session"); signUpFormBean = (SignUpFormBean) session.get(SignUpFormBean.SESSION_KEY); session.remove(SignUpFormBean.SESSION_KEY); // errors from previous failure have been retrieved via the MessageStore interceptor } } public SignUpFormBean getModel() { return signUpFormBean; } // Struts execute method // NOTE: the error messages from the validation failure are available to this action (and the view) via the StoreMessages interceptor public String execute() throws Exception { // we always provide region and country lists to the view allPostalAddressRegions = postalAddressRegionDao.getAllPostalAddressRegions(); allPostalAddressCountries = postalAddressCountryDao.getAllPostalAddressCountries(); return Action.SUCCESS; } ---- One of the fields for the form view (freemarker in my case) looks something like this... ${(fieldErrors["postalAddress.firstName"]) !} ---- The idea being that the view will show data in the SignUpFormBean if that object contains it. If that object is null Freemarker shows nothing. Works great, you can use the exact same form code regardless of whether SignUpFormBean (in your case NewCar) has data or not. You may need to play with how your own view layer (JSP? Velocity?) handles the display of data for objects (or fields) that are null (and they will be if this is the 1st time the user visits the form, they'll only have data if the form is getting shown after a validation problem). Freemarker is a bit touchy about null objects and properties so you have to some special notation which you see above. I think velocity is more forgiving. Not sure about JSP (I'm still actively trying to avoid it, mostly succeeding). Hopefully that gets you going in the right direction. - Gary Jeremy JGR. Grumbach wrote: > Hi, > > Let's take the following scenario: we have a database which manage car > models (for example Dogde Viper). The column "name" of the "car model" > table must be unique. > The user wants to add a "car model" in the database, thus he has an "add > screen" containing all the fields of the "car model" and a "Save" > button. However he has entered a model which already exists in the > database. I check that in my business layer and return a runtime > exception "name already exists". > I can display it using global-exceptions, however it is forwarded to > another page and consequently, the user must reenter all the field > values one more time. > To avoid that, I want to go back to the "add screen" without losing user > inputs but with a red message "name already exists in the database" - > exactly like the struts validation error messages. > > Do you think it is possible with Struts 2? I have used that lots of time > in Struts 1. > > Thanks in advance, > > Jeremy > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org > For additional commands, e-mail: user-help@struts.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@struts.apache.org For additional commands, e-mail: user-help@struts.apache.org