开发者

Can i use struts tags inside the html tags to initialise their attribute?

I am using the following code but haven't tried it yet:

开发者_Python百科
<input type="checkbox" id="<bean:write name="element" property="idvalue" />" />

Is it valid ?

And how can it be acheived more efiiciently ?


You can use server tags to initialize attributes of HTML tags. The code you posted is valid.

This code:

<input type="checkbox" id="<bean:write name="element" property="idvalue" />" />

evaluates to

<input type="checkbox" id="theID" />

assuming that "theID" is what's inside the "idvalue" property of your bean.

Off course this isn't very easy to read even if you use JSTL as VinAy suggested. You will just ed up with something like this:

<input type="checkbox" id="<c:out value="${element.idvalue}" />" />

Again not easy to read if you have an entire JSP full of these.

The Struts html tags come in handy here and generate the input by using a construct like:

<html:text name="element" property="idvalue" />

which, if you have it inside a <html:form> tag can be further simplified to:

<html:text property="idvalue" />

And if all fails, you can always simplify it as much as you want by writing your own JSP custom tags.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