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?