RichFaces Ajax (conditional) Rendering: HowTo?
Please look at the following Code Snippet:
<h:form>
<h:panelGrid columns="2">
开发者_运维问答 <h:inputText value="#{vehicleBean.pin}" />
<a4j:commandButton action="#{vehicleBean.loadVehiclesByPin}" render="results"/>
</h:panelGrid>
</h:form>
<a4j:outputPanel id="results">
<rich:dataTable value="#{vehicleBean.vehicles}" rendered="#{not empty vehicleBean.vehicles}">
...
</rich:dataTable>
</a4j:outputPanel>
When I press the button an Ajax request is sent to load some business entities. They are displayed in a rich:dataTable which is only rendered if the corresponding array is not empty.
This works for me in Chrome an Firefox 4 but not in IE9. But I'm pretty sure it's my fault and not IE's ;-)
So please tell me:
- What is the correct approach to solve this kind of problem (with a conditionally rendered element)?
- Which element(s) should I re-render?
- The commandButton also has a execute attribute: When and why do I have to use this attribute?
Greetings Sebi
RichFaces 3.x does not support IE9, refer to this post: http://community.jboss.org/thread/156720
You can upgrade to RF 4, or implement a filter to force IE9 to run in compatibility mode:
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
HttpServletResponse resp = (HttpServletResponse) response;
resp.addHeader("X-UA-Compatible", "IE=EmulateIE8");
chain.doFilter(request, resp);
}
some things that you could fix:
- let your form tag surround all JSF compontents
- if loadVehiclesByPin relies on the value of pin, you should execute the inputText component (assign an id to it, e.g. "inputPin") with commandButton like that: execute="@this inputPin"
- i'm not sure, if you use the correct in in render="result" (be aware of the NamespaceContainer concept, read javadoc of UIComponent.findComponent )
for better debugging, i suggest to enable PROJECT_STAGE=Development in web.xml and to open your browsers javascript console.
Be aware that, when using conditional rendering, you need to point your render parameter to an id in your JSF component tree, that is already there (you did right here by surrounding your conditional dataTable with a panel)
regards
精彩评论