Skip to main content

Netbeans 5.5.1 - Problem Editing Database for Visual Web Form

1 reply [Last post]
dwallin2
Offline
Joined: 2007-10-25
Points: 0

Hello

I am currently creating a Visual Web Form.

My first page is the Login screen, where I enter an account number and password. After submit button is clicked, my code then searches the

Database for the account number entered. If the account number entered is found, it makes that the Rowkey(rk) and stores that rowkey into

the session bean. It then navigates to the second page, ACCOUNT, and populates the fields on the Account Page with the information from

the Database Rowkey that is stored in the Session Bean.

My problem arises when I try to edit Fields in the ACCOUNT page. For example, the field emailAddress_txt. When I try to edit the

emailAddress field with the new value I would like, instead of editing the field in the RowKey currently stored in the Session Bean, it

edits the first row's emailAddress_txt instead. My emailAddress_txt in the RowKey where it should be change, stays the same.

I have no idea why it is doing this. I have set the RowKey properly, which is proven by the informatino in the fields that are being

populated, but changes made still are not affecting the Row Key that it should be. Here is my code for the ACCOUNT page, posted below...

public class Account extends AbstractPageBean {
//
private int __placeholder;

/**
* Automatically managed component initialization. WARNING:
* This method is automatically generated, so any user-specified code inserted
* here is subject to being replaced.
*/
private void _init() throws Exception {
accountDataProvider.setCachedRowSet((javax.sql.rowset.CachedRowSet)getValue("#{SessionBean1.accountRowSet1}"));
}

private Page page1 = new Page();

public Page getPage1() {
return page1;
}

public void setPage1(Page p) {
this.page1 = p;
}

private Html html1 = new Html();

public Html getHtml1() {
return html1;
}

public void setHtml1(Html h) {
this.html1 = h;
}

private Head head1 = new Head();

public Head getHead1() {
return head1;
}

public void setHead1(Head h) {
this.head1 = h;
}

private Link link1 = new Link();

public Link getLink1() {
return link1;
}

public void setLink1(Link l) {
this.link1 = l;
}

private Body body1 = new Body();

public Body getBody1() {
return body1;
}

public void setBody1(Body b) {
this.body1 = b;
}

private Form form1 = new Form();

public Form getForm1() {
return form1;
}

public void setForm1(Form f) {
this.form1 = f;
}

private StaticText account_stt = new StaticText();

public StaticText getAccount_stt() {
return account_stt;
}

public void setAccount_stt(StaticText st) {
this.account_stt = st;
}

private Hyperlink hyperlink1 = new Hyperlink();

public Hyperlink getHyperlink1() {
return hyperlink1;
}

public void setHyperlink1(Hyperlink h) {
this.hyperlink1 = h;
}

private Hyperlink hyperlink2 = new Hyperlink();

public Hyperlink getHyperlink2() {
return hyperlink2;
}

public void setHyperlink2(Hyperlink h) {
this.hyperlink2 = h;
}

private Hyperlink hyperlink3 = new Hyperlink();

public Hyperlink getHyperlink3() {
return hyperlink3;
}

public void setHyperlink3(Hyperlink h) {
this.hyperlink3 = h;
}

private StaticText accountInformation_stt = new StaticText();

public StaticText getAccountInformation_stt() {
return accountInformation_stt;
}

public void setAccountInformation_stt(StaticText st) {
this.accountInformation_stt = st;
}

private Label accountNumber_lbl = new Label();

public Label getAccountNumber_lbl() {
return accountNumber_lbl;
}

public void setAccountNumber_lbl(Label l) {
this.accountNumber_lbl = l;
}

private Label accountStatus_lbl = new Label();

public Label getAccountStatus_lbl() {
return accountStatus_lbl;
}

public void setAccountStatus_lbl(Label l) {
this.accountStatus_lbl = l;
}

private Label accountDateCreated_lbl = new Label();

public Label getAccountDateCreated_lbl() {
return accountDateCreated_lbl;
}

public void setAccountDateCreated_lbl(Label l) {
this.accountDateCreated_lbl = l;
}

private Label timeZone_lbl = new Label();

public Label getTimeZone_lbl() {
return timeZone_lbl;
}

public void setTimeZone_lbl(Label l) {
this.timeZone_lbl = l;
}

private StaticText userInformation_stt = new StaticText();

public StaticText getUserInformation_stt() {
return userInformation_stt;
}

public void setUserInformation_stt(StaticText st) {
this.userInformation_stt = st;
}

private Label firstName_lbl = new Label();

public Label getFirstName_lbl() {
return firstName_lbl;
}

public void setFirstName_lbl(Label l) {
this.firstName_lbl = l;
}

private Label lastName_lbl = new Label();

public Label getLastName_lbl() {
return lastName_lbl;
}

public void setLastName_lbl(Label l) {
this.lastName_lbl = l;
}

private Label contactPhoneNumber_lbl = new Label();

public Label getContactPhoneNumber_lbl() {
return contactPhoneNumber_lbl;
}

public void setContactPhoneNumber_lbl(Label l) {
this.contactPhoneNumber_lbl = l;
}

private Label userName_lbl = new Label();

public Label getUserName_lbl() {
return userName_lbl;
}

public void setUserName_lbl(Label l) {
this.userName_lbl = l;
}

private Label emailAddress_lbl = new Label();

public Label getEmailAddress_lbl() {
return emailAddress_lbl;
}

public void setEmailAddress_lbl(Label l) {
this.emailAddress_lbl = l;
}

private Label password_lbl = new Label();

public Label getPassword_lbl() {
return password_lbl;
}

public void setPassword_lbl(Label l) {
this.password_lbl = l;
}

private StaticText paymentInformation_stt = new StaticText();

public StaticText getPaymentInformation_stt() {
return paymentInformation_stt;
}

public void setPaymentInformation_stt(StaticText st) {
this.paymentInformation_stt = st;
}

private Label paymentMethod_lbl = new Label();

public Label getPaymentMethod_lbl() {
return paymentMethod_lbl;
}

public void setPaymentMethod_lbl(Label l) {
this.paymentMethod_lbl = l;
}

private Label firstNameOnCreditCard_lbl = new Label();

public Label getFirstNameOnCreditCard_lbl() {
return firstNameOnCreditCard_lbl;
}

public void setFirstNameOnCreditCard_lbl(Label l) {
this.firstNameOnCreditCard_lbl = l;
}

private Label lastNameOnCreditCard_lbl = new Label();

public Label getLastNameOnCreditCard_lbl() {
return lastNameOnCreditCard_lbl;
}

public void setLastNameOnCreditCard_lbl(Label l) {
this.lastNameOnCreditCard_lbl = l;
}

private Label cardType_lbl = new Label();

public Label getCardType_lbl() {
return cardType_lbl;
}

public void setCardType_lbl(Label l) {
this.cardType_lbl = l;
}

private Label cardNumber_lbl = new Label();

public Label getCardNumber_lbl() {
return cardNumber_lbl;
}

public void setCardNumber_lbl(Label l) {
this.cardNumber_lbl = l;
}

private Label expirationDate_lbl = new Label();

public Label getExpirationDate_lbl() {
return expirationDate_lbl;
}

public void setExpirationDate_lbl(Label l) {
this.expirationDate_lbl = l;
}

private StaticText billingAddress_stt = new StaticText();

public StaticText getBillingAddress_stt() {
return billingAddress_stt;
}

public void setBillingAddress_stt(StaticText st) {
this.billingAddress_stt = st;
}

private Label address_lbl = new Label();

public Label getAddress_lbl() {
return address_lbl;
}

public void setAddress_lbl(Label l) {
this.address_lbl = l;
}

private Label city_lbl = new Label();

public Label getCity_lbl() {
return city_lbl;
}

public void setCity_lbl(Label l) {
this.city_lbl = l;
}

private Label state_lbl = new Label();

public Label getState_lbl() {
return state_lbl;
}

public void setState_lbl(Label l) {
this.state_lbl = l;
}

private Label zipCode_lbl = new Label();

public Label getZipCode_lbl() {
return zipCode_lbl;
}

public void setZipCode_lbl(Label l) {
this.zipCode_lbl = l;
}

private Label country_lbl = new Label();

public Label getCountry_lbl() {
return country_lbl;
}

public void setCountry_lbl(Label l) {
this.country_lbl = l;
}

private TextField accountStatus_txt = new TextField();

public TextField getAccountStatus_txt() {
return accountStatus_txt;
}

public void setAccountStatus_txt(TextField tf) {
this.accountStatus_txt = tf;
}

private TextField accountDateCreated_txt = new TextField();

public TextField getAccountDateCreated_txt() {
return accountDateCreated_txt;
}

public void setAccountDateCreated_txt(TextField tf) {
this.accountDateCreated_txt = tf;
}

private TextField timeZone_txt = new TextField();

public TextField getTimeZone_txt() {
return timeZone_txt;
}

public void setTimeZone_txt(TextField tf) {
this.timeZone_txt = tf;
}

private TextField firstName_txt = new TextField();

public TextField getFirstName_txt() {
return firstName_txt;
}

public void setFirstName_txt(TextField tf) {
this.firstName_txt = tf;
}

private TextField userName_txt = new TextField();

public TextField getUserName_txt() {
return userName_txt;
}

public void setUserName_txt(TextField tf) {
this.userName_txt = tf;
}

private TextField lastName_txt = new TextField();

public TextField getLastName_txt() {
return lastName_txt;
}

public void setLastName_txt(TextField tf) {
this.lastName_txt = tf;
}

private TextField contactPhoneNumber_txt = new TextField();

public TextField getContactPhoneNumber_txt() {
return contactPhoneNumber_txt;
}

public void setContactPhoneNumber_txt(TextField tf) {
this.contactPhoneNumber_txt = tf;
}

private TextField cardNumber_txt = new TextField();

public TextField getCardNumber_txt() {
return cardNumber_txt;
}

public void setCardNumber_txt(TextField tf) {
this.cardNumber_txt = tf;
}

private TextField firstNameOnCreditCard_txt = new TextField();

public TextField getFirstNameOnCreditCard_txt() {
return firstNameOnCreditCard_txt;
}

public void setFirstNameOnCreditCard_txt(TextField tf) {
this.firstNameOnCreditCard_txt = tf;
}

private TextField lastNameOnCreditCard_txt = new TextField();

public TextField getLastNameOnCreditCard_txt() {
return lastNameOnCreditCard_txt;
}

public void setLastNameOnCreditCard_txt(TextField tf) {
this.lastNameOnCreditCard_txt = tf;
}

private TextField zipCode_txt = new TextField();

public TextField getZipCode_txt() {
return zipCode_txt;
}

public void setZipCode_txt(TextField tf) {
this.zipCode_txt = tf;
}

private TextField address1_txt = new TextField();

public TextField getAddress1_txt() {
return address1_txt;
}

public void setAddress1_txt(TextField tf) {
this.address1_txt = tf;
}

private TextField city_txt = new TextField();

public TextField getCity_txt() {
return city_txt;
}

public void setCity_txt(TextField tf) {
this.city_txt = tf;
}

private PasswordField password_pwd = new PasswordField();

public PasswordField getPassword_pwd() {
return password_pwd;
}

public void setPassword_pwd(PasswordField pf) {
this.password_pwd = pf;
}

private Button submit_btn = new Button();

public Button getSubmit_btn() {
return submit_btn;
}

public void setSubmit_btn(Button b) {
this.submit_btn = b;
}

private Button cancel_btn = new Button();

public Button getCancel_btn() {
return cancel_btn;
}

public void setCancel_btn(Button b) {
this.cancel_btn = b;
}

private Label label1 = new Label();

public Label getLabel1() {
return label1;
}

public void setLabel1(Label l) {
this.label1 = l;
}

private Label label2 = new Label();

public Label getLabel2() {
return label2;
}

public void setLabel2(Label l) {
this.label2 = l;
}

private CachedRowSetDataProvider accountDataProvider = new CachedRowSetDataProvider();

public CachedRowSetDataProvider getAccountDataProvider() {
return accountDataProvider;
}

public void setAccountDataProvider(CachedRowSetDataProvider crsdp) {
this.accountDataProvider = crsdp;
}

private Label address2_lbl = new Label();

public Label getAddress2_lbl() {
return address2_lbl;
}

public void setAddress2_lbl(Label l) {
this.address2_lbl = l;
}

private TextField address2_txt = new TextField();

public TextField getAddress2_txt() {
return address2_txt;
}

public void setAddress2_txt(TextField tf) {
this.address2_txt = tf;
}

private TextField paymentMethod_txt = new TextField();

public TextField getPaymentMethod_txt() {
return paymentMethod_txt;
}

public void setPaymentMethod_txt(TextField tf) {
this.paymentMethod_txt = tf;
}

private TextField cardType_txt = new TextField();

public TextField getCardType_txt() {
return cardType_txt;
}

public void setCardType_txt(TextField tf) {
this.cardType_txt = tf;
}

private TextField month_txt = new TextField();

public TextField getMonth_txt() {
return month_txt;
}

public void setMonth_txt(TextField tf) {
this.month_txt = tf;
}

private TextField year_txt = new TextField();

public TextField getYear_txt() {
return year_txt;
}

public void setYear_txt(TextField tf) {
this.year_txt = tf;
}

private TextField accountNumber_txt = new TextField();

public TextField getAccountNumber_txt() {
return accountNumber_txt;
}

public void setAccountNumber_txt(TextField tf) {
this.accountNumber_txt = tf;
}

private ImageHyperlink header_img = new ImageHyperlink();

public ImageHyperlink getHeader_img() {
return header_img;
}

public void setHeader_img(ImageHyperlink ih) {
this.header_img = ih;
}

private ImageComponent sidebar_img = new ImageComponent();

public ImageComponent getSidebar_img() {
return sidebar_img;
}

public void setSidebar_img(ImageComponent ic) {
this.sidebar_img = ic;
}

private ImageComponent footer_img = new ImageComponent();

public ImageComponent getFooter_img() {
return footer_img;
}

public void setFooter_img(ImageComponent ic) {
this.footer_img = ic;
}

private DropDown country_drp = new DropDown();

public DropDown getCountry_drp() {
return country_drp;
}

public void setCountry_drp(DropDown dd) {
this.country_drp = dd;
}

private DropDown state_drp = new DropDown();

public DropDown getState_drp() {
return state_drp;
}

public void setState_drp(DropDown dd) {
this.state_drp = dd;
}

private TextField emailAddress_txt = new TextField();

public TextField getEmailAddress_txt() {
return emailAddress_txt;
}

public void setEmailAddress_txt(TextField tf) {
this.emailAddress_txt = tf;
}

//

private RowKey acctRowKey = null;
/**
* Construct a new Page bean instance.
*/
public Account() {
}

/**
* Callback method that is called whenever a page is navigated to,
* either directly via a URL, or indirectly via page navigation.
* Customize this method to acquire resources that will be needed
* for event handlers and lifecycle methods, whether or not this
* page is performing post back processing.
*
* Note that, if the current request is a postback, the property
* values of the components do not represent any
* values submitted with this request. Instead, they represent the
* property values that were saved for this view when it was rendered.
*/
public void init() {
// Perform initializations inherited from our superclass
super.init();
// Perform application initialization that must complete
// *before* managed components are initialized
// TODO - add your own initialiation code here

//
// Initialize automatically managed components
// *Note* - this logic should NOT be modified
try {
_init();
} catch (Exception e) {
log("Page3 Initialization Failure", e);
throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
}

//
// Perform application initialization that must complete
// *after* managed components are initialized
// TODO - add your own initialization code here
}

/**
* Callback method that is called after the component tree has been
* restored, but before any event processing takes place. This method
* will only be called on a postback request that
* is processing a form submit. Customize this method to allocate
* resources that will be required in your event handlers.
*/
public void preprocess() {
}

/**
* Callback method that is called just before rendering takes place.
* This method will only be called for the page that
* will actually be rendered (and not, for example, on a page that
* handled a postback and then navigated to a different page). Customize
* this method to allocate resources that will be required for rendering
* this page.
*/
public void prerender() {

acctRowKey = getSessionBean1().getAcctRowKey();
accountDataProvider.setCursorRow(acctRowKey);

}

/**
* Callback method that is called after rendering is completed for
* this request, if init() was called (regardless of whether
* or not this was the page that was actually rendered). Customize this
* method to release resources acquired in the init(),
* preprocess(), or prerender() methods (or
* acquired during execution of an event handler).
*/
public void destroy() {
accountDataProvider.close();
}

/**
* Return a reference to the scoped data bean.
*/
protected RequestBean1 getRequestBean1() {
return (RequestBean1)getBean("RequestBean1");
}

/**
* Return a reference to the scoped data bean.
*/
protected ApplicationBean1 getApplicationBean1() {
return (ApplicationBean1)getBean("ApplicationBean1");
}

/**
* Return a reference to the scoped data bean.
*/
protected SessionBean1 getSessionBean1() {
return (SessionBean1)getBean("SessionBean1");
}

public void paymentMethod_txt_processValueChange(ValueChangeEvent event) {
// TODO: Replace with your code

}

public String submit_btn_action() {
// TODO: Process the action. Return value is a navigation
// case name where null will return to the same page.

acctRowKey = getSessionBean1().getAcctRowKey();
accountDataProvider.setCursorRow(acctRowKey);

String accountNumberText = (String) accountNumber_txt.getText();

try {

acctRowKey = accountDataProvider.findFirst("account.num",accountNumberText);
accountDataProvider.setCursorRow(acctRowKey);

RowKey newRowKey = accountDataProvider.getCursorRow();
accountDataProvider.commitChanges();
accountDataProvider.refresh();

} catch (Exception ex) {
log("Error Description", ex);
error(ex.getMessage());
}
return null;

}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
dwallin2
Offline
Joined: 2007-10-25
Points: 0

I'm sorry, I wasn't expecting the code format to be screwed up.

Anyway, if someone could just explain to me how I can properly edit a field in a selected rowkey that already has existing values, that'd be great.

Thanks