Struts2 form elements - struts2

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.

Related

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

Can I add html to a jsf h:message with a custom component?

I would like to add a header and footer image to a h:message in JSF 2.0 so it has nice borders.
It looks like the way to do this is to implement a custom renderer for a component and write out the tags. Id like to do this as a composite component but I cant figure out how to say 'dont draw the header and footer unless youre drawing the message'.
Is there a way to do this with a composite component?
Im using mojarra.
You can use FacesContext#messageList(String clientId) to get a List<FacesMessage> with all messages for a specific client ID (of which you'd usually be interested in only the first one, you can change the below example if you want). So you could just check in the rendered attribtue if the list is not empty. Then you can use <h:outputText escape="false"> to display the message without implicitly escaping HTML. You could if necessary wrap it all in a composite to keep your code DRY.
<h:inputText id="input1" binding="#{input1}" value="#{bean.input1}" />
<ui:param name="input1Messages" value="#{facesContext.messageList(input1.clientId)}" />
<h:panelGroup rendered="#{not empty input1Messages}">
<h3>Some header</h3>
<p><h:outputText value="#{input1Messages[0].summary}" escape="false" /></p>
<p>Some footer</p>
</h:panelGroup>
Note that this method was not available in JSF 1.x, that's why you'd need to create a custom component for it.

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