无法创建 Managedbean 在 URL 上传递参数时出错
我试图在 URL 上传递参数,但收到托管 bean“无法实例化类:”错误。 代码在这里:
创建 url:
<h:outputLink id="link"
value="#{facesContext.externalContext.requestContextPath}/Public/Home/altKanallar.jsf?id=#{item.id}&name=#{item.name}">
<h:outputText value="#{item.name}" />
</h:outputLink>
altKanallar.jsf
<h:form>
<div style="text-align: center;">
<div style="text-align: left;">
<h:panelGrid style="font-size: 12px; text-decoration:none; " width="100%">
<h:dataTable value="#{altKanallarBean.categories}" var="item" style=" width : 100%;">
<h:column>
<h:outputLink id="link"
value="#{facesContext.externalContext.requestContextPath}/Public/Home/default.jsf">
<h:outputText value="#{item.name}" />
</h:outputLink>
<div style="style=clear:both; font-size:1px; height:2px; line-height:1px;">
</div>
<div style="border-bottom:1px solid #D3E8FF; font-size:1px; height:1px; line-height:1px;">
</div>
<div style="style=clear:both; font-size:1px; height:2px; line-height:1px;">
</div>
</h:column>
</h:dataTable>
</h:panelGrid>
</div>
</h:form>
AltKanallarBean.java
public class AltKanallarBean {
private List<com.uzmantv.data.category.Item> categories;
public AltKanallarBean(){
HttpServletRequest request=(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
System.out.println(request.getParameter("name"));
System.out.println(request.getParameter("id"));
categories = RestServices.getCategoriesById(Long.parseLong(request.getParameter("id"))).getItems();
name = request.getParameter("name");
}
public List<com.uzmantv.data.category.Item> getCategories() {
return categories;
}
public void setCategories(List<com.uzmantv.data.category.Item> categories) {
this.categories = categories;
}
}
I'm trying to pass parameters on URL but I get Managed bean "Cant instantiate class:" error.
Code is Here:
create url:
<h:outputLink id="link"
value="#{facesContext.externalContext.requestContextPath}/Public/Home/altKanallar.jsf?id=#{item.id}&name=#{item.name}">
<h:outputText value="#{item.name}" />
</h:outputLink>
altKanallar.jsf
<h:form>
<div style="text-align: center;">
<div style="text-align: left;">
<h:panelGrid style="font-size: 12px; text-decoration:none; " width="100%">
<h:dataTable value="#{altKanallarBean.categories}" var="item" style=" width : 100%;">
<h:column>
<h:outputLink id="link"
value="#{facesContext.externalContext.requestContextPath}/Public/Home/default.jsf">
<h:outputText value="#{item.name}" />
</h:outputLink>
<div style="style=clear:both; font-size:1px; height:2px; line-height:1px;">
</div>
<div style="border-bottom:1px solid #D3E8FF; font-size:1px; height:1px; line-height:1px;">
</div>
<div style="style=clear:both; font-size:1px; height:2px; line-height:1px;">
</div>
</h:column>
</h:dataTable>
</h:panelGrid>
</div>
</h:form>
AltKanallarBean.java
public class AltKanallarBean {
private List<com.uzmantv.data.category.Item> categories;
public AltKanallarBean(){
HttpServletRequest request=(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
System.out.println(request.getParameter("name"));
System.out.println(request.getParameter("id"));
categories = RestServices.getCategoriesById(Long.parseLong(request.getParameter("id"))).getItems();
name = request.getParameter("name");
}
public List<com.uzmantv.data.category.Item> getCategories() {
return categories;
}
public void setCategories(List<com.uzmantv.data.category.Item> categories) {
this.categories = categories;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保构造函数 AltKanallarBean() 不会引发异常。
一般来说,不建议在构造函数中调用业务逻辑。
Make sure that constructor AltKanallarBean() does not throw an exception.
In general this is not recommended to invoke business logic in constructors.
感谢您的支持。问题已经解决了。
Jboss 没有部署
AltKanallarBean
类。花了几个小时才决定关闭并重新打开 Eclipse 并清理 jboss。Thanks for your support. Problem has solved.
Jboss didn't deployed the
AltKanallarBean
class. it took hours to decide close and reopen Eclipse and clean jboss.