This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts Validation Empty alert Box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Validation Empty alert Box" Watch "Struts Validation Empty alert Box" New topic
Author

Struts Validation Empty alert Box

leela addagulla
Greenhorn

Joined: Mar 31, 2008
Posts: 10
Hello,

I am using Struts Validation. The validation is working properly. But I get an empty Alert box with no message. But i see that the focus is set to the field left empty.
Can anyone please help me with this?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Not without any code or configs.
leela addagulla
Greenhorn

Joined: Mar 31, 2008
Posts: 10
Hello David,

Please find the Files Content below:

StrutsConfig.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources/>

<form-beans>
<form-bean name="LoginForm" type="org.suiteaccess.form.LoginForm"/>
<form-bean name="MCStatusReportForm" type="org.apache.struts.action.DynaActionForm"/>
<form-bean name="memberCompanySelectForm" type="org.suiteaccess.form.MemberCompanySelectForm"/>
<form-bean name="MemberCompanyForm" type="org.suiteaccess.form.MemberCompanyForm"/>
</form-beans>

<global-exceptions/>
<global-forwards/>
<action-mappings>
<action
path="/login"
type="org.suiteaccess.action.LoginAction"
name="LoginForm"
scope="request"
validate="true"
input="/login.jsp">
<forward name="success" path="/welcome.jsp"/>
<forward name="failure" path="/login.jsp"/>
</action>

<action
path="/logout"
type="org.suiteaccess.action.LogoutAction"
name="LoginForm"
scope="request">
<forward name="login" path="/login.jsp"/>
</action>

<action
path="/MemberCompanyAdd"
type="org.suiteaccess.action.MemberCompanyDetailAction"
name="MemberCompanyForm"
parameter="dispatch"
scope="request"
validate="true">
<forward name="form" path="/MemberCompanyDetail.jsp"/>
<forward name="added" path="/MemberCompanyDetail.jsp"/>
<forward name="editmode" path="/MemberCompanyDetail.jsp"/>
<forward name="delete" path="/MemberCompany.do"/>
</action>

<action
path="/MCStatusReport"
type="org.suiteaccess.action.MCStatusReportAction"
name="MCStatusReportForm"
scope="request"
validate="true">
<forward name="report" path="/MCStatusReport.jsp"/>
</action>

<action
path="/MemberCompany"
type="org.suiteaccess.action.MemberCompanyAction"
name="memberCompanySelectForm"
scope="session">
<forward name="select" path="/MemberCompanySelection.jsp"/>
</action>
</action-mappings>

<message-resources parameter="MessageResources" />

<!-- Validator plugin -->
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>

</struts-config>

The JSP: MemberCompanyDetail.jsp

<%@ taglib uri="/WEB-INF/struts-bean" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic" prefix="logic" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="my" %>

<html:html locale="true">
<head>
<title>LOGIN SUITE ACCESS</title>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<script>

function floorSelect(checkBox){
var controlName=checkBox.name+"Floors";
if(checkBox.checked)
document.getElementById(controlName).disabled=false;
else{
document.getElementById(controlName).disabled=true;
document.getElementById(controlName).value='';
}
}

function validate(){
document.forms[0].dispatch.value='save'
var value= document.getElementById('accountManager').value;
if(value==null)
return false;
else
return true;
}
</script>
<html:javascript formName="MemberCompanyForm"/>
</head>

<body bgcolor="white">

<logic:empty name="user">
<jsp:forward page="/login.jsp"/>
</logic:empty>

<%@ include file="header.html" %>
<html:form action="/MemberCompanyAdd" method="post" enctype="multipart/form-data" onsubmit="return validateMemberCompanyForm(this)">

<table>
<%
String status="";
String industry="";
String contactType="";
String user="";
if(request.getAttribute("selectedStatus")!=null)
status=request.getAttribute("selectedStatus").toString();
if(request.getAttribute("selectedIndustry")!=null)
industry=request.getAttribute("selectedIndustry").toString();
if(request.getAttribute("selectedUser")!=null)
user=request.getAttribute("selectedUser").toString();
%>
<tr><td >* indicates Required Fields</td></tr>
<tr><td >*Company Name:</td><td><html:text styleId="search-text" property="companyName"/></td></tr>
<tr><td >*Industry:</td>
<td>
<html:select property="industry" value="<%=industry %>">
<htmlptions collection="industries" property="industryId" labelProperty="industryName" />
</html:select>
</td></tr>
<tr><td >*Company Status:</td>
<td>
<html:select property="companyStatus" value="<%=status %>">
<htmlptions collection="companyStatuses" property="id" labelProperty="description" />
</html:select>
</td>
</tr>

