Return-Path: Delivered-To: apmail-struts-user-archive@www.apache.org Received: (qmail 50887 invoked from network); 21 Feb 2006 05:37:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 21 Feb 2006 05:37:30 -0000 Received: (qmail 18812 invoked by uid 500); 21 Feb 2006 05:37:20 -0000 Delivered-To: apmail-struts-user-archive@struts.apache.org Received: (qmail 18788 invoked by uid 500); 21 Feb 2006 05:37:19 -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 18777 invoked by uid 99); 21 Feb 2006 05:37:19 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Feb 2006 21:37:19 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of craigmcc@gmail.com designates 64.233.162.204 as permitted sender) Received: from [64.233.162.204] (HELO zproxy.gmail.com) (64.233.162.204) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Feb 2006 21:37:18 -0800 Received: by zproxy.gmail.com with SMTP id s18so1056214nze for ; Mon, 20 Feb 2006 21:36:58 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:in-reply-to:mime-version:content-type:references; b=d6Lb7gXj7k7NBKgRB1thiW/mqRhzW5/RulESvWfMOGv8kz533+opb0ckj6z8js0Sk0+y016vWqVkcP7iPmc10D8nqnQlokU3oNeUDWnQSm4rVSUL0JjVsM1m7B96xxsnjCTUObHzh5OBak4dkHnxXQtn+lMDjL0WkUR7//sZIvI= Received: by 10.65.183.18 with SMTP id k18mr1187001qbp; Mon, 20 Feb 2006 21:36:58 -0800 (PST) Received: by 10.64.253.5 with HTTP; Mon, 20 Feb 2006 21:36:57 -0800 (PST) Message-ID: Date: Mon, 20 Feb 2006 21:36:57 -0800 From: "Craig McClanahan" Sender: craigmcc@gmail.com To: "Struts Users Mailing List" Subject: Re: Value-ChangeEvent under Struts-Faces In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_6544_4553040.1140500217995" References: <022020060430.7632.43F945D60003B10F00001DD022007340760A9D9B0E03020E9009@comcast.net> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N ------=_Part_6544_4553040.1140500217995 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 2/20/06, Leila Carvalho wrote: > > Craig, > First of all, congratulations for your Struts-Faces library!! > This library is what I have been looking for.. > > be careful of one particular scenario. Struts only creates one instance > of > > an Action class for the entire application, so that is not a good place > to > > put request-specific event handlers. > > > --great!!! > I=B4m newbie in Faces, so I=B4m dissecting struts-faces' very good exampl= es 1 > and 2. > I=B4m sure that all run well for actionEvents and there are some backing > beans > for that. > Please, is there some sample code for Value-change Events in > Struts-Faces??? > I would like saving time not doing my own tests... > > >By the way, are you writing a new application, or trying to adapt > something > that already exists? > > --My Struts application already exists. All I need at first is avoiding > JavaScript when > relating 2 modal comboboxes. Can I apply Value-change Events instead?? Here is an outline of one way to accomplish this task -- it's not by any means the only possible pattern. I need to start with an assumption -- that the relationship between the two combo boxes is specific to a particular user? If so, that means the backin= g bean we are talking about will naturally fit into session scope. Next, I'l= l make one more assumption ... the set of options in the second checkbox should depend on the user's choice in the first box. If I'm correct so far= , let's pretend the first combobox is the set of US states, and the second on= e changes to be the set of cities appropriate to that state. This is just to make the illustration clearer. Now, assume you have a backing bean called "geography" that is defined to b= e a managed bean in session scope. On this bean, you'll have two methods: // Return selection items for *all* states public SelectItem[] getStates() { return this.states; } // Return selection items for cities in the specified state public SelectItem[] getCities() { return this.cities; } With a couple of instance variables (by the way, SelectItem is the representation of the label and value of a particular option to show in a dropdown). // Initialize the states list to all the state abbreviations and names private SelectItem[] states =3D new SelectItem[] { new SelectItem("AL", "Alabama"), new SelectItem("AK", "Alaska"), ... } // Initialize the cities list to a zero-length arary private SelectItem[] cities =3D new SelectItem[0]; In addition, this bean might have a value change listener method like this: // Respond to changes in which state is selected public void stateChanged(ValueChangeEvent event) { String newState =3D (String) event.getNewValue(); cities =3D ... calculate array of cities based on the value of newState ... } Putting this together into one page, you would have your two combo boxes declared something like this: There are a couple of issues still to deal with your comment about doing this kind of thing "without Javascript" but the details really depend on ho= w seriously that is actually to be taken. Making this work with Javascript disabled in the browser, for example, is possible ... but you have to be ready to deal with the fact that you need the entire form submitted for the value change event to be fired, since it (like all the other events that JS= F defines) happen on the *server*, not on the *client*. It's also possible to look for combo box components that are more sophisticated than the one defined by the standard ... perhaps even one tha= t uses AJAX techniques to change the city list on the fly, without requiring = a form submit. But any component like this is going to depend on being able to execute Javascript in the client. Thanks!! > ---------- > > Craig ------=_Part_6544_4553040.1140500217995--