简体   繁体   English

渲染的JSF不起作用

[英]JSF rendered is not working

I have something like this on my webpage, a select/drop down menu. 我的网页上有一个类似的东西,一个选择/下拉菜单。 This drop down menu should generate another drop down menu based on selected item. 此下拉菜单应根据所选项目生成另一个下拉菜单。 The way I am doing it, is by calling <f:ajax event="change"..listener=..> 我这样做的方法是调用<f:ajax event="change"..listener=..>

But it is not happening as I expected. 但它并没有像我预期的那样发生。 While selecting item in the dropdown menu trigger the listener in the ajax tag, the rendered property of the following drop down tables seems not affected by the changes. 在下拉菜单中选择项目时,会触发ajax标记中的侦听器,以下下拉列表的rendered属性似乎不受更改的影响。 And the value for rendered changed successfully from false to true. 并且rendered值从false成功更改为true。 Which..made me wonder what is wrong in my jsf page. 哪位......让我想知道我的jsf页面有什么问题。

Here is the xhtml ' 这是xhtml'

                        <h:selectOneMenu value="#{teacher.viewCategory}">
                            <f:selectItem itemValue="0" itemLabel="Tahun" />
                            <f:selectItem itemValue="1" itemLabel="Mata Pelajaran" />
                            <f:ajax event="change" render="divYearSelection divCourseSelection"
                                    listener="#{teacher.enableViewCategory}"/>
                        </h:selectOneMenu>

                        <h:panelGroup id="divYearSelection" layout="block" rendered="#{teacher.showViewYearSelection}">
                            <h:outputText value="YEAR"/>
                        </h:panelGroup>

                        <h:panelGroup id="divCourseSelection" layout="block" rendered="#{teacher.showViewCourseSelection}">
                            <h:outputText value="COURSE"/>
                        </h:panelGroup>


                        <h:commandButton value="#{msg.tcr_form_submit_view}" action="#{teacher.viewTeacher}"/>
                    </h:panelGrid>
                </h:form>' 

and this is the bean's function supporting the ajax 这是bean支持ajax的功能

public void enableViewCategory(AjaxBehaviorEvent e) {       
        if (this.getViewCategory().equals("0")) {
            this.setShowViewYearSelection(true);
        } else {
            this.setShowViewCourseSelection(true);
        }
    } 

When I debugged , the function works fine. 当我调试时,该功能正常工作。

If partial rendering doesn't work a good starting point is to look into html source of your page as it is rendered in browser. 如果部分渲染不起作用,一个好的起点是查看页面的html源,因为它在浏览器中呈现。 Your render="divYearSelection" will only work if both (the ajax triggering component and the target component) have the same direct parent container. 只有当两者(ajax触发组件和目标组件)具有相同的直接父容器时,您的render="divYearSelection"才有效。

Ids of rendered html components usually look like id="formId:componentId:nestedComponentId1" or id="formId:componentId:nestedComponentId2" 渲染的html组件的ID通常看起来像id="formId:componentId:nestedComponentId1"id="formId:componentId:nestedComponentId2"

So a render="nestedComponentId2" called from component1 will only work if both ids have the same "trailer". 所以从component1调用的render="nestedComponentId2"只有在两个id都具有相同的“预告片”时才有效。

You could try to use the complete id as given in the example starting with the id of the form or alternatively (if the whole form is not too big) use render="@form" which updates the whole form. 你可以尝试使用示例中给出的完整id,从表单的id开始,或者(如果整个表单不是太大)使用render="@form"来更新整个表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM