Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 获取表单中RequestScope bean的页面参数_Jsf_Jsf 2 - Fatal编程技术网

Jsf 获取表单中RequestScope bean的页面参数

Jsf 获取表单中RequestScope bean的页面参数,jsf,jsf-2,Jsf,Jsf 2,我有以下一页: <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="htt

我有以下一页:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"        
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:p="http://primefaces.org/ui"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:ui="http://java.sun.com/jsf/facelets">



<h:head>
    <title>Fire - Registration</title>
</h:head>

<h:body>

    <f:view>
        <f:event type="preRenderView" listener="#{confirmPasswordResetBean.bindSessionKey()}"/>
    </f:view>

    <p:growl id="growl" showDetail="true" life="5000" />

    <h:form>

        <p:panel header="Select your new password">

            <h:panelGrid columns="2" cellpadding="5">

                <p:outputLabel for="newPassword" value="Type your new password"/>
                <p:password id="newPassword" 
                            value="#{confirmPasswordResetBean.firstPassword}"
                            feedback="true"/>

                <p:outputLabel for="retypedPassword" value="Retype your password"/>
                <p:password id="retypedPassword" 
                            value="#{confirmPasswordResetBean.secondPassword}"/>

            </h:panelGrid>

            <p:commandButton id="confirmButton" 
                             value="reset" 
                             action="#{confirmPasswordResetBean.doResetPassword()}"
                             update=":growl"/>

        </p:panel>       

    </h:form>

</h:body>

火警登记

上面使用的支持bean是RequestScope的,页面本身只接受一个参数(sessionKey)…我想做的是: 1.将sessionKey绑定到支持bean中的变量。这很简单。 2.当客户机按下commandButton时,在同一bean中执行专用逻辑时,使用sessionKey的绑定值


问题是按下按钮启动一个新的请求,这会使当前bean(具有绑定值)以及外部页面上下文无效…因此,我失去了从bean或页面参数获取sessionKey的所有方法…我如何解决这个问题?我对web编程和JSF都比较陌生,所以如果这有一个明显的答案,请原谅。

将bean放在视图范围内,这样它就可以在与同一视图交互时长时间存在,或者通过
将请求参数传递给后续请求

<p:commandButton ...>
    <f:param name="sessionKey" value="#{param.sessionKey}" />
</p:commandButton>

顺便说一下,您更希望使用
将请求参数直接绑定到bean

<f:metadata>
    <f:viewParam name="sessionKey" value="#{bean.sessionKey}" />
</f:metadata>

另见: