0

索引.xhtml

...
<ui:include src="#{part.fullPath}">
   <ui:param name="topListId" value="#{part.topListId}" rendered="#{part.topListNeeded}"/>
</ui:include>
...

fullPath是类似的东西"WEB-INF/parts/customPart.xhtml"。它运行良好,并且每个部分都正确包含和渲染。但是当我有要传递的参数时,问题就出现了,即当part.topListNeeded==true

我想要包含的部分之一具有fullPath=WEB-INF/parts/topList.xhtml, topListNeeded=true, topListId=1.

顶部列表.xhtml

<h:body>        
   <f:metadata>
      <f:viewParam name="topListId" value="#{topListBean.topListId}" />
      <f:viewAction action="#{topListBean.init}" />
   </f:metadata>
   <ui:composition>
      <f:view>
         <ui:repeat value="#{topListBean.list}" var="row" rendered="#{!topListBean.listEmpty}">
            <h:outputText value="#{row.someData}"/>
         </ui:repeat>
      </f:view>
   </ui:composition>
</h:body>

topListBean.java

@ViewScoped
@ManagedBean
public class TopListBean {
    private LinkedList<Event> list;
    private boolean listEmpty;
    private long topListId;

    public TopListEvents() {
        System.out.println("DEBUG ::: TopListEvents:constructor");
    }

    @PostConstruct // if I ommit this, init() is never called
    public void init() {
        System.out.println("DEBUG ::: TopListEvents:init");

        topListId = Long.parseLong(FacesContext.getCurrentInstance().
        getExternalContext().getRequestParameterMap().
        get("topListId")); // EXCEPTION: java.lang.NumberFormatException: null !!!

        // ...fetch toplist elements based on topListId...

        // ...getters and setters...
    }

我有输出:
DEBUG ::: TopListEvents:constructor
DEBUG ::: TopListEvents:init
...但随后抛出异常(java.lang.NumberFormatException: null)。我在评论中标记了那个地方。

我的索引页面上可能会有多个带有参数的部分。参数将始终存储在part.topListId. 传递这些参数的最佳方法是什么?

4

0 回答 0