Struts 2 supports DWR/Dojo plugin for AJAX and other JavaScript. It also has a plugin for jQuery. But as a developer, I feel that using the plugins will couple the front-end and plugin more tightly. If you want to avoid it, we can write our own custom JavaScript AJAX methods. But the drawback is more coding. Plus point is full control is with you and no coupling with any plugin.

In this example, I am trying to do an AJAX validation to a form with normal jQuery.

The key changes in configurations are:

  1. Add jsonValidationWorkflowStack interception to the action class in struts.xml
  2. Add these 2 hidden variables inside your form and set them to true
    1. struts.enableJSONValidation
    2. struts.validateOnly
  3. Remove your normal <s:submit/> button or override its onsubmit event to do your AJAX things.

Step: 1 – Add jsonValidationWorkflowStack interception to the action class in struts.xml

      <action name=...>
            <interceptor-ref name="jsonValidationWorkflowStack" />
            <result name="input">....</result>
        </action>

Step: 2 – Adding hidden variables to the form

    <s:form action="login" id="submitForm">
        <legend>Login</legend>
        <s:textfield name="username" />
        <s:password name="password" />
        <s:hidden name="struts.enableJSONValidation" value="true"></s:hidden>
        <s:hidden name="struts.validateOnly" value="true"></s:hidden>
        <input type="button" id="submitLogin" />
    </s:form>

Step: 2 – Remove your normal <s:submit/> button or override its onsubmit event

Here I am using a normal button for simplicity.

<input type="button" id="submitLogin" />

And this is the JavaScript that does the AJAX Submission.

    $(document).ready(
    function () {
        $("#submitLogin").click(
        function () {
            $.post($("#submitForm").attr("action"), $("#submitForm").serialize(), function (data) {
                //Here the data will be a json.
                //Parse the json and implement the validation error logic.
            });
        });
    });

Liferay has a great architecture with almost every detail covered, mainly embracing the open standards.
If you come across any Liferay portal with no search feature in it(Or even your own portal), you can use the Liferay’s Open search implementation for searching content.

The default open search description xml is located in this location:
http://www.liferay.com/c/search/open_search_description.xml

From this URL, you can see that there are 3 types of results(http://www.opensearch.org/Specifications/OpenSearch/1.1#OpenSearch_description_document) available. RSS, ATOM and text results.
So the normal search URL for RSS will be like this:

http://www.liferay.com/c/search/open_search?keywords={searchTerms}&p={startPage?}&c={count?}&format=rss

In a broader sense,
http://{YOUR_URL}/c/search/open_search?keywords={searchTerms}

Note:
Sometimes you may come across missing content, this may because the liferay server has not indexed all content in database. If you the admin of your portal, Goto Control Panel -> Server -> Server Administration -> Reindex all search indexes.

This is a quick step by step setup for libharu static libraries in Xcode 3.2 for pdf generation. Initially I planned to use coregraphics for pdf generation but some forum discussions lead me to use libharu since coregraphics generated pdf has some problems in some pdf clients.

I had difficulties in setting up the static libraries since this is my first static library set up. At last I followed these steps to make it work. Hope it will help some people.

1. Get the libharu demo project from github project iPhonePDF
2. Copy the support directory and its files from the demo project into your project in Xcode. When you copy make sure “Copy items into destination groups folderchecked and under “Add To Targetsuncheck the project build.


3. Right click on targets from Groups & Files panel and choose Add -> New Target -> Static Library. Name it png. Repeat it to create another library named haru.

4. Each static library has 3 sections Copy Headers, Compile Sources and Link Binary With Libraries. Now we need to copy the header files (.h) to the Copy Headers and the class files(.c) to the Compile Sources from libpng & libharu subdirectories(from libharu support files) to respectively png and haru static libraries.

After copying files for both static library targets, the project will be like this:

5. Now we need to add Dependencies and link libraries to the haru target. Set “png” static library as Direct Dependancy and libpng.a, libz.dylib as linked libraries to the haru target. (Double click on the target to open it)

6. Now the project is setup with libharu and its good to go now.

PS: Looking for an demo project here? Duh, its gonna be the same demo project as the one downloaded github. But look for my next post which is about iPhone pdf templating.

References:

http://stackoverflow.com/questions/3674858/setting-up-lib-haru-in-an-iphone-project-for-pdf-creation

http://www.iphonedevsdk.com/forum/iphone-sdk-development/15505-pdf-font-problem-cant-get-cids-glyphs.html

© 2012 Techlona Suffusion theme by Sayontan Sinha

Switch to our mobile site