Wednesday, August 13, 2014

Submit a form with different actions using Jquery.


Here is the jsp:

<form:form id="clientLinkAbuseTypesForm" method="post"  commandName="clientLinkAbuseTypeForm">
...

<input type="submit" id="saveLinkAbuse" value="Save">
<input type="submit" id="cancelLinkAbuse"  value="Cancel" >

</form:form>

Here I have 2 different buttons each need to be calls different action and also need to send all form parameters. In this situation we need to change the form action's dynamically

Here I am explaining with the Jquery:

<script language="javascript">
$(document).ready(function()
{
   $("#saveLinkAbuse").click(function()
   {
        $("#clientLinkAbuseTypesForm").attr("action", "saveClientLinkAbuseTypes");
      // we can change the method type
     like $("#clientLinkAbuseTypesForm").attr("method", "get");  // or post here.
       $("#clientLinkAbuseTypesForm").submit();

   });

                 $("#cancelLinkAbuse").click(function()
    {
  
     $("#clientLinkAbuseTypesForm").attr("action", "cancelLinkAbuse");
        $("#clientLinkAbuseTypesForm").submit();

    });
}
);
</script>

From the above code you can observe the action attribute changing dynamically.. This will hit the corresponding action methods in controller with form fields...

Spring - multiple check boxes check

This Post explain you how to auto check the check box fields in Spring's at the time of loading page:


In controller you need to set the selected categories:

clientLinkAbuseTypesForm.setSelectedCategories(new Long{10,11..etc});

In Jsp page:
<c:forEach items="${displayGroup.value }" var="cateogryRec" varStatus="rec" >
<form:checkbox path="selectedCategories" value="${cateogryRec.key }" /><span id="Name"><c:out value="${cateogryRec.value }"/></span></td>


Here selectedCategories is the  Long[] selectedCategories of form ; Which contains the check box values which to make checked=true.

The spring will take care of checked=true .

Maven cobertura integration for JUNIT code coverage report

Add the below code inside the pom.xml

This should be under build tag
<build>
....
       <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
                                <version>2.6</version>
<configuration>
<check></check>
<formats>
<format>html</format>
<format>xml</format>
</formats>
<instrumentation>
<ignores>
<!-- <ignore>com.cscinfo.dc.triage.solr.*</ignore> -->
</ignores>
<excludes>
                                                     <!--This is place where we can ignore the list of class which we really don't require junits -->
<exclude>com/cscinfo/dc/triage/solr/*.class</exclude>
</excludes>

</instrumentation>
</configuration>
</plugin>
Under the report tag add the below code
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.6</version>
</plugin>
</plugins>
</reporting>

To generate the cobertura report run
mvn cobertura:cobertura
This will generate the html report under target/site/cobertura/index.html.