Struts2 tags in divs appear empty

♀尐吖头ヾ 提交于 2019-12-31 05:17:50

问题


I have a s:checkbox inside a html div. When the code is run, the checkbox is outside (both) the div and the divs seem to be empty and nonexistant. Why is this occuring and how can I fix it? When I place random text inside either div, the div contains it. I set the background color to red so I can detect the div.

<div id="outer">
    <div id="inner">
        <s:checkbox name="chBx" id"chBx" fieldValue="false" value="true" label="Check 
            This" />
    </div>
</div>

回答1:


Like described in this answer (that you should consider upvoting too), Struts2 generates (or not) a certain kind of HTML when rendering Struts Tags, basing on the Theme you have chosen.

The default one is xhtml, that will generate a lot of stuff for you. It may be handy, but also annoying, according to how you work. Personally I prefer to generate the HTML by myself, and then I use the theme that won't generate almost any HTML: the simple Theme.

Note that when working on big projects or with multiple projects with the same, particular needs, you can also write your own custom theme (for example for generating security tokens automatically).

You can use a theme globally (in struts.xml)

<constant name="struts.ui.theme" value="simple" />

or locally to a single tag / form:

<s:checkbox name="chBx" id"chBx" fieldValue="false" 
           theme="simple"
           value="true" label="Check This" />

In this case, you may need to write the <label> object by yourself.



来源:https://stackoverflow.com/questions/27252330/struts2-tags-in-divs-appear-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!