jsp - how to use struts form fields (s:textfield, s:password) and style them using materializecss framework? -
<form class = "col l12 s12"> <div class = "row"> <div class="input-field col l6 s6"> <input id="firstname" type="text" class="validate"> <label for="firstname">first name</label> </div> </div> </form>
i want apply struts2 on above code value of firstname
. how should that?
edit (whole jsp code registration form):
<%@ page contenttype="text/html;charset=utf-8" language="java" %> <%@taglib prefix="s" uri="/struts-tags" %> <html> <head> <!--import google icon font--> <link href="http://fonts.googleapis.com/icon?family=material+icons" rel="stylesheet"> <!--import materialize.css--> <link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/> <link type="text/css" rel="stylesheet" href="css/register.css"> <!--let browser know website optimized mobile--> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> </head> <body> <!--import jquery before materialize.js--> <script type="text/javascript" src="js/jquery-2.1.4.min.js"></script> <script type="text/javascript" src="js/materialize.min.js"></script> <div class = "background"> <h1 class = "center-align white-text">register</h1> </div> <div class = "container formcontainer white z-depth-2"> <div class = "row formparent"> <form class = "col l12 s12"> <div class = "row"> <div class="input-field col l6 s6"> <input id="firstname" type="text" class="validate"> <label for="firstname">first name</label> </div> <div class="input-field col l6 s6"> <input id="lastname" type="text" class="validate"> <label for="lastname">last name</label> </div> </div> <div class = "row"> <div class="input-field col l12 s12"> <input id="username" type="text" class="validate"> <label for="username">username</label> </div> </div> <div class = "row"> <div class="input-field col s6"> <input id="password" type="password" class="validate"> <label for="password">enter password</label> </div> <div class="input-field col s6"> <input id="repeatpassword" type="password" class="validate"> <label for="repeatpassword">repeat password</label> </div> </div> <div class="row"> <div class="input-field col s12"> <input id="email" type="email" class="validate"> <label for="email" data-error="wrong" data-success="right">email</label> </div> </div> <div class = "row formbuttons"> <button class="btn waves-effect waves-light right submitbutton purple accent-4" type="submit" name="submit">submit</button> <a href = 'index.jsp' class = 'btn waves-effect waves-dark right cancelbutton purple accent-1'>cancel</a> </div> </form> </div> </div> </body>
in above jsp code, wish field values , want able assign them following actionclass:
public class registeraction { private string firstname, lastname, username; public string execute(){ return ""; } }
but dont know how apply struts prefix jsp form using materialize css input fields.
here code struts.xml
<?xml version="1.0" encoding="utf-8"?> <!doctype struts public "-//apache software foundation//dtd struts configuration 2.3//en" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="struts.devmode" value="true"/> <package name="helloworld" extends="struts-default"> <action name="hello" class = "com.bugmanager.registeraction" method="execute"> <result name="success">helloworld.jsp</result> </action> </package> </struts>
ok, did on own. if wants use materializecss form tags in struts2 following:
1. add line struts.xml
<constant name="struts.ui.theme" value="simple" />
my updated , working struts.xml
<struts> <constant name="struts.devmode" value="true"/> <constant name="struts.ui.theme" value="simple" /> <!-- line helps in applying materializecss's styling form elements --> <package name="com.bugmanager" extends="struts-default"> <action name="register" class = "com.bugmanager.registeraction" method="execute"> <result name="success">helloworld.jsp</result> </action> </package> </struts>
my helloworld.jsp: (any redirection page, made page test out if values being mapped , stored correctly)
<html> <head> <title>hello world strut</title> </head> <body> hello <s:property value = "firstname"/> <s:property value = "lastname"/> <s:property value = "username"/> <s:property value = "password"/> <s:property value="email"/> </body> </html>
2. change
form tags
<form></form> <s:form></s:form>
any text or email input tags to
<s:textfield />
password fields to
<s:password />
submit can remain same.
check out example form code given below
<s:form class = "col l12 s12" action = "register"> <div class = "row"> <div class="input-field col l6 s6"> <s:textfield name = "firstname" id="firstname" type="text" class="validate"/> <label for="firstname">first name</label> </div> <div class="input-field col l6 s6"> <s:textfield name = "lastname" id="lastname" type="text" class="validate"/> <label for="lastname">last name</label> </div> </div> <div class = "row"> <div class="input-field col l12 s12"> <s:textfield name = "username" id="username" type="text" class="validate"/> <label for="username">username</label> </div> </div> <div class = "row"> <div class="input-field col s6"> <s:password name = "password" id="password" type="password" class="validate"/> <label for="password">enter password</label> </div> <div class = 'input-field col s6'> <s:password name = "password" id="repeatpassword" type="password" class="validate"/> <label for="repeatpassword">repeat password</label> </div> </div> <div class="row"> <div class="input-field col s12"> <s:textfield name = "email" id="email" type="email"/> <label for="email">email</label> </div> </div> <div class = "row formbuttons"> <button class="btn waves-effect waves-light right submitbutton purple accent-4" type="submit" name="submit">submit</button> <a href = 'index.jsp' class = 'btn waves-effect waves-dark right cancelbutton purple accent-1'>cancel</a> </div> </s:form>
take @ struts form tags here: http://www.tutorialspoint.com/struts_2/struts_form_tags.htm
i hope helps trying implement materializecss in struts2!
Comments
Post a Comment