I use jsf 1.x. I do not understand where I am wrong with my code.
faces-config.xml
<managed-bean>
<managed-bean-name>mainNavigationParametersHandlerBean</managed-bean-name>
<managed-bean-class>com.test.MainNavigationParametersHandlerBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>userType</property-name>
<property-class>java.lang.String</property-class>
<value>#{param.userType}</value>
</managed-property>
</managed-bean>
My bean:
package com.test;
public class MainNavigationParametersHandlerBean {
// url parameters
private String userType = "";
public String getUserType() {
return userType;
}
public void setUserType(String userType) {
this.userType = userType;
}
}
And my jsp page (actually it uses content from j开发者_Python百科sf files):
<jsp:root
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jstl/core"
version="1.2">
<head>
</head>
<body>
<jsp:forward page="/WEB-INF/jsf/userapp-main.jsf" />
</body>
</jsp:root>
In the userapp-main.jsf I have a header where I want to print out the userType parameter's value for this url:
http://localhost:8080/index-userapp.jsp?userType=grav
but, in my xhtml page, #{mainNavigationParametersHandlerBean.userType}
seems to be empty...
Do you see why?
Thanks.
Rightclick the opened page in browser and choose View Source. Do you see the generated HTML output of JSF tags or the unparsed JSF tags plain among the HTML? I'll bet that it's the latter.
Your JSP approach is a bit weird. I'd just put the contents of userapp-main.jsp
page inside the index-userapp.jsp
page and call the page by an URL which matches the URL pattern of the FacesServlet
as definied in web.xml
. If it is for example *.jsf
, then you need to open the page by http://localhost:8080/index-userapp.jsf?userType=grav.
I'd also consider upgrading if there is room. JSP 1.2 is quite ancient (10 years old already), it's currently at 2.2 and its successor, Facelets, has already taken its place in Java EE 6 which was released almost 1.5 years ago.
精彩评论