简体   繁体   中英

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) . 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).

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:

<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

@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. The issue here is when saving, the parentAsset which already should be null is not null.

I am using JSF 2 to perform the tasks.

奇怪的是,是否还有其他字段可以保存parentAsset的值(我的意思是在页面中)具有某些字段,如<h:inputText value="parentAsset.shortName"/> ,则当您单击保存按钮时,会初始化一个新的parentAsset并保存,还可以对其进行调试,并查看parentAsset的哈希码以确保是否相同。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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