简体   繁体   English

Richfaces a4j:jsFunction呈现文本框,但呈现的验证失败

[英]Richfaces a4j:jsFunction renders textbox but rendered validation fails

My test application contains two h:inputText and one a4j:outputPanel which is a trigger for rerendering both text fields. 我的测试应用程序包含两个h:inputText和一个a4j:outputPanel ,这是重新呈现两个文本字段的触发器。 Both text fields are empty at the beginning and the second one is also invisible. 两个文本字段的开头都为空,第二个字段也不可见。 After clicking the panel a method is called which sets both input values and also the boolean value for displaying the second text field. 单击面板后,将调用一个方法,该方法既设置输入值,又设置用于显示第二个文本字段的布尔值。 Here is the code: 这是代码:

<?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>

The problem is that when clicking on the panel only the first text field gets rendered and the second one is still invisible, although I have updated the boolean value in the ajax method inside the bean. 问题是,尽管我已经更新了bean内ajax方法中的布尔值,但是在面板上单击时仅呈现第一个文本字段,而第二个文本字段仍然不可见。 It is also strange, that when I always return true for the showString value in the getter, the second text field value gets updated (I can see it this time because the second text field will be always rendered then). 同样奇怪的是,当我总是在getter中为showString值返回true时,第二个文本字段值将被更新(我这次可以看到它,因为第二个文本字段将始终被渲染)。 So all in all I can say that the updating of the actual values are correct but the render attribute of the h:inputText is not correctly evaluated by ajax. 因此,总的来说,我可以说实际值的更新是正确的,但是ajax无法正确评估h:inputTextrender属性。 What am I doing wrong? 我究竟做错了什么?

If you got conditionally rendered components rerendering them directly does not work. 如果您有条件地渲染了组件,则直接重新渲染它们是行不通的。 You have to wrap them in something and call render on the wrapper. 您必须将它们包装成某种东西,然后在包装器上调用render。

<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" />

Bear in mind that rendered="false" doesn't mean the component is invisible, it means it doesn't exist in the component tree. 请记住, rendered="false"并不意味着该组件是不可见的,这意味着它在组件树中不存在。

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

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