rakela
rakela

Reputation: 303

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?

Upvotes: 2

Views: 1874

Answers (4)

sampopes
sampopes

Reputation: 2696

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

Upvotes: 0

Dave Newton
Dave Newton

Reputation: 160191

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.

Upvotes: 3

verisimilitude
verisimilitude

Reputation: 5108

It's not at all mandatory to use struts2 tags. You could go with regular HTML.

Upvotes: 3

Andrea Colleoni
Andrea Colleoni

Reputation: 6021

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.

Upvotes: 2

Related Questions