Struts 2 text box arrangment - struts2

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.

Related

How to use Html5 tags e.g email with 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

how to display headerkey options in struts2 jquery grid column

i have a jsp page where i am displaying data in strust2 jquery Grid.
In grid column there is search facility based on the Select type(Drop down select).
<sjg:gridColumn name="subjectId" title="Subject Name" editable="true" align="center" search="true" searchtype="select"
searchoptions="{dataUrl:'%{selecturl}'}" edittype="select" editoptions="{dataUrl:'%{selecturl}'}" />
.My dropdown list is coming fine from my Class as well as it is correctly displaying on its place.
What i want exactly is a header value something like this ( ----select here--) followed by all the values populated from my class.
eg. I know how to do this(below code) in struts2 but i don't know this in struts2 jquery grid column.Now i am only able to display all list without header key & header values.
<s:select label="What's your favor search engine"
headerKey="-1" headerValue="----Select here----"
list="selecturl"
name="name" />
Please help me regarding this issue.

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="+" />

Struts2 form elements

Why is it that when I insert an element in between the s:textfield it gets placed on top?
Is there a way to fix that?
Thanks for helping on this.
<s:textfield label="First Name" required="true"/>
<s:textfield label="Last Name" required="true"/>
<s:text name="testing1">test1</s:text>
<s:textfield label="Address" required="false"/>
<s:textfield label="Email" required="true"/>
<s:text name="testing2">test2</s:text>
Order being displayed on browser:
test1
test2
First Name
Last Name
Address
Email
I guess my answer to this question comes too late, but I respond to this just for the record.
The reason why the text elements don't appear in between is because struts renders a table to display your input fields (and their labels). If you look at the HTML rendered by struts you will see one tag for each textfield. If you insert any other component between these, struts will not know how to format these into the table of the form, resulting in the items being displayed before the start of the table.
To avoid this behavior you can set the "theme" attribute of the form to "simple". This will result in the fact that you will need to do all formatting by yourself.
Hope this helps.

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