How to use Html5 tags e.g email with struts2 - struts2

I am using struts2 for presentation layer, now there is requirement to use html5 tags e.g. email, tel etc., but it seems that struts2 doesn't support html5 tags.
Is there any way to achieve the above requirement?

You can add custom (HTML5 and others) attributes to Struts2 Tags that have declared they support Dynamic Attributes. Look in the documentation, for each tag you are using, under the Parameters part if you see Dynamic Attributes Allowed: true;
You can still use native HTML elements, along with Struts tags. Then both the following ways are good:
<s:textfield name="foo" value="bar" customAttr />
<input type="text" name="foo" value="<s:property value="bar"/>" customAttr />
If you need to change the type, you can now do it with the Struts <s:textfield /> tag too:
<s:textfield type="email" name="foo" value="bar" customAttr />
<s:textfield type="date" name="foo" value="bar" customAttr />
<s:textfield type="currency" name="foo" value="bar" customAttr />
etc...

Your struts2 tags(<s: >) will finally be converted to basic HTML tags when the page is rendered, which you can check by looking into the generated source. Usually, Struts2 just adds some css(if you are not using theme="simple") to the basic HTML tags. So. it is incorrect to say that
struts2 doesn't support html5 tags
Use the Html5 tags as usual, they will work.
It looks like you are new to the community, so dont get demotivated by the downvotes but in future try to do some homework and ask specific problems, what did you try and what did not work

Related

Struts2 csrf token in velocity template

How to use Struts 2 CSRF token interceptor in Velocity template.
Below is standard JSP example with struts tag
<s:form action="UpdateUser">
<s:textfield name="name" label="User Name">
</s:textfield>
<s:textfield name="address" label="Address">
</s:textfield>
<s:submit name="submit" value="Update">
</s:submit>
<%-- add token to JSP to be used by Token interceptor --%>
<s:token />
</s:form>
Same I want to achieve using Velocity template and want to know how to get token value in Velocity.
What do you want to know about Velocity, is already integrated in Struts 2. You might want to use tags in velocity type results. You can learn more about it reading Velocity Tags.
Velocity tags are extensions of the generic Struts Tags provided by the framework. You can get jump right in just by knowing the structure in which the tags can be accessed: #s<tag> (...), where tag is any of the Struts Tags supported by the framework.
For using token interceptor for CSRF you should read this answer.

Struts1 tags to Struts2 tags

The Web application which i am currently working uses Struts1, now i am migrating this application to Struts2.
The below tags are Struts1 tags, Need to modify this tags to Struts2.
<bean:define id="recordPerPageList" name="searchForm" property="recordPerPageList" type="java.util.Collection"/>
<td class="formPromptTd"><html:hidden property="action" value="<%=actionFirst%>"/><input name="quickSearchFlag" type="hidden" value=""></td>
<html:image property="searchButton" src="<%=searchImage%>"/>
Could any one provide the Struts 2 equivalent tags ?
The <s:fieldError> tag would be the closest equivalent for <html:message>
<html:messages id="userName" property="userName">
<s:fielderror fieldName="userName" />
The tag would be the closest equivalent for

Can i use html tags in struts2 form?

Can i use html form tags in struts 2 form?
Like
<input type='text' value='' />
<input type='submit' />
Will the values be posted through struts2?
It's not at all mandatory to use struts2 tags. You could go with regular HTML.
Of course.
This is one of those questions you can just try.
All the S2 form tags do is emit HTML, filling in various attributes as required. (It's slightly more complicated than that, but ultimately, they spit out an HTML form field.)
Flip your question on its head: why wouldn't a hand-crafted input tag be sent via the normal browser HTTP submission process? What mechanism could prevent it from working? How is the request body of from such a form submission different from one where the input tags are S2 custom tags?
These questions are all trivial to explore.
Yes.
You must give them a name; the name will be used to set properties (with correct type conversion) in the struts action.
If you call an input somename the setSomename() will be called on post.
If simple HTML used you wont be able to call struts tags inside it eg:
<s:submit cssStyle="submit_button" id='newrc%{#stat.index}.%{#questionIndex.index}' name="newrc%{#stat.index}.%{#questionIndex.index}" onclick="return newrcClick(this)" value="+" />
This works but below code does not provide values for id and name from values stack thus :name="newrc%{#stat.index}.%{#questionIndex.index}"
<input type="button" cssStyle="submit_button" id='newrc%{#stat.index}.%{#questionIndex.index}' name="newrc%{#stat.index}.%{#questionIndex.index}" onclick="return newrcClick(this)" value="+" />

Struts 2 text box arrangment

I want to create a form that contains text boxes as follow. I am using Struts2.
User Name
|Text Box for user name|
mail id
|Text box for mail id|
<s:textarea name="username" id="username" label="User Name"/>
This is showing:
User name |Text Box for user name|
But I want the above format. When I am using validation framework label is shown in italic, I want normal text.
That is because of default struts2 theme factor xhtml which is showing the output html in table structure
Change the theme to simple ans use your own css/HTML way to customize the output
crate a struts.properties file and add the following entry
struts.ui.theme=simple
this will change the theme for whole application as struts2 tags will no longer generates HTML/table code for you
else u can override the theme per page basis
like
<s:set name="theme" value="'simple'" scope="page" />
alternate way can be what "Steven" suggested
You're in luck. Just add the labelposition="top" attribute to your Struts2 input tags. e.g.,
<s:textfield name="subject"
label="Subject"
size="30"
maxlength="50"
labelposition="top"
required="true"/>
As for the italic label, that should be controlled by CSS.

Why use <g:textField /> in Grails?

What is the reason to use g:textField in Grails if you're already familiar with standard HTML form tags?
If I understand correctly the following two markup alternatives are equivalent:
<input type="text" name="name" value="${params.name}" id="name" />
<g:textField name="name" value="${params.name}" />
Are there any circumstances under which using g:textField would add value? Am I missing something?
The textField tag is provided as a convenience (slightly shorter than writing the HTML input) and is there to provide a full set of form tags. Personally I prefer to write as much plain HTML as possible in my Grails views and only tend to use the tags that really offer a benefit such as the form tag. I have not found an instance where using textField would have added any value outside of requiring a few less characters to type.
<g:textField /> is not shorter as plain text field tag, except id attribute will be attached automatically.
However, I recommend you to use customized tags associating the bean values with input fields. That shortens the code a lot. For more information you can read http://www.jtict.com/blog/shorter-grails-textfield/
Also you can find useful stuff in Form Helper Plugin

Resources