|
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
}
}
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.