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 a Bootstrap based Struts2 Web app. 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.

<!DOCTYPE html>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sb" uri="/struts-bootstrap-tags" %>
<html lang="en">
<head>
    <meta charset="utf-8">

    <s:head />
    <sb:head includeScripts="true" />
</head>

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"
                        labelCssClass="col-sm-3 col-form-label"
                        elementCssClass="col-sm-5"
                        cssClass="form-control-sm"
                        tooltip="Enter your Name here"/>

                <s:password
                        label="Password"
                        name="password"
                        tooltip="Enter your Password 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"
                        elementCssClass="col-sm-4"
                        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:checkboxlist
                        tooltip="Checkboxes with inline position"
                        labelPosition="left"
                        label="Friends Inline"
                        list="{'Wes', 'Patrick', 'Jason', 'Jay', 'Toby', 'Rene'}"
                        name="friendsInline"/>

                <s:radio
                        tooltip="Choose your Best Friend"
                        label="Best Friend"
                        list="{'Wes', 'Patrick', 'Jason', 'Jay', 'Toby', 'Rene'}"
                        name="bestFriend"
                        cssErrorClass="foo"/>

                <s:radio
                        tooltip="Radio Buttons with inline position"
                        label="Best Friend Inline"
                        labelPosition="left"
                        list="{'Wes', 'Patrick', 'Jason', 'Jay', 'Toby', 'Rene'}"
                        name="bestFriendInline"
                        cssErrorClass="foo"/>

                <s:checkbox
                        tooltip="Confirm that your are over 18 years old"
                        label="Age 18+"
                        name="legalAge"/>

                <s:doubleselect
                        tooltip="Choose Your State"
                        label="State"
                        name="region" list="{'North', 'South'}"
                        value="'South'"
                        doubleValue="'Florida'"
                        doubleList="top == 'North' ? {'Oregon', 'Washington'} : {'Texas', 'Florida'}"
                        doubleName="state"
                        headerKey="-1"
                        headerValue="---------- Please Select ----------"
                        emptyOption="true"/>

                <s:file
                        tooltip="Upload Your Picture"
                        label="Picture"
                        name="picture"/>

                <s:optiontransferselect
                        tooltip="Select Your Favourite Cartoon Characters"
                        label="Favourite Cartoons Characters"
                        name="leftSideCartoonCharacters"
                        leftTitle="Left Title"
                        rightTitle="Right Title"
                        list="{'Popeye', 'He-Man', 'Spiderman'}"
                        multiple="true"
                        headerKey="headerKey"
                        headerValue="--- Please Select ---"
                        emptyOption="true"
                        doubleList="{'Superman', 'Mickey Mouse', 'Donald Duck'}"
                        doubleName="rightSideCartoonCharacters"
                        doubleHeaderKey="doubleHeaderKey"
                        doubleHeaderValue="--- Please Select ---"
                        doubleEmptyOption="true"
                        doubleMultiple="true"/>

                <s:inputtransferselect
                        tooltip="Add Your Favourite Cartoon Character"
                        label="Favourite Cartoons Characters"
                        name="inputLeftSideCartoonCharacters"
                        addLabel="Add element"
                        removeLabel="Remove element"
                        removeAllLabel="Remove all elements"
                        upLabel="Move up"
                        downLabel="Move down"
                        leftTitle="Add Character"
                        rightTitle="Existing Characters"
                        list="{'Popeye', 'He-Man', 'Spiderman'}"/>

                <s:textarea
                        label="Your Thougths"
                        name="thoughts"
                        labelCssClass="col-sm-3 col-form-label col-form-label-sm"
                        cssClass="input-xxlarge"
                        tooltip="Enter your thoughts here"/>

                <s:submit cssClass="btn btn-primary"/>
            </s:form>

Project: https://github.com/struts-community-plugins/struts2-bootstrap
Showcase: https://struts.jgeppert.com/struts2-bootstrap-showcase/
Issues: https://github.com/struts-community-plugins/struts2-bootstrap/issues

New Struts2 Bootstrap Plugin released
Tagged on:             

20 thoughts on “New Struts2 Bootstrap Plugin released

  • 2012-02-03 at 04:26
    Permalink

    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 🙂

    Reply
    • 2012-02-03 at 08:55
      Permalink

      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.

      Reply
  • 2012-03-01 at 10:07
    Permalink

    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?

    Reply
    • 2012-03-01 at 11:13
      Permalink

      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.

      Reply
  • 2012-03-04 at 11:28
    Permalink

    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?

    Reply
    • 2012-03-04 at 13:16
      Permalink

      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.

      Reply
  • 2012-03-05 at 11:25
    Permalink

    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.

    Reply
  • 2012-03-05 at 11:27
    Permalink

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

    Reply
  • 2012-03-05 at 14:46
    Permalink

    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?

    Reply
  • 2012-03-05 at 17:16
    Permalink

    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!

    Reply
    • 2012-03-05 at 19:32
      Permalink

      Nice to here. 🙂

      What exactly was the problem/solution?

      Reply
  • 2012-03-05 at 20:43
    Permalink

    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?

    Reply
    • 2012-03-06 at 19:35
      Permalink

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

      $(‘#myModal’).modal()

      Reply
  • 2012-03-11 at 07:14
    Permalink

    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.

    Reply
    • 2012-03-12 at 18:00
      Permalink

      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.

      Reply
  • Pingback:Version 1.2.0 of Struts2 Bootstrap Plugin released | Java, Programming, Struts2, jQuery, Linux and more

  • 2012-07-02 at 09:33
    Permalink

    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

    Reply
  • 2013-03-04 at 09:40
    Permalink

    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 .

    Reply
    • 2013-03-10 at 15:22
      Permalink

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

      @InterceptorRef(“jsonValidationWorkflowStack”)

      Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.