我正在尝试实现一个用户名列表,可以通过单击UP或DOWN链接重新排列.
<ul>
<ui:repeat var="user" value="#{cc.attrs.value}">
<li>
#{user.name}
<h:link outcome = "user" value = "left" onclick="#{accountController.moveDown}">
<f:param name="id" value = "${user.id}" />
</h:link>
</li>
</ui:repeat>
</ul>
Run Code Online (Sandbox Code Playgroud)
这里的问题是我似乎没有正确使用onclick属性.这样做的正确方法是什么?
编辑:根据您的建议,我将所有链接放在一个表单中:
<h:form>
<ui:repeat value="#{cc.attrs.value}" var = "user">
<div class = "user">
<h:commandLink id = "Link1" value = "Up" binding = "#{accountController.ommandLink}" action = "#{accountController.moveUserUp}">
<f:attribute name = "userId" value = "#{user.id}" />
</h:commandLink>
<h:commandLink id = "Link2" value = "Down" binding = "#{accountController.commandLink}" action = "#{accountController.moveUserDown}">
<f:attribute name = …
Run Code Online (Sandbox Code Playgroud) 我正在维护一个JSF2 Ajax应用程序,我们正在大量使用h:commandLinks
和f:ajax
标记所有操作 - 总是只重新渲染所需的内容.
当然,当执行右键单击链接并选择"在新标签中打开链接"等时,这会打破用户的预期行为.
我理解f:ajax强制生成的a
元素的href属性#
并且在onclick函数中执行所有魔术发布请求技巧 - 我现在想通过放置一些有意义的内容为"Open Link ..."操作提供后备支持链接在结果<a>
标记的href属性中.
这不会破坏"正常"的onclick行为,因为生成的javascript总是完成,return false;
但允许我使用普通的GET请求将我的用户发送到某个页面,以防他们想要在新窗口中打开链接.
有没有建立方式来做到这一点?或者有人可以指出我在JSF生命周期的哪个方向上正确的方向我可能会使用阶段监听器来进行此操作?
我在glassfish 3.0.1上使用jsf 2.0来构建我的搜索引擎的接口,当我在我的jsf页面上使用Openfaces组件时,每当我提交表单时,我都会收到以下错误消息:
java.lang.ClassCastException:[Ljava.lang.Object; 无法转换为com.sun.faces.application.view.StateHolderSaver
我没有在网上找到任何帮助,请问有什么问题?以及如何摆脱它?
谢谢.
我不想附加?faces-redirect=true
到我的每一个动作中<h:commandButton />
,而是希望一次性使用它,faces-config.xml
但我还不确定使用它的后果.
它规定redirect
将代替使用forward
.但后果是什么?这是一种不好的做法,它是否会影响持久性和servlet请求和响应?
对我来说,REDIRECT的使用仅用于正确的URL浏览器显示.我打算用这样的东西:
<navigation-rule>
<from-view-id>/*</from-view-id>
<navigation-case>
<from-outcome>*</from-outcome>
<redirect />
</navigation-case>
</navigation-rule>
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'
任何人都可以帮助我理解正确导航到页面所需的相对路径吗?
嗨我有一个像这样的代码:
<p:commandLink value="#{user.strUserid}" action="test.xhtml?faces-redirect=true"/>
Run Code Online (Sandbox Code Playgroud)
如何将参数传递给test.xhtml以获取所述页面中的值?我尝试使用<f:param>
tag.But可以获取test.xhtml
页面中的值.请建议.
例如,如果我放置以下组件并单击它,它的行为符合预期:
<h:commandLink value="Click me" action="anotherPage.jsf" />
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用Ajax:
<h:commandLink value="Click me" action="anotherPage.jsf"><f:ajax /></h:commandLink>
Run Code Online (Sandbox Code Playgroud)
它不会导航到其他页面.我错过了什么吗?这应该不起作用吗?
另一个问题是,当我在会话超时后单击使用ajax的按钮时,应用程序会重定向到登录页面,但它不会加载css文件.
有任何想法吗?
亲切的问候,
卡洛斯费雷拉
我正在使用过滤器处理JSF 2.0中的会话到期.这是代码
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
throws IOException, ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
HttpSession session = httpServletRequest.getSession(false);
if (session == null) {
//session timeout check.
if (httpServletRequest.getRequestedSessionId() != null && !httpServletRequest.isRequestedSessionIdValid()) {
System.out.println("Session has expired");
session = httpServletRequest.getSession(true);
session.setAttribute("logedin", "0"); // public user
httpServletResponse.sendRedirect(timeoutPage);
} else {
session = httpServletRequest.getSession(true);
session.setAttribute("logedin", "0");
filterChain.doFilter(httpServletRequest, httpServletResponse);
}
}
} //end of doFilter()
Run Code Online (Sandbox Code Playgroud)
但问题是,当会话到期并且用户点击后退按钮时,他会获得所有样式的页面.无论如何,当会话到期时,如果用户单击浏览器后退按钮,则他会指向timeoutPage.
还有一点,我也在我的页面上使用Prime Faces组件,比如datatable.我正在使用分页.如果会话超时,并且我单击分页,则不会出现会话到期消息.似乎ajax请求不调用过滤器?如何连接我的ajax事件,或者你可以说数据表分页事件到会话到期?
谢谢
我想实现一个导航按钮,将用户带到另一个页面.我不希望或需要运行任何验证,也不需要更新模型,等等.我已将其实现为ajaxified客户端重定向(注意,我使用的是Primefaces 3.2).
它有效 - 但这是最好的方法吗?
从"onePage.xhtml"导航到"anotherPage.xhtml"
onePage.xhtml:
...
<p:commandButton value="Navigate to Another Page"
process="@this"/>
action="anotherPage?faces-redirect=true"
...
Run Code Online (Sandbox Code Playgroud)
注意,我已经尝试使用immediate ="true",但是仍然运行Apply Request Values阶段,这导致我在托管bean中的getter中的NPE(因为我不再拥有我的getter需要的数据).
1)在JSF中使用get http变量是一个好习惯吗?似乎它试图避免这种情况.
2)这是我想要做的:在第一页上,我有一个链接列表,如果你点击链接,你有一个页面与其他链接等像树.我希望用户能够访问第三深度(例如)而无需从顶层开始(例如,通过带有get变量中相关对象ID的链接).
所以我的问题是:如何从托管bean设置get http变量?
为了得到它,这篇文章很清楚:获取http变量JSF
3)当然,如果您有其他解决方案,请随时分享.
jsf ×6
jsf-2 ×5
java ×2
navigation ×2
primefaces ×2
actionmethod ×1
ajax ×1
hyperlink ×1
mojarra ×1
onclick ×1
openfaces ×1
view ×1