New Struts2 Bootstrap Plugin released

I have just released my first GIT based Project at Google Code. Thanks to IntelliJ IDEA for the great GIT Integration.

This Struts2 Bootstrap Plugin is for an easy Integration of Twitter Bootstrap into an Bootstrap based Struts2 Webapp. It provides a Head Tag which loads necessary resources and a new theme for Struts2 Tags. A new Struts2 Bootstrap Plugin Showcase provides a short introduction how to use this Plugin.

Steps to use it in your Project:

1. Add the jar

To use this plugin you need to copy the struts2-bootstrap-plugin.jar into your WEB-INF/lib path. A maven Integration is following soon.

2. Add the Head Tag to your JSP

To load the required CSS Styles and JavaScript Resources you need to add the Head Tag to your html head area like following Example.

<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sb" uri="/struts-bootstrap-tags" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>MyApp Title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 
    <!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
    <!--[if lt IE 9]>
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
 
    <sb:head/>
</head>
<body>
...
</body>
</html>

3. Using the Form Tags

Now you are able to use the form theme, simple by adding the theme="bootstrap" attribute to your tag.

    <s:actionerror theme="bootstrap"/>
    <s:actionmessage theme="bootstrap"/>
    <s:fielderror theme="bootstrap"/>
 
 
    <s:form action="index" enctype="multipart/form-data" theme="bootstrap" cssClass="form-horizontal"
            label="A sample horizontal Form">
        <s:textfield
                label="Name"
                name="name"
                tooltip="Enter your Name here"/>
 
        <s:textfield
                label="Textfield with Error"
                name="error"/>
 
        <s:textarea
                tooltip="Enter your Biography"
                label="Biography"
                name="bio"
                cols="20"
                rows="3"/>
 
        <s:select
                tooltip="Choose Your Favourite Color"
                label="Favorite Color"
                list="{'Red', 'Blue', 'Green'}"
                name="favouriteColor"
                emptyOption="true"
                headerKey="None"
                headerValue="None"/>
 
        <s:checkboxlist
                tooltip="Choose your Friends"
                label="Friends"
                list="{'Wes', 'Patrick', 'Jason', 'Jay', 'Toby', 'Rene'}"
                name="friends"/>
 
        <s:radio
                tooltip="Choose your Best Friend"
                label="Best Friend"
                list="{'Wes', 'Patrick', 'Jason', 'Jay', 'Toby', 'Rene'}"
                name="bestFriend"
                cssErrorClass="foo"/>
 
        <s:checkbox
                tooltip="Confirmed that your are Over 18"
                label="Age 18+"
                name="legalAge"/>
 
        <s:submit cssClass="btn"/>
    </s:form>

Download: http://code.google.com/p/struts2-bootstrap/downloads/list
Showcase: http://struts.jgeppert.com/struts2-bootstrap-showcase/
Issues: http://code.google.com/p/struts2-bootstrap/issues/list

20 Kommentare

  1. Jerome

    Wow, this is great. I just learned about bootstrap today and found the new plugin for struts2.

    Can this plugin used with the struts-jquery plugin as well?

    Thanks for the nice plugin :)

    Antworten
    1. jogep (Beitrag Autor)

      I don’t have tested it yet against the Struts2 jQuery Plugin.
      But I see no resonse why it sould not work with it together.

      Antworten
  2. Gilbert

    In the showcase, advanced Bootstrap form with simple Type Ahead, entering ‘A’ displays the list ‘Alabama’,’Alaska’,’Arizona’,’Arkansas’. If you continue typing in the type ahead field and continue ‘l’ (so the box now contains ‘Al’ then the list then changes to ‘Alabama’, ‘Alaska’, ‘California’. Why?

    Antworten
    1. jogep (Beitrag Autor)

      Because C al ifornia includes “al”! :-)

      The first times it does not show California because it is not in the first 4 search results. See the data-items=”4″ attribute.

      Antworten
  3. Siddharth

    The line is throwing up errors. I am using Eclipse and have Struts2 properly working in my project right now. What am I doing wrong?

    Antworten
    1. jogep (Beitrag Autor)

      Which line is throwing an error? Can you please give some more details about your problem? If you think this is an bug, please fill free to create an Issue.

      Antworten
  4. Siddharth

    The <sb:head/> line is throwing up errors of all sorts. The error log is as follows:
    org.apache.jasper.JasperException: An exception occurred processing JSP page /Test1.jsp at line 14

    11:
    12:
    13:
    14:
    15:
    16:
    17:

    I’m kind of new at struts. Please help me out.

    Antworten
  5. Siddharth

    Oh sorry, I copy pasted the log but it is wiped out in the post. The line 14 is exactly the <sb:head/>

    Antworten
  6. Siddharth

    Hey man, nice work you’ve done. I solved my previous error but encountered a new one. I’ve integrated the plugin well enough. But every jsp page now in my project is not executed. I get error 404 for each page, even the ones not using bootstrap tags. What could i’ve done wrong?

    Antworten
  7. Siddharth

    Please don’t bother with my earlier posts. I’ve solved all problems and its working fine now. I really have to say excellent job done. Salud!

    Antworten
    1. jogep (Beitrag Autor)

      Nice to here. :-)

      What exactly was the problem/solution?

      Antworten
  8. Siddharth Sakhadeo

    The problem was that after including the plugin in the lib folder, no struts tag was properly executed. All jsp pages were showing an http error 404. Anyhow, I downloaded youe entire showcase war package and ran the same on mine. Somehow it worked. Very lame, I know, but I’m new to struts and trying to learn more. I wanted to ask you if you’ve included the modal scripts in the plugin. If yes, how do I access them?

    Antworten
    1. jogep (Beitrag Autor)

      All scripts should be available. All you need is to include an reference to jquery and tag in your head area.

      $(‘#myModal’).modal()

      Antworten
  9. Siddharth Sakhadeo

    Which Hibernate release should I use such that I can include this bootstrap plugin? Also I’m using the struts 2.0 and Hibernate 3.0 release and somehow this plugin isn’t working with those jars.

    Antworten
    1. jogep (Beitrag Autor)

      The Hibernate Release should not have any side effects to the Bootstrap Plugin. Maybe you need Struts2 2.1.x or higher instead of version 2.0.x.

      Antworten
  10. Pingback: Version 1.2.0 of Struts2 Bootstrap Plugin released | Java, Programming, Struts2, jQuery, Linux and more

  11. ramesh m

    Hi friends

    I am using struts2.0 with bootstrap-plugin client side validations ,

    i wrote this code,it won’t client validations.please help me

    Antworten
    1. jogep (Beitrag Autor)

      Have you seen the Validation Example in the Struts2 Bootstrap Showcase?

      http://struts.jgeppert.com/struts2-bootstrap-showcase/validation.action

      Antworten
  12. Dinesh

    Hi,
    iam trying to use Struts2 Bootstrap for client-Side Validation

    i added jar and Done jsp changes as present in showcase.

    are there any other prerequisites to use this .

    Antworten
    1. jogep (Beitrag Autor)

      Can you provide some Code Examples?
      Do you have the jsonValidationWorkflowStack Interceptor in your Interceptor Stack?

      @InterceptorRef(“jsonValidationWorkflowStack”)

      Antworten

Kommentar verfassen