[英]JSF 2 Property does not reflect the changes after an ajax action
This is the situation: 这种情况:
I have a popup box to select one of the item listed(click the showParentAssetSearchButton) . 我有一个弹出框来选择列出的项目之一(单击showParentAssetSearchButton)。 Once selected the value of the selected item will be display in the main screen.
选择后,所选项目的值将显示在主屏幕中。 In the main screen, there will be a button to clear up the item that selected.
在主屏幕中,将有一个按钮可以清除所选的项目。 It will trigger an ajax action to the managed bean to clear the binding value(via click clearParentAssetButton).
它将触发对托管bean的ajax操作以清除绑定值(通过单击clearParentAssetButton)。
When i do debugging, the value is clear and will not show in the main screen. 当我进行调试时,该值很清楚,不会在主屏幕中显示。 However when i click on the save button, i notice that the property that should be empty is not actually empty.
但是,当我单击保存按钮时,我注意到应该为空的属性实际上并不为空。 It still keep the value.
它仍然保持价值。
Following is the snippet UI code: 以下是代码段UI代码:
<h:panelGroup id="myregion">
<p:inputText id="parentAsset"
ondblclick="parentAssetDlg.show()"
value="#{assetMasterCreatePage.parentAsset.shortName}"
rendered="#{not empty assetMasterCreatePage.parentAsset}"/>
</h:panelGroup>
<p:commandButton icon="ui-icon-search"
id="showParentAssetSearchButton"
type="button"
title="#{msg.label_asset_search_parent_asset}"
onclick="parentAssetDlg.show()" />
<p:commandButton icon="ui-icon-trash"
id="clearParentAssetButton"
title="#{msg.label_asset_clear_parent_asset}"
actionListener="#{assetMasterCreatePage.doResetParentAsset}"
immediate="true"
process="@form"
update="clearParentAssetButton, myregion"
disabled="#{empty assetMasterCreatePage.parentAsset}" />
........
<p:commandButton value="#{msg.button_save}" icon="ui-icon-disk"
action="#{assetMasterCreatePage.doSaveAsset}" />
This is the managed bean snippet 这是托管bean片段
@ManagedBean(name="assetMasterCreatePage")
@ViewScoped
public class AssetMasterCreatePage extends DefaultAssetMasterPage {
private AssetMaster assetMaster;
private AssetMaster parentAsset;
..........
.........
public void doResetParentAsset(){
parentAsset = null;
}
public String doSaveAssetMaster(){
assetMaster.setParentAsset(parentAsset);
assetMasterService.save(assetMaster);
MessageUtils.saveSuccessMessage();
return "save";
}
}
As you can see, when the button of the clearParentAssetButton is click, it will trigger ajax action #{assetMasterCreatePage.doResetParentAsset} to reset the value of the parentAsset. 如您所见,当单击clearParentAssetButton的按钮时,它将触发Ajax操作#{assetMasterCreatePage.doResetParentAsset}以重置parentAsset的值。 The issue here is when saving, the parentAsset which already should be null is not null.
这里的问题是保存时,已经为null的parentAsset不为null。
I am using JSF 2 to perform the tasks. 我正在使用JSF 2执行任务。
奇怪的是,是否还有其他字段可以保存parentAsset
的值(我的意思是在页面中)具有某些字段,如<h:inputText value="parentAsset.shortName"/>
,则当您单击保存按钮时,会初始化一个新的parentAsset
并保存,还可以对其进行调试,并查看parentAsset
的哈希码以确保是否相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.