【问题标题】:f:setPropertyActionListener not calling methodf:setPropertyActionListener 不调用方法
【发布时间】:2012-12-18 18:37:56
【问题描述】:

我需要一些帮助。我在 JSF 上使用 f:setPropertyActionListener 时遇到问题。问题是 JSF 没有在目标方法上设置任何值。

部分xhtml代码如下:

<h:form>
    <fieldset style="width:100; margin-left: 350px; margin-top: 250px; position:absolute; border-style: none">
        <p:dataGrid var="prod" value="#{productoController.arrProductosRelevantes}" 
                    columns="5" rows="10" paginator="true">

            <p:panel style="text-align:center">  
                <h:panelGrid columns="1" style="width:100%" columnClasses="colStyle1" rowClasses="rowStyle1" >  
                    <p:graphicImage value="#{prod.imagenUrl}" style="width:100px; height:100px"/>   
                    <h:outputText value="#{prod.marca}" style="width:40px"/>  
                    <p:commandLink value="Ver" action="#{productoController.visualizarProducto()}">  
                        <f:setPropertyActionListener value="#{prod}"   
                                                     target="#{productoController.productoSeleccionado()}" />  
                    </p:commandLink>
                </h:panelGrid>  
            </p:panel>  
        </p:dataGrid>  
    </fieldset>
</h:form>

支持 bean 如下(最相关):

public Producto getProductoSeleccionado() {
    return productoSeleccionado;
}

public void setProductoSeleccionado(Producto productoSeleccionado) {
    if (productoSeleccionado != null) {
        this.productoSeleccionado = productoSeleccionado;
        arrComentarios = null;
        arrProductosComplementarios = null;
        arrProductosSuplementarios = null;
    }
}

public String visualizarProducto() {
    if (arrComentarios == null) {
        obtenerComentarios();
    }
    if (arrProductosComplementarios == null) {
        obtenerArrProductosComplementarios();
    }
    if (arrProductosSuplementarios == null) {
        obtenerArrProductosSuplementarios();
    }
    return "visualizarProducto.xhtml?faces-redirect=true";
}


public ArrayList<Producto> getArrProductosRelevantes() {
    return arrProductosRelevantes;
}

public void obtenerArrProductosRelevantes() {
    clienteDAO = new ClienteDAO();
    productoDAO = new ProductoDAO();
    cliente = clienteDAO.getClientePorId(Sesion.IDCLIENTE);
    arrProductosRelevantes = productoDAO.obtenerProductoRelevantesPorCliente(cliente);
}

顺便说一句,我正在使用@SessionScoped。

任何帮助将不胜感激,谢谢。

【问题讨论】:

    标签: jsf primefaces


    【解决方案1】:

    f:setPropertyActionListenertarget 属性应该是属性,而不是方法。这意味着,如果您设置target="#{productoController.productoSeleccionado}",它将调用productoController bean 中的setProductoSeleccionado(Producto prod) 方法,并将您为value 属性设置的值作为参数传递。

    您所指的方法productoSeleccionado() 可能甚至不存在于您的代码中。所以,只要去掉括号就可以了:

    <f:setPropertyActionListener value="#{prod}"
                   target="#{productoController.productoSeleccionado}" />
    

    【讨论】:

    • 实际上有一个名为 setProductoSeleccionado() 的方法,正如我之前在 backbean 代码中显示的那样,即使去掉括号,它也不会设置产品
    • 另外,我已经通过其他 JSF 页面使用了该方法,但在这个页面中它只是不起作用
    • 我知道 setter 在那里,但你不是指它,你指的是 productoSeleccionado() 方法。现在,当你去掉括号时,setter 确实被引用了,为什么它现在不工作可能是另一回事。你的 bean 是什么范围?
    • 那么你应该已经设置好了。您可以将问题中的代码更新为您现在使用的代码吗?
    • 我没有将数据网格用于我的特定目的,而是将其更改为数据表,它工作正常。感谢您的宝贵时间
    猜你喜欢
    • 1970-01-01
    • 2013-04-22
    • 1970-01-01
    • 2011-09-24
    • 1970-01-01
    • 2018-03-30
    • 1970-01-01
    • 2013-07-24
    • 1970-01-01
    相关资源
    最近更新 更多