gpt4 book ai didi

jsf - 如何从 View 中为 jsf 支持 bean 设置隐藏值

转载 作者:行者123 更新时间:2023-12-02 15:34:45 26 4
gpt4 key购买 nike

我有一个硬编码值,需要在提交表单时将其设置为 jsf 支持 bean。

谁能告诉我这个。

 <h:inputHidden value="#{leaveBean.fApproverEmail}"></h:inputHidden>

但我想发送一个硬编码值代替 "#{leaveBean.fApproverEmail}" 并将其设置为支持 bean 的属性..

最佳答案

选项 1。

将您的属性初始化为您的硬编码值。 JSF 将在表单提交时自动更新此属性。因此,如果它发生了变化,您最终将在您的操作方法中获得更新的属性值。

String fApproverEmail = "default";

<h:inputHidden id="app" value="#{leaveBean.fApproverEmail}" />

选项 2。

有一个纯 HTML <input type="hidden">或无值(value) <h:inputHidden> .这样提交的值在请求参数映射中可用。所以你将能够从 ExternalContext#getRequestParameterMap() 中获取它以它的名字作为键。但请注意,如果您的对象不是字符串,则您必须自己进行转换/验证,而操作方法是放置该逻辑的错误位置。

String fApproverEmail;
public void action() {
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
String s1 = ec.getRequestParameterMap().get("plain");
String s2 = ec.getRequestParameterMap().get("form:jsf");
fApproverEmail = ...;//and-or other logic
}

<h:form id="form">
<h:inputHidden id="jsf" />
<input type="hidden" id="plain" name="plain" value="#{backingBean.fApproverEmail}"/>
...
</h:form>

关于jsf - 如何从 View 中为 jsf 支持 bean 设置隐藏值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19852216/

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