<tr><td>
<table>
<tr><td class="title">Contact Details</td></tr>
<tr><td >Contact Type:</td>
<td>
<html:select property="contactType">
<htmlptions collection="contactTypes" property="contactTypeId" labelProperty="description" />
</html:select>
</td>
</tr>
<tr><td >Contact First Name:</td><td><html:text styleId="search-text" property="contactFirstName"/></td></tr>
<tr><td >Contact Last Name:</td><td><html:text styleId="search-text" property="contactLastName"/></td></tr>
<tr><td >Salutation</td><td><html:text styleId="search-text" property="salutation"/></td></tr>
<tr><td >WorkPhone</td><td><html:text styleId="search-text" property="workPhone"/></td></tr>
<tr><td >AlternatePhone</td><td><html:text styleId="search-text" property="alternatePhone"/></td></tr>
<tr><td >CellPhone</td><td><html:text styleId="search-text" property="cellPhone"/></td></tr>
<tr><td >FaxNumber</td><td><html:text styleId="search-text" property="faxNumber"/></td></tr>
<tr><td >ContactEmail</td><td><html:text styleId="search-text" property="contactEmail"/></td></tr>
</table>
</td></tr>


<tr>
<td>
<table>
<tr><td class="title">Address Details</td></tr>
<tr><td >HeadQuarters:</td><td><html:radio property="addressType" value="addressOne"/></td></tr>
<tr><td >Address1:</td><td><html:text styleId="search-text" property="addressOneOne"/></td></tr>
<tr><td >Address2:</td><td><html:text styleId="search-text" property="addressOneTwo"/></td></tr>
<tr><td >Address3:</td><td><html:text styleId="search-text" property="addressOneThree"/></td></tr>
<tr><td >City</td><td><html:text styleId="search-text" property="cityOne"/></td></tr>
<tr><td >State</td><td><html:text styleId="search-text" property="stateOne"/></td></tr>
<tr><td >ZipCode</td><td><html:text styleId="search-text" property="zipOne"/></td></tr>
<tr><td >Country</td><td><html:text styleId="search-text" property="countryOne"/></td></tr>
<tr><td >Province</td><td><html:text styleId="search-text" property="provinceOne"/></td></tr>
</table>
</td>
<td>
<table>
<tr><td>
</td></tr>
<tr><td >HeadQuarters:</td><td><html:radio property="addressType" value="addressTwo"/></td></tr>
<tr><td >Address1:</td><td><html:text styleId="search-text" property="addressTwoOne"/></td></tr>
<tr><td >Address2:</td><td><html:text styleId="search-text" property="addressTwoTwo"/></td></tr>
<tr><td >Address3:</td><td><html:text styleId="search-text" property="addressTwoThree"/></td></tr>
<tr><td >City</td><td><html:text styleId="search-text" property="cityTwo"/></td></tr>
<tr><td >State</td><td><html:text styleId="search-text" property="stateTwo"/></td></tr>
<tr><td >ZipCode</td><td><html:text styleId="search-text" property="zipTwo"/></td></tr>
<tr><td >Country</td><td><html:text styleId="search-text" property="countryTwo"/></td></tr>
<tr><td >Province</td><td><html:text styleId="search-text" property="provinceTwo"/></td></tr>
</table>
</td>
</tr>

