PrettyFaces:@URLQueryParameter未传递给@URLAction方法

时间:2014-05-14 11:01:48

标签: prettyfaces

我无法弄清楚如何将参数从URL传递到指定的控制器方法。 所以这是我如何注释控制器:

@Component
@ManagedBean
@RequestScoped
@URLMappings(mappings={
        @URLMapping(id = "posts", pattern = "/posts/", viewId = "/faces/posts/list.xhtml"),
        @URLMapping(id = "postComments", pattern = "/posts/#{id}/comments", viewId = "/faces/posts/post_comments.xhtml")
})
public class PostsController {

  @Autowired
  private PostService postService;

  private Post post;

  @URLQueryParameter("id")
  private String id;

  public Post getPost() {        
    return postService.findById(Long.valueOf(getId()));
  }

  @URLAction(mappingId = "postsComments")
  public void loadPost() {
    System.out.println("in loadPost, ID: " + getId());
  }
}

以下是观点:

<ui:repeat value="#{postsController.posts}" var="post">
                    <tr>
                        <td>#{post.title}</td>
                        <td>
                            <pretty:link mappingId="postComments">
                                <f:param value="#{post.id}" />
                                Comments
                            </pretty:link>
                        </td>
                        <td><a href="#">Edit</a></td>
                        <td><a href="#">Delete</a></td>
                    </tr>
                </ui:repeat>

我的身份证总是空的。然而,在生成的HTML代码中,id总是正确的:

posts/1/comments
posts/2/comments
posts/3/comments

有什么想法吗?我正在使用PrettuFaces 3.3.3。 谢谢。

1 个答案:

答案 0 :(得分:0)

您可以使用id方法获取getPost()参数: FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id")