0

index.xhtml:

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

fullPath is something like "WEB-INF/parts/customPart.xhtml". It works well and each part is properly included and rendered. But the problem appears when I have the parameter to pass, i.e. when part.topListNeeded==true

One of the parts that I want to include has fullPath=WEB-INF/parts/topList.xhtml, topListNeeded=true, topListId=1.

topList.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...
    }

I have the output:
DEBUG ::: TopListEvents:constructor
DEBUG ::: TopListEvents:init
...but then the exception is thrown (java.lang.NumberFormatException: null). I marked that place in the comments.

I will probably have multiple parts with parameters on my index page. The parameter will always be stored in part.topListId. What is the best way to pass those parameters?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
vtomic85
  • 590
  • 1
  • 11
  • 32
  • What package is `@ViewScoped` from? – Tiny May 04 '15 at 09:25
  • @Tiny, the package of the TopListBean class is toplist.beans, if that's what you meant. – vtomic85 May 10 '15 at 11:51
  • Is it from `javax.faces.bean.ViewScoped`? (It should not mistakenly be imported from `javax.faces.view.ViewScoped` (the managed bean will simply be treated as a request scoped bean in that case), since beans are managed by JSF (`@ManagedBean`) and not by the container itself -- CDI (`@Named`)). – Tiny May 10 '15 at 12:26
  • Yes, it's javax.faces.bean.ViewScoped – vtomic85 May 10 '15 at 14:39

0 Answers0