【发布时间】:2014-01-15 19:51:50
【问题描述】:
我是 jsf 的新手,我想在单击 h:link 时显示问题的详细信息,为此我需要在两个 jsf 页面之间传递问题 ID(我有一个详细信息页面和另一个页面显示问题列表以显示其详细信息)但此 id 是 Long 类型,因此我需要对其进行转换以便能够在数据库中查找它,但我不知道该怎么做。
我用谷歌搜索,但搜索后我写的代码不起作用。这是代码
<p:dataList value="#{questionBean.questionsForums}" var="quests"
itemType="none">
<p:panel >
<f:facet name="header">
<h:outputText value="#{quests.nbupvote}"
style="margin-right:30px;color:#cdcdcd" class="voteBox" />
<h:outputText class="font-custom" value="#{quests.titre}" />
</f:facet>
<h:link value="Consulter Détails" outcome="question">
<f:param name="quesId" value="#{quests.quesPk}" >
</f:param>
</h:link>
</p:panel>
</p:dataList>
这是 managedBean 的代码
private String quesPk;
private Question detailQuestion;
public Question getDetailQuestion() {
return detailQuestion=qDao.selectDetail(Long.valueOf(quesPk));
}
public void setDetailQuestion(Question detailQuestion) {
this.detailQuestion = detailQuestion;
}
日志中的这个例外
2014-01-16T21:11:22.145+0100|Grave: Error Rendering View[/question.xhtml]
javax.el.ELException: /question.xhtml @52,24 value="#{questionBean.detailQuestion}": java.lang.NumberFormatException: null
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIData.getValue(UIData.java:732)
Caused by: javax.el.ELException: java.lang.NumberFormatException: null
at javax.el.BeanELResolver.getValue(BeanELResolver.java:368)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstValue.getValue(AstValue.java:140)
at com.sun.el.parser.AstValue.getValue(AstValue.java:204)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
... 53 more
Caused by: java.lang.NumberFormatException: null
at java.lang.Long.parseLong(Long.java:404)
at java.lang.Long.valueOf(Long.java:540)
at com.portail.managedBeans.QuestionBean.getDetailQuestion(QuestionBean.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
2014-01-16T21:11:22.220+0100|Avertissement: StandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NumberFormatException: null
at java.lang.Long.parseLong(Long.java:404)
at java.lang.Long.valueOf(Long.java:540)
at com.portail.managedBeans.QuestionBean.getDetailQuestion(QuestionBean.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:363)
这是问题细节的代码
<h:head>
<f:metadata>
<f:viewParam name="quesId" value="#{questionBean.quesPk}" converter="javax.faces.Long" />
</f:metadata>
</h:head>
<h:form>
<p:dataList value="#{questionBean.detailQuestion}" var="quests"
itemType="none">
<h:outputText value="1" style="margin-right:30px;color:#cdcdcd"
class="voteBox" />
<h3><h:outputText class="font-custom"
value="#{quests.titre}" /></h3><br/><p:separator></p:separator>
<h:outputText class="font-custom"
value="#{quests.contenu}" />
<div class="navfooter" style="margin-left: 20%">
<ul>
<li><a href="profil.xhtml">Modifier</a></li>
<li style="margin-left: 40%">Auteur</li>
</ul>
</div>
</p:dataList>
我正在使用 eclipse kepler 和 jsf2 和 primefaces。如果你知道怎么做,请告诉我
【问题讨论】:
-
删除
f:convertNumber行。转换器已用于 f:param。 -
我删除了它,但 f:param 中的转换器无法正常工作我收到此异常
com.sun.faces.mgbean.ManagedBeanPreProcessingException: Erreur inattendue lors du traitement du bean géré «questionBean» Caused by: com.sun.faces.mgbean.ManagedBeanPreProcessingException: Erreur inattendue lors du traitement de la propriété gérée «quesPk» at com.sun.faces.mgbean.ManagedBeanBuilder.bake(ManagedBeanBuilder.java:117) at com.sun.faces.mgbean.BeanManager.preProcessBean(BeanManager.java:353) ... 68 more Caused by: java.lang.IllegalArgumentException: can't parse argument number: param.quesId
标签: jsf-2 type-conversion