This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Struts and the fly likes Handling validations of multiple forms in single jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Handling validations of multiple forms in single jsp" Watch "Handling validations of multiple forms in single jsp" New topic
Author

Handling validations of multiple forms in single jsp

Janarthanan Chandrasekaran
Greenhorn

Joined: Jan 02, 2012
Posts: 1
I have a jsp that handles two forms. The jsp goes like this. " If the user clicks on the "manual" radio button, the "createHolidayAction" will be invoked on pressing the "save" button of that form, and if the user clicks on the "file upload' radio button , the "uploadHolidayAction" will be invoked on pressing the "upload" button on that form.

Now when the user submits the "manual" form it is checked for some validations. On failure the input jsp is retained with the error messages.

The error messages is visible on both the forms of the jsp. How to hide the error messages on another form..? Say if validation fails on "manual" form , the error message should be visible only on that form. (but when i click the "file upload" radio button, the error message of "manual" is also still visible)

the code for upload_holiday_main.jsp is here...

<script src="datetimepicker_css.js"></script>
<script type="text/javascript">
function chooseEntryMethod(hiddenbox) {
var box = document.getElementsByTagName("div");
for(var x=0; x<box.length; x++) {
name = box[x].getAttribute("name");
if (name == 'entryMethod') {
if (box[x].id == hiddenbox) {
if (box[x].style.display == 'block') {
box[x].style.display = 'none';
}
else {
box[x].style.display = 'block';
}
}else {
box[x].style.display = 'none';
}
}
}
}</script>
</head>



<div id="template" style="padding-bottom:1%;">
<div id="tagline">
<p><bean:message key="ems.hdlabel.holidayconfig" /></p>
</div>


<input type="radio" checked="checked" name="method" value="Manual" id="manual" onclick="javascript:chooseEntryMethod('manual');"/><span style="font-family:Tahoma;font-size:13px;color:#000000;border-style:none;">Manual</span>
<input type="radio" name="method" value="File Upload" id="fileupload" onclick="javascript:chooseEntryMethod('fileupload');"/><span style="font-family:Tahoma;font-size:13px;color:#000000;border-style:none;">File Upload</span>


<div class="error">
<html:errors />
<html:errors name="dateexists" />
</div>

<html:form action="/createHolidayAction">

<div class="uploadlayout" name="entryMethod" id="manual" style="display:block;">

<label style="width:100px;">
<bean:message key="ems.hdlabel.date" />
<span id="mandatory"> <bean:message key="ems.hdlabel.mandatory" /> </span>
</label>
<html:text style="width:200px;" readonly="true" styleId="dp" property="hcDate" />
<img style="margin-right:55%;" src="images/datepicker.png" class="datepicker" onclick="javascript:NewCssCal('dp')" style="cursor:pointer;" />



<label style="width:100px;">
<bean:message key="ems.hdlabel.comments" />
</label>
<html:textarea property="comments" />



<html:submit property="saveholiday" style="width:50px;margin-left:12.5%;" styleId="formbuton" styleClass="save" value=" Save " />
<html:cancel style="width:54px;margin-left:2%;padding-left:1%;" styleId="formbuton" styleClass="cancel" value=" Cancel " />

</div>
</html:form>

<html:form action="/uploadHolidayAction" method="post" enctype="multipart/form-data">


<div class="uploadlayout" name="entryMethod" id="fileupload" style="display:none;">

<p style="margin-left:8%;" class="title"><bean:message key="ems.hdlabel.uploadtitle" /></p>


<label style="width:120px;">
<bean:message key="ems.hdlabel.upload" />
<span id="mandatory"> <bean:message key="ems.hdlabel.mandatory" /> </span>
</label>
<html:file property="holidayFile" styleClass="cancel"/>



<html:submit style="width:54px;margin-left:15%;" styleId="formbuton" styleClass="save" value=" Upload " />
<html:cancel style="width:54px;margin-left:2%;" styleId="formbuton" styleClass="cancel" value=" Cancel " />



<label style="width:130px;">
<bean:message key="ems.hdlabel.downloadtemplate" />
</label>
<a href="SampleCSV.csv" target="_blank"><img style="padding-left:0%;width:120px;height:35px;" src="images/d2.png" title="Click to download CSV template file" /></a>

</div>
</html:form>


the struts-config.xml is as below (only snippets are posted)

<action path="/createHolidayAction"
type="com.stg.ems.actions.EMSCreateHolidayAction"
name="createHolidayForm" validate="true" input="upload_holiday.jsp"
cancellable="true" scope="request">

<forward name="success" redirect="true"
path="/listHolidays.do" />

</action>

<action path="/uploadHolidayAction" name="uploadHolidayForm"
type="com.stg.ems.actions.EMSUploadHolidayAction"
validate="true" input="upload_holiday.jsp" cancellable="true">
<forward name="success" redirect="true" path="/listHolidays.do"/>
</action>





 
 
subject: Handling validations of multiple forms in single jsp
 
Similar Threads
jQuery not working on page
Strange IllegalArgumentException: No bean specified
Need help for Check Box Validation in struts1.2 without using javascript
Help ASAP!
Clearing h:inputText value