<tr><td >*StartDate:</td><td><html:text styleId="search-text" property="startDate"/></td></tr>
<tr><td >Total Employees in NY Office:</td><td><html:text styleId="search-text" property="employeeCount"/></td></tr>
<tr><td >Total Male Employees:</td><td><html:text styleId="search-text" property="maleEmployeeCount"/></td></tr>
<tr><td >Total Female Employees:</td><td><html:text styleId="search-text" property="femaleEmployeeCount"/></td></tr>
<tr><td >Average Employee Age:</td><td><html:text styleId="search-text" property="avgAge"/></td></tr>
<tr><td >How many Floors do you occupy in your building:</td><td><html:text styleId="search-text" property="floorCount"/></td></tr>
<tr><td >How many Floors have Kitchens/pantries</td><td><html:text styleId="search-text" property="kitchenFloorCount"/></td></tr>
<tr><td >Which Floors</td><td><html:text styleId="search-text" property="kitchenFloors"/></td></tr>
<tr><td ><html:checkbox property="executiveKitchen" onchange="floorSelect(this)">Is there a separate Kitchen/Pantry for the Executive Team?</html:checkbox></td></tr>
<tr><td >Which Floors:</td><td><html:text styleId="search-text" styleId="executiveKitchenFloors" property="executiveKitchenFloors" /></td></tr>
<tr><td ><html:checkbox property="clientKitchen" onchange="floorSelect(this)">Is there a separate Kitchen/Pantry for the Clients/Visitors?:</html:checkbox></td></tr>
<tr><td >Which Floors:</td><td><html:text styleId="search-text" styleId="clientKitchenFloors" property="clientKitchenFloors" /></td></tr>
<tr><td ><html:checkbox property="restrooms" onchange="floorSelect(this)">Are there any private restrooms?:</html:checkbox></td></tr>
<tr><td >Which Floors:</td><td><html:text styleId="search-text" styleId="restroomsFloors" property="restroomFloors" /></td></tr>

<tr><td >*Upload Company Logo: </td><td><html:file styleId="search-text" property="companyLogo"/></td></tr>
<tr><td >Comments:</td><td><html:text styleId="search-text" property="comments"/></td></tr>

<tr><td >*Select the Account Manager:</td>
<td>
<html:select property="accountManager" styleId="accountManager" value="<%=user %>">
<htmlptions collection="users" property="userid" labelProperty="username" />
</html:select>
</td>
</tr>

</table>
<html:hidden property="dispatch"/>
<html:submit>Save</html:submit>
<%
if(session.getAttribute("editmode")!=null){
%>
<html:submit onclick="document.forms[0].dispatch.value='delete'">Delete</html:submit>
<%
}
%>

</html:form>
<%@ include file="footer.html" %>
</body>
</html:html>

Validation.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_1.dtd">

<form-validation>
<global>
</global>
<formset>
<form name="LoginForm">
<field property="username" depends="required">
<arg0 key="LoginForm.username"/>
</field>
<field property="password" depends="required">
<arg0 key="LoginForm.password"/>
</field>
</form>
<form name="MemberCompanyForm">
<field property="companyName" depends="required">
<arg0 key="MemberCompanyForm.companyName"/>
</field>
<field property="companyStatus" depends="required">
<arg0 key="MemberCompanyForm.companyStatus"/>
</field>
<field property="startDate" depends="required">
<arg0 key="MemberCompanyForm.startDate"/>
</field>
<field property="accountManager" depends="required">
<arg0 key="MemberCompanyForm.accountManager"/>
</field>
<field property="companyLogo" depends="required">
<arg0 key="MemberCompanyForm.companyLogo"/>
</field>
<field property="industry" depends="required">
<arg0 key="MemberCompanyForm.industry"/>
</field>
</form>
</formset>
</form-validation>

ActionForm:

package org.suiteaccess.form;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;
import org.apache.struts.upload.FormFile;
import org.apache.struts.validator.ValidatorActionForm;
import org.apache.struts.validator.ValidatorForm;

public class MemberCompanyForm extends ValidatorActionForm
{
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}

