Java Ninja Chronicles By Norris Shelton

Things I learned in the pursuit of code

It has been a while since I wrote a form. I kept posting data even though the Jquery Validation fired and was not valid. I forgot that you have to check for a valid form. I also learned that you can also add a submit handler to the validation call. Here is what the completed validation and ajax call looked like. Notice that in this form, I disable the submit button belonging to the form just before the ajax request is sent.

$(document).ready(function () {
    $("#expungementForm").validate({
        submitHandler: function(form) {
            $.ajax({
                cache: false,
                type: "POST",
                url: form.action,
                data: $(form).serialize(),
                beforeSend: function (jqXHR, settings) {
                    $('input[type="submit"]', form).attr('disabled', true);
                },
                success: function (data) {
                    $('#expungeResult').html(data)
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    $('#expungeResult').html(textStatus).append("...").append(errorThrown).css('color', 'red')
                }});
            return false;
        }
    });
});

June 13th, 2012

Posted In: HTML, javascript, JQuery, json

Tags: , , , , ,

Leave a Comment

Maven is geared around the concept of producing one artifact per Maven module. If you need to have a Maven module produce multiple artifacts, you can use the Maven Assembly plugin to accomplish your goals. If you need the maven assembly plugin to produce two artifacts, it must be with two separate execution blocks. One execution block creates one artifact, like one module typically produces one artifact.

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <id>client</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <finalName>${project.artifactId}-${project.version}</finalName>
                            <appendAssemblyId>true</appendAssemblyId>
                            <descriptors>
                                <descriptor>src/main/assembly/client.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                    <execution>
                        <!-- NOTE This is for backwards compatibility with the original builds-->
                        <id>client-no-version</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <finalName>licensemgr-3.0-client</finalName>
                            <appendAssemblyId>false</appendAssemblyId>
                            <descriptors>
                                <descriptor>src/main/assembly/client.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

June 12th, 2012

Posted In: Maven

Tags: ,

Leave a Comment

This is a typical Jquery ajax request.

$.get(this.action, $(this).serialize(), function (data) {
    $('#expungeResult').html(data);
})

This works great until you realize that it is really taking data from a form and is changing data on the site. It should be a post, but it was mistakenly made with a get. The controller method was defined as POST only. This causes the an error in the server log.

Request method ‘GET’ not supported

Jquery $.get and $.post do support chaining .success(), .error() and .complete() methods. Unfortunately, they don’t have parameters.

$.ajax has what you need, at the expense of a more verbose declaration.

$.ajax({
    cache: false,
    type: "GET",
    url: this.action,
    data:$(this).serialize(),
    success: function (data) {
        $('#expungeResult').html(data)
    },
    error: function (jqXHR, textStatus, errorThrown) {
        $('#expungeResult').html(textStatus).append("...").append(errorThrown).css('color', 'red')
    }}
);

Now, “error…Request method ‘GET’ not supported” is displayed in red in my display area. An ugly message, but at least the user will not keep clicking the button because it looks like nothing happened.

June 12th, 2012

Posted In: javascript, JQuery

Tags:

Leave a Comment

LinkedIn Auto Publish Powered By : XYZScripts.com