|
Hi Aaron, I guess there are various ways to design your JSF applications. One of the simplest options is to put your ActionListener code into the same class that backs up your JSF components, that is Customer.java. By the way, looks like there should be another faces-config.xml entry for the Events.java, right? In any event, you might want to create your business object as a separate Java class and have Customer.java reference it. Then ActionListener will simply retrieve values of each component (name, address, etc) since they are accessible and update your business object with those values. Anyway, this is how I would design my JSF apps, at least to get things going. Hope this helps, Vadim. Internet: berestet@xxxxxxxxxx "Bartell, Aaron L. (TC)" <ALBartell@taylor To corp.com> "Websphere Development Studio Sent by: Client for iSeries" wdsci-l-bounces@m <wdsci-l@xxxxxxxxxxxx> idrange.com cc Subject 10/28/2004 04:42 [WDSCI-L] JSF Model objects - how PM do you fill them from a listener? Please respond to Websphere Development Studio Client for iSeries Status: Head bleeding from wall hitting Ok, I have just about the simplest JSF app I can think of and what just isn't making sense to me is how I update my "model" or "business logic" object from an action listener that isn't part of the model object. I am displaying an input text field where the user will enter a number. When they hit the submit button an actionListener will get called (this works). But how do I fill in my Customer java object from the action listener method? The Customer object is registered in the faces-config.xml as follows: <managed-bean> <managed-bean-name>customer</managed-bean-name> <managed-bean-class>com.wgeb.customer.Customer</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> As you can see below I am filling in the outputFormat fields with #{customer.xxxxx} which should map to the Customer object and pull values from it. CustIndex.jsp: ... <f:view> <BODY> <hx:scriptCollector id="scriptCollector1"> <h:form styleClass="form" id="form1"> <P><h:outputText styleClass="outputText" id="text1" value="Enter Customer"></h:outputText><h:inputText styleClass="inputText" id="text2"></h:inputText><hx:commandExButton type="submit" value="Display Customer" styleClass="commandExButton" id="button1" actionListener="#{listener.displayCustomer}"> </hx:commandExButton><BR> <BR> <BR> <h:outputText styleClass="outputText" id="text3" value="Name"></h:outputText> <h:outputFormat styleClass="outputFormat" id="format1" value="#{customer.name}"> </h:outputFormat><BR> <h:outputText styleClass="outputText" id="text4" value="Address"></h:outputText> <h:outputFormat styleClass="outputFormat" id="format2" value="#{customer.address}"></h:outputFormat><BR> <h:outputText styleClass="outputText" id="text5" value="City"></h:outputText> <h:outputFormat styleClass="outputFormat" id="format3" value="#{customer.city}"></h:outputFormat><BR> <h:outputText styleClass="outputText" id="text6" value="State"></h:outputText><h:outputFormat styleClass="outputFormat" id="format4" value="#{customer.state}"></h:outputFormat> <BR> <h:outputText styleClass="outputText" id="text7" value="Zip"></h:outputText><h:outputFormat styleClass="outputFormat" id="format5" value="#{customer.zip}"></h:outputFormat> <BR> <BR> </P> </h:form> </hx:scriptCollector> </BODY> </f:view> ... Customer.java: package com.wgeb.customer; public class Customer { public Customer() { } private String name = ""; private String address = ""; private String city = ""; private String state = ""; private String zip = ""; public String getAddress() { return address; } public String getCity() { return city; } public String getName() { return name; } public String getState() { return state; } public String getZip() { return zip; } public void setAddress(String string) { address = string; } public void setCity(String string) { city = string; } public void setName(String string) { name = string; } public void setState(String string) { state = string; } public void setZip(String string) { zip = string; } } Events.java: package listeners; import javax.faces.event.AbortProcessingException; import javax.faces.event.ActionEvent; import javax.faces.event.ActionListener; public class Events implements ActionListener { public Events() { } public void processAction(ActionEvent arg0) throws AbortProcessingException { } public void displayCustomer(ActionEvent arg0) throws AbortProcessingException { //!!!! Here is where I want to fill in the customer object !!!!!!!!! // Eventually this will be calling some RPG programs to get the customer information } } _______________________________________________ This is the Websphere Development Studio Client for iSeries (WDSCI-L) mailing list To post a message email: WDSCI-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/mailman/listinfo/wdsci-l or email: WDSCI-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/wdsci-l.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.