gpt4 book ai didi

javascript - 从 javascript 更新 bean

转载 作者:行者123 更新时间:2023-11-29 21:51:58 24 4
gpt4 key购买 nike

我有一个 .xhtml 页面,我从中启动了一个 javascript,在这个 javascript 中我想更新一个 bean 的内容,我发现最简单的方法是添加一个隐藏的表单并链接所述 bean 的属性到它的值(value):

index.xhtml

<h:form id="poi-form" styleClass="invisible">
<h:inputHidden id="poi" value="#{userBean.email}" />
</h:form>

javascriptfile.js

function handleEmailResponse(resp) {
document.getElementById('poi-form:poi').value = 'usersNewEmailValue';
window.location.replace("timeline.xhtml");
}

但是,从 timeline.xhtml 来看,该值不是我预期的值(好像它没有更新),因为我看到用户在

中设置了旧电子邮件值

userBean.java

@PostConstruct
public void init() {
email = "usersOldEmailValue;
}

我是不是忘记了什么?预先感谢您的帮助!

最佳答案

您实际上忘记了提交表单,因此服务器端可以更新您的模型。

此外,如果您使用的是 PrimeFaces,您也​​可以使用 p:remoteCommand。

关于javascript - 从 javascript 更新 bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28664854/

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