• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Not able to save the details of a textbox in DB

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Currently in our application we have a client form, where we are providing email ids in one of the input field "Email". We can provide multiple email ids in the same filed using comma(,) separated. Then clicking on "update" button saves all the email ids in the database.

Now as a part of new requirement we want each email address to be shown in different text box. for example if any user has 5 email ids saved in the database, he can see each of his email ids in a separate textbox.
I am able to retrieve these emailds from the database in a separate textbox but if i want to edit those email ids in each text box and subsequently clicking on "update" button, the same is not updated in the DB table i .e retrieving is working fine but not saving functionality.

Database model will remain same i.e all the emails saved there will be separted by comma (,)

code in the form.java (created a list of object rather than singel "email" object)

private List<String> email; (earlier it was "private String email" )


code in the AdminDAOJDBC.java

public boolean updateClient(final AdminForm client) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Update client: " + client);
}

final Object params[] = new Object[] {client.getName(),
StringUtils.isBlank(client.getStreet()) ? null : client.getStreet(),
StringUtils.isBlank(client.getBox()) ? null : client.getBox(),
StringUtils.isBlank(client.getZipCode()) ? null : client.getZipCode(),
StringUtils.isBlank(client.getCity()) ? null : client.getCity(),
StringUtils.isBlank(client.getCountry()) ? null : client.getCountry(),
StringUtils.isBlank(client.getReportingFrequency()) ? null : client.getReportingFrequency(),
StringUtils.isBlank(client.getReportingCurrency()) ? null : client.getReportingCurrency(),
StringUtils.isBlank(getEmails(client.getEmail())) ? null : getEmails(client.getEmail()),
client.isExcelAttachFlag() ? "Y" : "N",
client.getSenderId(),
client.getClientShortCode()};
final StringBuilder sql = new StringBuilder(164);
sql.append("UPDATE CVR_CLIENT ");
sql.append("SET NAME = ?, ");
sql.append("STREET_NUMBER = ?, ");
sql.append("BOX = ?, ");
sql.append("ZIPCODE = ?, ");
sql.append("CITY = ?, ");
sql.append("COUNTRY_CODE = ?, ");
sql.append("REPORTING_FREQUENCY = ?, ");
sql.append("REPORTING_CURRENCY = ?, ");
sql.append("EMAIL = ?, ");
sql.append("EXCEL_ENABLED = ?,");
sql.append("SENDER_ID = ? ");
sql.append("WHERE INTERVENIENT_PSP = ?");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("SQL: " + sql);
LOGGER.debug("params: " + Arrays.toString(params));
}

int numRowsAffected = -1;
numRowsAffected = this.jdbcTemplate.update(sql.toString(), params);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Number of rows updated: " + numRowsAffected);
}

return numRowsAffected == 1;
}

// method created by me to save the list of emails in the database using comma separated.

private String getEmails(List<String> email) {
StringBuilder mergeEmailId=new StringBuilder();
for(String singleMail: email){
mergeEmailId.append(singleMail);
mergeEmailId.append(",");
}
return String.valueOf(mergeEmailId).substring(0,mergeEmailId.length()-1);
}



Code in the Controller class.

/**
* Handle client edit.
*
* @param form the form
*/
private void handleClientEdit(final AdminForm form) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Handle edit of client with short code: " + form.getClientShortCode());
}

// Get client to edit from search result
final List<Client> searchResult = form.getSearchResult();
for (final Client client : searchResult) {
if (StringUtils.equalsIgnoreCase(form.getClientShortCode(), client.getShortCode())) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Found client in result: " + client);
}
form.setName(client.getName());
form.setStreet(client.getStreetAndNumber());
form.setBox(client.getBox());
form.setZipCode(client.getZipCode());
form.setCity(client.getCity());
form.setCountry(client.getCountry());
form.setEmail(getEmails(client.getEmail()));
form.setSenderId(client.getSender());
form.setReportingFrequency(client.getReportingFrequency());
form.setReportingCurrency(client.getReportingCurrency());
form.setAction(AdminConstants.ACTION_UPDATE);
LOGGER.info("ExcelAttachFlag"+client.isExcelAttachFlag());
form.setExcelAttachFlag(client.isExcelAttachFlag());
break;
}
}
}

/**
* Handle client update.
*
* @param form the form
*/
private void handleClientUpdate(final AdminForm form) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Handle update of client: " + form);
}
boolean success = false;
String shortCode = form.getClientShortCode();
try {
LOGGER.info("while updating excel flag "+form.isExcelAttachFlag());
success = this.adminService.updateClient(form);
//form.setRemark("Successfully updated.");
form.setRemark("Successfully updated client with short code '" + form.getClientShortCode() + "'.");
PortletAuditUtil.log(form.getPortalUserName(), PortletAuditConstants.CVRADM_CL_UPD);
} catch (final Exception e) {
LOGGER.warn("An error occurred while updating client: " + e);
form.setRemark("An error occurred while updating client with short code '" + form.getClientShortCode() + "'.");
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Client successfully updated: " + success);
}
form.clearUpdateFields();
this.handleClientSearch(form);
form.setClientShortCode(shortCode);
this.handleClientEdit(form);

}

// method writen by me to retrieve all the stored emails from the database in the form of list, and then splitting it so that we will get a separate textbox for each emails

private List<String> getEmails(String emails) {
List<String> emailList=new ArrayList<String>(Arrays.asList(emails.split(","))); return emailList;
}

code in the VM (velocity) file for view :

<tr class="GMsearchFormA">
<td class="GMsearchstCol" nowrap="nowrap">#springMessage("label.email"):</td>
<td class="GMsearchstCol" nowrap="nowrap">#springFormInput("adminForm.email" ${adminForm.email} "class='GMtradeSearch' size='80'")#springMessage("label.emailMessage")</td>

</tr>

I have changed this file to in the below way to retrieve the multiple email ids in a separate text box :-

<tr class="GMsearchFormA">
<td class="GMsearchstCol" nowrap="nowrap">#springMessage("label.email"):</td>
#foreach ($emailId in $adminForm.email)
#if ($velocityCount > 1)
<tr class="GMsearchFormA">
<td class="GMsearchstCol" nowrap="nowrap"></td>
<td class="GMsearchstCol" nowrap="nowrap">
<input type="text" name="${adminForm.email}.get($velocityCount).value" value="$!{emailId}" class='GMtradeSearch' size='80'" id="${adminForm.email}.get($velocityCount).value"/></td>
</tr>
#else
<td class="GMsearchstCol" nowrap="nowrap">
<input type="text" name="${adminForm.email}.get($velocityCount).value" value="$!{emailId}" class='GMtradeSearch' size='80'" id="${adminForm.email}.get($velocityCount).value" /></td>
#end
#end
</tr>

Javascript called while clicking on "update" button :- (this function is called in one of the vm file)

function update() {
var frm = document.getElementById('adminForm');
frm.action.value = 'update';
submitForm(frm);
}

Using these code i can see different email text boxes in the view page but updating any email id in these boxes and subsequently clickinmg on "update" button , the emails are not saved in the Database. Please help
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic