f:param不发送参数

问题描述 投票:0回答:2

在我的代码中,我将摄影师的id发送到另一页。但是,当我试图得到它时,我得到了空。这是jsf代码:

 <h:commandButton action="/viewGallery.xhtml" value="View Gallery" class="btn btn-lg">
        <f:param name="pgid" value="#{logged.logged.photographerid}" />
 </h:commandButton>

我的bean变量:

@ManagedBean(value = "album")
@RequestScoped
public class AlbumDAO {

private CachedRowSetImpl crs;
private Album a;
private ArrayList<Album> aList;

@ManagedProperty(value = "#{param.pgid}")
private int pgid;

在那里我打印bean中的参数:

        FacesContext fc = FacesContext.getCurrentInstance();
        Map<String, String> params = fc.getExternalContext().getRequestParameterMap();
        System.out.println("params = " + params);
        System.out.println("params.get(pgid) = " + params.get("pgid"));

当我打印时,我得到以下内容:

     INFO:   params = {j_idt7=j_idt7, j_idt7:j_idt15=Go to profile,  javax.faces.ViewState=6834092215913674538:3363757559364464357}
     INFO:   params.get(pgid) = null

有人能帮助我吗?它曾经工作但现在停止了,我不知道。

jsf post
2个回答
1
投票

f:param会发送参数。不幸的是,它会在动作开始之前发送参数。

人们会期望(至少我做过)它会做动作并计算参数,然后进行重定向,但f:param的值已经在动作开始之前计算出来(所以经常有null,0或类似的东西)参数)和重定向不反映行动结果。

如果需要根据解决方案更新操作的结果,则需要从操作本身启动重定向。看看here如何做到这一点。


0
投票

<f:param />应该有效。但是有一种传递参数的替代方法。试试看

<h:button outcome="/viewGallery.xhtml?faces-redirect=true&amp;pgid=#{logged.logged.photographerid}" value="View Gallery" class="btn btn-lg">
</h:button>
© www.soinside.com 2019 - 2024. All rights reserved.