gpt4 book ai didi

java - :inputText value inside rich:modalPanel not binding to backing bean

转载 作者:行者123 更新时间:2023-12-01 05:15:12 25 4
gpt4 key购买 nike

当我单击“保存”按钮时,会调用“addCompany”操作,但是当我调试并在支持 bean 中看到实例变量 companyName 的值时,它显示为 null。我想我犯了一些真正愚蠢的错误。

模态 XHTML:包含在另一个 xhtml 的表单标记中。

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:f="http://java.sun.com/jsf/core">

<rich:modalPanel id="AddDmpCompanyModalId"
showWhenRendered="#{companyAdminAction.showAddCompanyModal}"
width="500"
height="340"
autosized="true">

<f:facet name="header">
<h:outputText value="Add Company"/>
</f:facet>


<a4j:outputPanel id="addDmpCompanyInputPanel">

<label style="font-weight:bold;margin-top:5px">Name: </label>
<h:inputText id="companyName" value="#{companyAdminAction.companyName}"/>

<a4j:commandLink id="submit-add-company-name-link"
immediate="true"
action="#{companyAdminAction.addCompany()}"
styleClass="button"
reRender="AddDmpCompanyModalId,addDmpCompanyInputPanel"
limitToList="true">
<span class="inner-button">Save</span>
</a4j:commandLink>


</a4j:outputPanel>

</rich:modalPanel>

</ui:composition>

支撑 bean (接缝组件)

Name("companyAdminAction")
@Scope(ScopeType.CONVERSATION)
public class CompanyAdmin {

private String companyName;

public String getCompanyName() {
return companyName;
}

public void setCompanyName(String companyName) {
this.companyName = companyName;
}

public void addCompany() {
// On click of save debugger comes here, but shows the value of
//companyName as null
}

}

最佳答案

是的,原因很简单:您正在使用immediate=true在你的<a4j:commandLink/> 。此选项使 JSF 调用addCompany()函数 BEFORE 值被转换并更新模型。

解决方案同样简单:删除 immediate=true来自 <a4j:commandLink/> 的属性.

关于java - :inputText value inside rich:modalPanel not binding to backing bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11352036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com