【问题标题】:How to retrieve value of a ui:param in the backing bean of same page如何在同一页面的支持 bean 中检索 ui:param 的值
【发布时间】:2013-05-07 07:16:19
【问题描述】:

我想在我的支持 bean 中检索 ui:param 的值,但不是在从一个页面导航到另一个页面时从同一页面检索
我试过了:

FaceletContext faceletContext = (FaceletContext) FacesContext.getCurrentInstance().getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
String formId = (String) faceletContext.getAttribute("formId");


我也试过它返回 null:

String param = FacesContext.getCurrentInstance().getExternalContext()
            .getRequestParameterMap().get(name);

它也返回 null
我尝试在 preRenderView 和 postValidate 事件中获取这些值,并以两种方式返回 null
不要忘记我想获取页面的 ui:param 的值我在

【问题讨论】:

  • 试试 f:param insted of ui:param.
  • 我试过它也返回null
  • 当我遇到同样的问题时,我遇到了这个问题。对我来说,事实证明错误消息有点误导。它实际上不是<ui:param> 对象引用,它是null,但该对象上的方法没有在我使用的接口上声明。我的建议是在 UI 参数中“值”所指的对象上设置断点,并检查 it 是否真的 is null

标签: java jsf-2 facelets composite-component


【解决方案1】:

我想这个问题与我也面临的问题非常相似。 请允许我解释一下这个问题。

当“p:dialog”下包含两个“ui:include”时,我遇到了这个问题。 像这样的

<p:dialog header="Customer Selection Criteria" widgetVar="customerSelectionDialog" width="1200" position="center" appendToBody="true">
        <h:form id="customerForm">
            <p:outputPanel id="customerSelection">
                <ui:include src="../INTERNAL/8500.xhtml">
                    <ui:param name="showCidSelect" value="1" /> 
                    <ui:param name="targetObject" value="#{customerDetailsInquiry.cf8444.cg1014.cg1014cidnumb}" />
                </ui:include>
                <p:commandButton rendered="false" value="#{COMMON.COMMON_SELECTBUTTON}" action="#{customerDetailsInquiry.tchelp.handleReturnFromCustomerSelectionCriteria}" oncomplete="customerSelectionDialog.hide();" update=":mainForm:cf8444icg1014c1002" >
                    <f:setPropertyActionListener value="#{customerSearchEngine}" target="#{flash.customerSearchEngine}"/>
                </p:commandButton>
            </p:outputPanel>
        </h:form>
    </p:dialog>
    <p:dialog closeOnEscape="true" modal="true" appendToBody="false" header="Entity Stack" widgetVar="entityStackDialog" width="400" >
        <h:form id="entityForm">
            <ui:include src="../INTERNAL/StackedEntity.xhtml">
                <ui:param name="displayCaption" value="CID Numbers" />

                <ui:param name="department" value="8" /> 
                <ui:param name="stackedObject" value="#{customerDetailsInquiry.cf8444.cg1014.cg1014cidnumb}" />
            </ui:include>

        </h:form>
    </p:dialog>

现在,当我尝试启动 8500.xhtml 时,我的 showCidSelect 参数值总是返回“null”。 如果我按如下方式替换代码,这很好用

<p:dialog header="Customer Selection Criteria" widgetVar="customerSelectionDialog" width="1200" position="center" appendToBody="true">
        <h:form id="customerForm">
            <p:outputPanel id="customerSelection">
                <ui:include src="../INTERNAL/8500.xhtml">
                    <ui:param name="showCidSelect" value="1" /> 
                    <ui:param name="targetObject" value="#{customerDetailsInquiry.cf8444.cg1014.cg1014cidnumb}" />
                </ui:include>
                <p:commandButton rendered="false" value="#{COMMON.COMMON_SELECTBUTTON}" action="#{customerDetailsInquiry.tchelp.handleReturnFromCustomerSelectionCriteria}" oncomplete="customerSelectionDialog.hide();" update=":mainForm:cf8444icg1014c1002" >
                    <f:setPropertyActionListener value="#{customerSearchEngine}" target="#{flash.customerSearchEngine}"/>
                </p:commandButton>
            </p:outputPanel>
        </h:form>
    </p:dialog>
    <p:dialog closeOnEscape="true" modal="true" appendToBody="false" header="Entity Stack" widgetVar="entityStackDialog" width="400" >
        <h:form id="entityForm">
            <ui:include src="../INTERNAL/StackedEntity.xhtml">
                <ui:param name="displayCaption" value="CID Numbers" />
                <ui:param name="showCidSelect" value="1" />
                <ui:param name="department" value="8" /> 
                <ui:param name="stackedObject" value="#{customerDetailsInquiry.cf8444.cg1014.cg1014cidnumb}" />
            </ui:include>

        </h:form>
    </p:dialog>

我必须为两个“ui:include”显式传递 showCidSelect 才能使其工作。

这可能是您也面临的同样问题吗?
贴一些 UI 示例代码。

【讨论】:

    猜你喜欢
    • 2013-01-05
    • 1970-01-01
    • 2012-06-29
    • 1970-01-01
    • 2018-04-04
    • 2013-02-16
    • 2011-08-22
    • 1970-01-01
    相关资源
    最近更新 更多