开发者

Reducing size of HTML output by sharing f:selectItems between h:selectOneMenu?

开发者 https://www.devze.com 2023-02-25 02:21 出处:网络
Got a page with ui:repeat bound to a list collection like below: <ui:repeat value=\"#{myBean.products}\" var=\"product\">

Got a page with ui:repeat bound to a list collection like below:

<ui:repeat value="#{myBean.products}" var="product">
 开发者_如何学JAVA   ....
    ....
    <h:selectOneMenu id="type" required="true" value="#{product.category}">
      <f:selectItems value="#{productcategories}"/>
    </h:selectOneMenu>
</ui:repeat>

I have a list of products being displayed binding to a drop down on a product field as above.

It works fine but the number of #{productcategories} is very large, about 500 categories and increasing, so for each repeat the drop down items is output in the HTML file. This increases the file size especially when the product listing is in the 50 items per page, so is there a way I can reduce the size of the output HTML by sharing the h:selectItems among multiple drop downs?

Anyone got any ideas?


That's not possible. That's the nature of HTML. The HTML <option> elements generated by <f:selectItems> has to go in the <select> element generated by JSF <h:selectOneMenu> anyway and cannot be referenced from each other's one.

You could consider to render (show/hide) components conditionally in the server side by the rendered attribute so that the generated HTML output is less large. You could also consider to turn on GZIP compression on the response in the servletcontainer you're using so that the network bandwidth is saved.

0

精彩评论

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