public String getCompanyStatus() {
return companyStatus;
}
public void setCompanyStatus(String companyStatus) {
this.companyStatus = companyStatus;
}
public String getContactType() {
return contactType;
}
public void setContactType(String contactType) {
this.contactType = contactType;
}
public String getContactFirstName() {
return contactFirstName;
}
public void setContactFirstName(String contactFirstName) {
this.contactFirstName = contactFirstName;
}
public String getContactLastName() {
return contactLastName;
}
public void setContactLastName(String contactLastName) {
this.contactLastName = contactLastName;
}
public String getSalutation() {
return salutation;
}
public void setSalutation(String salutation) {
this.salutation = salutation;
}
public String getWorkPhone() {
return workPhone;
}
public void setWorkPhone(String workPhone) {
this.workPhone = workPhone;
}
public String getAlternatePhone() {
return alternatePhone;
}
public void setAlternatePhone(String alternatePhone) {
this.alternatePhone = alternatePhone;
}
public String getCellPhone() {
return cellPhone;
}
public void setCellPhone(String cellPhone) {
this.cellPhone = cellPhone;
}
public String getFaxNumber() {
return faxNumber;
}
public void setFaxNumber(String faxNumber) {
this.faxNumber = faxNumber;
}
public String getContactEmail() {
return contactEmail;
}
public void setContactEmail(String contactEmail) {
this.contactEmail = contactEmail;
}
public String getAddressType() {
return addressType;
}
public void setAddressType(String addressType) {
this.addressType = addressType;
}
public String getAddressOneOne() {
return addressOneOne;
}
public void setAddressOneOne(String addressOneOne) {
this.addressOneOne = addressOneOne;
}
public String getAddressOneTwo() {
return addressOneTwo;
}
public void setAddressOneTwo(String addressOneTwo) {
this.addressOneTwo = addressOneTwo;
}
public String getAddressOneThree() {
return addressOneThree;
}
public void setAddressOneThree(String addressOneThree) {
this.addressOneThree = addressOneThree;
}
public String getCityOne() {
return cityOne;
}
public void setCityOne(String cityOne) {
this.cityOne = cityOne;
}
public String getStateOne() {
return stateOne;
}
public void setStateOne(String stateOne) {
this.stateOne = stateOne;
}
public String getZipOne() {
return zipOne;
}
public void setZipOne(String zipOne) {
this.zipOne = zipOne;
}
public String getCountryOne() {
return countryOne;
}
public void setCountryOne(String countryOne) {
this.countryOne = countryOne;
}
public String getProvinceOne() {
return provinceOne;
}
public void setProvinceOne(String provinceOne) {
this.provinceOne = provinceOne;
}
public String getAddressTwoOne() {
return addressTwoOne;
}
public void setAddressTwoOne(String addressTwoOne) {
this.addressTwoOne = addressTwoOne;
}
public String getAddressTwoTwo() {
return addressTwoTwo;
}
public void setAddressTwoTwo(String addressTwoTwo) {
this.addressTwoTwo = addressTwoTwo;
}
public String getAddressTwoThree() {
return addressTwoThree;
}
public void setAddressTwoThree(String addressTwoThree) {
this.addressTwoThree = addressTwoThree;
}
public String getCityTwo() {
return cityTwo;
}
public void setCityTwo(String cityTwo) {
this.cityTwo = cityTwo;
}
public String getStateTwo() {
return stateTwo;
}
public void setStateTwo(String stateTwo) {
this.stateTwo = stateTwo;
}
public String getZipTwo() {
return zipTwo;
}
public void setZipTwo(String zipTwo) {
this.zipTwo = zipTwo;
}
public String getCountryTwo() {
return countryTwo;
}
public void setCountryTwo(String countryTwo) {
this.countryTwo = countryTwo;
}
public String getProvinceTwo() {
return provinceTwo;
}
public void setProvinceTwo(String provinceTwo) {
this.provinceTwo = provinceTwo;
}
public String getStartDate() {
return startDate;
}
public void setStartDate(String startDate) {
this.startDate = startDate;
}
public String getEmployeeCount() {
return employeeCount;
}
public void setEmployeeCount(String employeeCount) {
this.employeeCount = employeeCount;
}
public String getMaleEmployeeCount() {
return maleEmployeeCount;
}
public void setMaleEmployeeCount(String maleEmployeeCount) {
this.maleEmployeeCount = maleEmployeeCount;
}
public String getFemaleEmployeeCount() {
return femaleEmployeeCount;
}
public void setFemaleEmployeeCount(String femaleEmployeeCount) {
this.femaleEmployeeCount = femaleEmployeeCount;
}
public String getAvgAge() {
return avgAge;
}
public void setAvgAge(String avgAge) {
this.avgAge = avgAge;
}
public String getFloorCount() {
return floorCount;
}
public void setFloorCount(String floorCount) {
this.floorCount = floorCount;
}
public String getKitchenFloorCount() {
return kitchenFloorCount;
}
public void setKitchenFloorCount(String kitchenFloorCount) {
this.kitchenFloorCount = kitchenFloorCount;
}
public String getKitchenFloors() {
return kitchenFloors;
}
public void setKitchenFloors(String kitchenFloors) {
this.kitchenFloors = kitchenFloors;
}
public boolean getExecutiveKitchen() {
return executiveKitchen;
}
public void setExecutiveKitchen(boolean executiveKitchen) {
this.executiveKitchen = executiveKitchen;
}
public String getExecutiveKitchenFloors() {
return executiveKitchenFloors;
}
public void setExecutiveKitchenFloors(String executiveKitchenFloors) {
this.executiveKitchenFloors = executiveKitchenFloors;
}
public boolean getClientKitchen() {
return clientKitchen;
}
public void setClientKitchen(boolean clientKitchen) {
this.clientKitchen = clientKitchen;
}
public String getClientKitchenFloors() {
return clientKitchenFloors;
}
public void setClientKitchenFloors(String clientKitchenFloors) {
this.clientKitchenFloors = clientKitchenFloors;
}
public boolean getRestrooms() {
return restrooms;
}
public void setRestrooms(boolean restrooms) {
this.restrooms = restrooms;
}
public String getRestroomFloors() {
return restroomFloors;
}
public void setRestroomFloors(String restroomFloors) {
this.restroomFloors = restroomFloors;
}
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}
public String getAccountManager() {
return accountManager;
}
public void setAccountManager(String accountManager) {
this.accountManager = accountManager;
}
public FormFile getCompanyLogo() {
return companyLogo;
}
public void setCompanyLogo(FormFile companyLogo) {
this.companyLogo = companyLogo;
}
private String companyName;
private String companyStatus;
private String contactType;
private String contactFirstName;
private String contactLastName;
private String salutation;
private String workPhone;
private String alternatePhone;
private String cellPhone;
private String faxNumber;
private String contactEmail;
private String addressType;
private String addressOneOne;
private String addressOneTwo;
private String addressOneThree;
private String cityOne;
private String stateOne;
private String zipOne;
private String countryOne;
private String provinceOne;
private String addressTwoOne;
private String addressTwoTwo;
private String addressTwoThree;
private String cityTwo;
private String stateTwo;
private String zipTwo;
private String countryTwo;
private String provinceTwo;
private String startDate;
private String employeeCount;
private String maleEmployeeCount;
private String femaleEmployeeCount;
private String avgAge;
private String floorCount;
private String kitchenFloorCount;
private String kitchenFloors;
private boolean executiveKitchen;
private String executiveKitchenFloors;
private boolean clientKitchen;
private String clientKitchenFloors;
private boolean restrooms;
private String restroomFloors;
private String comments;
private String accountManager;
private FormFile companyLogo;
private String industry;
private String dispatch;

public String getDispatch() {
return dispatch;
}
public void setDispatch(String dispatch) {
this.dispatch = dispatch;
}
public String getIndustry() {
return industry;
}
public void setIndustry(String industry) {
this.industry = industry;
}

}

Thanks,
Leela.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

...

Please UseCodeTags. Without them it's impossible to read anything.

Also, kindly post only the immediately relevant portions--600 lines of code and configs is a lot to wade through. Most problems can be reduced their core rather easily. In this case, for example, you could probably reproduce the issue with a very short example.
leela addagulla
Greenhorn

Joined: Mar 31, 2008
Posts: 10
Hi David,

Sorry for that messy Code.
Please find the relevant portions of the code in each of file below.

Struts-Config.xml:




Validation.xml



ActionForm:



The JSP: MemberCompanyDetail.jsp:


leela addagulla
Greenhorn

Joined: Mar 31, 2008
Posts: 10
I missed the errors.required property in the Application resources. Its working fine now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts Validation Empty alert Box
 
Similar Threads
Struts 2.1 form validation
validate only if field is visible?
Problem in validatation in text filed.
onblur on textbox is executing after closing the popup with X button
JavaScript Validation in Struts for Drop Down List