【问题标题】:Richfaces a4j:jsFunction renders textbox but rendered validation failsRichfaces a4j:jsFunction 渲染文本框但渲染验证失败
【发布时间】:2014-01-09 13:51:55
【问题描述】:

我的测试应用程序包含两个h:inputText 和一个a4j:outputPanel,这是重新呈现两个文本字段的触发器。两个文本字段一开始都是空的,第二个也是不可见的。单击面板后,将调用一个方法,该方法设置输入值以及用于显示第二个文本字段的布尔值。代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:fm30x="http://myfaces.inter-forum.de/fm30x/facelets"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:c="http://java.sun.com/jsp/jstl/core">


<h:head>
    <h:outputStylesheet name="stylesheet.css" library="css" />
</h:head>
<h:body>
    <h:form id="mainForm">

        <h:panelGrid>

            <h:inputText id="text" value="#{testBean.testString}"/>

            <h:inputText id="text2" value="#{testBean.trackingId}" rendered="#{testBean.showString}"/>

                <a4j:outputPanel layout="block" styleClass="quote" onmousedown="begin();">              
                    <h:outputText value="Thats a test" ></h:outputText>
                </a4j:outputPanel>

        </h:panelGrid>

        <a4j:jsFunction name="begin" actionListener="#{testBean.start}" render="text text2" />

    </h:form>
</h:body>
</html>

问题是,当点击面板时,只有第一个文本字段被渲染,而第二个文本字段仍然不可见,尽管我已经更新了 bean 内 ajax 方法中的布尔值。同样奇怪的是,当我总是为 getter 中的 showString 值返回 true 时,第二个文本字段值被更新(这次我可以看到它,因为那时第二个文本字段将始终呈现)。所以总而言之,我可以说实际值的更新是正确的,但是 ajax 没有正确评估 h:inputTextrender 属性。我做错了什么?

【问题讨论】:

    标签: ajax jsf richfaces


    【解决方案1】:

    如果你有条件渲染的组件,直接重新渲染它们是行不通的。您必须将它们包装在某些东西中并在包装器上调用渲染。

    <a4j:outputPanel id="wrapper">
        <h:inputText id="text" value="#{testBean.testString}"/>
        <h:inputText id="text2" value="#{testBean.trackingId}" rendered="#{testBean.showString}"/>
    </a4j:outputPanel>
    
    <a4j:outputPanel layout="block" styleClass="quote" onmousedown="begin();">              
        <h:outputText value="Thats a test" ></h:outputText>
    </a4j:outputPanel>
    
    <a4j:jsFunction name="begin" actionListener="#{testBean.start}" render="wrapper" />
    

    请记住,rendered="false" 并不意味着组件是不可见的,而是意味着它不存在于组件树中。

    【讨论】:

    • 非常感谢您的回答,这对我帮助很大。我在这里也找到了解决方案:http://stackoverflow.com/questions/14790014/jsf-fajax-rendering.
    猜你喜欢
    • 2012-04-22
    • 2023-04-09
    • 2013-07-25
    • 1970-01-01
    • 2016-05-08
    • 2011-08-24
    • 2011-03-12
    • 2011-11-26
    • 2012-02-25
    相关资源
    最近更新 更多