我有简单的测试网络应用程序:第一页 - index.xhtml:
<?xml version='1.0' encoding='UTF-8' ?>
<html>
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
First page
<h:form>
<h:commandButton value="Go to Next page" action="next"/>
</h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
和下一页 - next.xhtml:
<?xml version='1.0' encoding='UTF-8' ?>
<html>
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
Next page
<h:form>
<h:commandButton value="Go to First page" action="index"/>
</h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我运行我的应用程序时,我在浏览器上有该URL:
http://localhost:8080/Test/
Run Code Online (Sandbox Code Playgroud)
和index.xhtml作为第一页.
然后当我点击"转到下一页"我有网址
http://localhost:8080/Test/index.xhtml
Run Code Online (Sandbox Code Playgroud)
和next.xhtml页面.当我点击"转到第一页"页面更改(到index.xhtml)但是url它
http://localhost:8080/Test/next.xhtml
Run Code Online (Sandbox Code Playgroud)
web.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping> …Run Code Online (Sandbox Code Playgroud) 我在JSF页面之间导航时遇到问题.单击命令按钮时,大多数导航都会发生.命令按钮的操作返回一个字符串.
我的登录页面是我的欢迎页面.这是在我的web.xml中:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>faces/pages/index.xhtml</welcome-file>
</welcome-file-list>
Run Code Online (Sandbox Code Playgroud)
在我浏览器的地址栏中,该页面显示为:
http://localhost:8080/ui/faces/pages/index.xhtml
Run Code Online (Sandbox Code Playgroud)
一旦身份验证发生,该函数返回此字符串:
"/ui/faces/pages/home.xhtml"
Run Code Online (Sandbox Code Playgroud)
我要导航到的文件位于:
pages/home.xhtml
Run Code Online (Sandbox Code Playgroud)
但是当导航应该发生时,我收到此错误:
无法找到与from-view-id'/pages/index.xhtml'匹配的导航案例,用于行动'#{indexPageController.login()}'与结果'/ui/faces/pages/home.xhtml'
任何人都可以帮助我理解正确导航到页面所需的相对路径吗?
我有JSF 2.2功能的问题<f:viewAction action="#{...}/>.我把这个标签放在我的XHTML-Page中,它被称为viewActionStart.xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head />
<h:body>
<f:view>
<f:metadata>
<f:viewAction action="#{redirect.getView()}" onPostback="true"
immediate="true" />
</f:metadata>
</f:view>
<h:outputText value="If you see that text, the viewAction was not performed." />
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
如果我直接访问此XHTML页面,一切正常:redirect.getView()调用该方法并执行重定向到另一个页面.
现在我有了我的登陆页面,它显示在viewActionStart-Page之前.有一个按钮,基本上应该导航到我的viewActionStart-Page来显示<f:viewAction>效果.以下代码来自此着陆页index.xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<f:view>
<h:form>
<h:commandButton action="viewActionStart.xhtml"
value="To f:viewAction Page" />
</h:form>
</f:view>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
如果我点击该命令按钮,则会显示viewActionStart.xhtml的内容.为什么JSF忽略了<f:viewAction>?我不明白为什么viewAction每个页面加载不起作用.我尝试了那些onPostback …
在部署GAE + primefaces应用程序时,我遇到以下错误:
com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException: Error Rendering View[/CreateEmployee.xhtml]
javax.el.ELException: /CreateEmployee.xhtml: Could not find property saveEmployee in class com.fetchinglife.domain.data.dao.EmployeeRepositoryImpl
at com.sun.faces.facelets.compiler.AttributeInstruction.write(AttributeInstruction.java:94)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:302)
at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
Run Code Online (Sandbox Code Playgroud)
甚至saveEmployee已经EmployeeRepositoryImpl上课了.这是怎么造成的,我该如何解决?是否有任何注释我需要额外添加?
让我们想象一下,我的JSF 2应用程序中有两个页面:第一页显示一个对象表(汽车或其他),另一个页面能够显示一个特定对象的详细信息.表页面位于请求范围内,因为每次用户请求时都应重新加载对象.详细信息页面在视图范围内.因此,当我单击表格内的对象时,该对象应显示在详细信息页面中.通过重定向,我可以转到详细信息页面,但详细信息页面为空,因为生成了新的vew.好吧,我可以将范围更改为会话但这会导致其他问题,所以我希望在视图范围内有详细信息页面.有没有办法将参数传递给新生成的视图范围bean?
更新1
这是第一次尝试使用视图参数的代码片段.评论说这不起作用.该值作为请求参数传递,但在目标页面中,该值为null.
表格页面:
<h:button value="Go to details" outcome="targetPage">
<f:param name="carId" value="This is a test" />
</h:button>
Run Code Online (Sandbox Code Playgroud)
详情页面:
<f:metadata>
<f:viewParam name="carId" value="#{bean.id}" />
<f:event type="preRenderView" listener="#{bean.loadData}"/>
</f:metadata>
Run Code Online (Sandbox Code Playgroud)
豆的详细信息页面:
private String id;
public String getId() {
return id;
}
public void setId( String id ) {
this.id = id;
}
public void loadData() {
System.out.println( "Id: " + id );
}
Run Code Online (Sandbox Code Playgroud)
更新2
我发现了自己的错误.元数据部分位于模板文件中.当我将标签放入主文件的详细信息页面时,它可以工作.非常感谢你.
我有一个JSF/PrimeFaces表单页面设置来编辑一些配置细节.底部是提交和取消按钮实现为CommandButton."取消"按钮如下所示:
<p:commandButton
action="priorPage.xhtml?faces-redirect=true"
value="Cancel" />
Run Code Online (Sandbox Code Playgroud)
问题是视图bean仍然会对输入到表单中的数据进行更多处理,而不是我想要的.它不会更新数据库中的任何内容,但是如果(比方说)我将字符串输入到正在查找bean中的数字的字段中,它仍然会产生错误.
当然,我的解决方案的一部分是让bean优雅地处理那种糟糕的数据,我正在研究它.但是我也想调整那个按钮,这样它就可以将用户带到前一页.我可以设置一些属性来阻止表单被处理吗?
jsf ×6
navigation ×2
primefaces ×2
view ×2
el ×1
jsf-2 ×1
jsf-2.2 ×1
parameters ×1
scope ×1
tomcat7 ×1
url ×1