【问题标题】:How to pass an object to a java method using a4j:commandbutton如何使用 a4j:commandbutton 将对象传递给 java 方法
【发布时间】:2015-10-01 08:16:56
【问题描述】:

我有一个丰富的:模态面板(代码如下)。我想将#{currentLeg} 传递给action="#{legHandler.assignAndInitLoadPlanning} 中调用的方法。但是当我调试时,在方法@​​987654323@,resolveVariable("currentLeg"); 返回一个对象,其所有属性值都等于null。它的属性不应该为空。

此外,这个rich:modal 是从同一个jsp 文件上的a4j:commandLink onclick="showUnitDialog(); 调用的。如果我将上面所说的 onclick 更改为 onclick="#{legHandler.assignAndInitLoadPlanning}",则 currentleg 将被正确传递,但我不能这样做,因为我需要显示一个弹出窗口(这是一个 rich:modalpanel)。我正在使用 JSF 1。

我已经尝试过保持活动并设置变量,但仍然无法正常工作。 currentLeg 似乎没有正确通过。你知道为什么吗?

<rich:modalPanel id="unitDialog" width="400" height="100">
    <f:facet name="header">
        <h:panelGroup>
            <h:outputText value="Please Select Unit for the Leg"></h:outputText>
            <h:outputText value="#{currentLeg.legId}"></h:outputText>
        </h:panelGroup>
    </f:facet>

        <h:panelGrid width="100%" columns="2" columnClasses="colStyle1, colStyle2">
            <h:selectOneRadio value="legHandler.unit">
                <f:selectItem itemValue="kg" itemLabel="kg" />
                <f:selectItem itemValue="lb" itemLabel="lb" />
            </h:selectOneRadio>


        </h:panelGrid>
        <h:panelGrid style="text-align: center" columns="3"
                columnClasses="col1, col2" width="100%">

      <a4j:commandButton  value="Apply" styleClass="big_btn" 
                               id="applyButton" immediate="true" 
                               action="#{legHandler.assignAndInitLoadPlanning}" 
                                oncomplete="{#{rich:component('unitDialog')}.hide();}"> 
                                </a4j:commandButton>                                


            <a4j:commandButton value="Cancel" styleClass="big_btn"
                immediate="true"
                id="closeUnitPopupDialog"
                onclick="#{rich:component('unitDialog')}.hide();"/>
        </h:panelGrid>

</rich:modalPanel>

【问题讨论】:

    标签: jsf richfaces parameter-passing


    【解决方案1】:

    如果您使用的是 EL 2.2+,您可以简单地将值作为参数传递:

    <a4j:commandButton action="#{legHandler.assignAndInitLoadPlanning(currentLeg)}" … />
    

    否则使用a4j:actionparam并将值保存到bean

    <a4j:commandButton …>
        <a4j:actionparam name="currentLeg" value="#{currentLeg}" assignTo="#{legHandler.currentLeg}" />
    <a4j:commandButton>
    

    【讨论】:

    • 对我不起作用:(但是当我将值更改为 #{currentLeg.legId} 时,它已正确传递。legId 只是一个 int。currentLeg 是一个对象。看来我可以传递一个 int 但不传递一个对象。你怎么看?
    猜你喜欢
    • 1970-01-01
    • 2019-01-02
    • 2017-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-18
    相关资源
    最近更新 更多