我正在Eclipse中创建一个JSF/Facelets Web应用程序.我已经将我的项目配置为使用由Eclipse启动/停止的Tomcat(6.0)服务器.
每当我保存文件(例如.xhtml)时,Eclipse都会重新启动应用程序,从而破坏我的HTTP会话.这很烦人,因为我经常更新我的.xhtml文件,并且应用程序不需要重新启动来检测更改.
有没有办法阻止Eclipse重新启动应用程序?具体来说,我可以将Eclipse配置为仅在保存某种类型的文件时重新启动应用程序吗?
如果我想在JSF 2.0中创建多个托管bean实例,在同一范围内使用不同的名称,我该如何处理?理想情况下,我希望等效(例如):
@ManagedBeans({name="myManagedBean1",name="myManagedBean2"})
@RequestScoped
public class MyManagedBean {
}
Run Code Online (Sandbox Code Playgroud)
谢谢 ..
以下是什么有用的?
<ui:composition template="template.xhtml">;
Run Code Online (Sandbox Code Playgroud)
"在使用的模板客户端页面中<ui:composition>,忽略标记范围之外的任何内容,并且不包含在渲染输出中"(JavaServerFaces 2.0,完整参考,第61页)
因为外面的一切都<ui:define>被忽略了,为什么要放在那里?没有什么必须放在外面<ui:define>.
但是这样做,我得到的只是模板本身,只填充了一些"可变"部分.
这似乎不是什么大问题.我不明白的另一件事是,composition元素的template属性是可选的.如果没有引用模板,它代表模板客户端是什么?
我想根据条件更改变量值,所以我尝试了以下内容:
<h:head>
<ui:param name="userCase" value="Insert" />
<ui:fragment rendered="#{employee.employeesBulkInsert==false}">
<ui:param name="userCase" value="Update" />
</ui:fragment>
<title>#{userCase} Employee </title>
</h:head>
Run Code Online (Sandbox Code Playgroud)
但它在更新的情况下不起作用,它显示一个空字符串,任何想法为什么?
我知道还有其他解决方案,比如在支持bean中定义变量,或者直接在title标签上创建条件ui片段,但我想知道为什么上面的不起作用,请指教,谢谢.
如何设置ui的id:重复
我的代码的结构是
Tabview
ui : repeat
dattable
column
checkbox
Run Code Online (Sandbox Code Playgroud)
我得到复选框的id为
tabViewId:0:j_idt45:0:dataTableId:0:checkBoxId
Run Code Online (Sandbox Code Playgroud)
它包含7件事
id of tabview
active tab
ui:repeat id
index of ui:repeat
id of dattable
row of dattable
id of checkbox
Run Code Online (Sandbox Code Playgroud)
我想指定ui的id:重复,以便它不会自己选择它.
如何设置ui的id:重复,比方说
repeatId
Run Code Online (Sandbox Code Playgroud)
代替 j_idt45
<ui:define name="description" rendered="false">
<meta name="description" content="do not render" />
</ui:define>
Run Code Online (Sandbox Code Playgroud)
我在我的xhtml页面中使用此代码,当我运行应用程序时,元描述仍在渲染.我想根据某些条件使用元描述标签.主布局:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<ui:insert name="description" />
</h:head>
...........
</html>
Run Code Online (Sandbox Code Playgroud)
网页:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
template="/templates/masterLayout.xhtml">
<ui:define name="description" rendered="false">
<meta name="description" content="do not render" />
</ui:define>
...........
</ui:composition>
Run Code Online (Sandbox Code Playgroud) 我已经使用JSF和PrimeFaces实现了一个登录表单.我在PrimeFaces展示网站上使用了这个例子.
我有一个Facelets页面来显示dataTable.现在我需要将上面的登录表单与此表页面集成.所以我在LoginBean.java中添加了几行来处理会话属性.
if (username.equals(getUsername_db()) && password.equals(getPassword_db())) {//valid user and paward
loggedIn = true;
msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Welcome", getUsername_db());
//new lines
FacesContext context2 = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) context2.getExternalContext().getSession(true);
session.setAttribute("user", username);
//end of new lines
...
Run Code Online (Sandbox Code Playgroud)
我需要隐藏在数据表中的列,如果用户没有登录.现在我的问题是,我如何才能访问里面我的Facelets页面会话属性?
我能够成功地使用我的应用程序中的模板:
<ui:decorate template="/WEB-INF/templates/mytemplate.xhtml">
Run Code Online (Sandbox Code Playgroud)
我还可以移动模板/META-INF/templates/mytemplate.xhtml一的JAR和得到这个工作:
<ui:decorate template="/templates/mytemplate.xhtml">
Run Code Online (Sandbox Code Playgroud)
我实际上想把这个文件放到文件系统(或数据库)上.我怎样才能做到这一点?我发现很多相关的东西com.sun.facelets.impl.DefaultResourceResolver,但我认为这实际上与覆盖模板的服务有关.它不是尝试解析URL,它只是试图以某种方式在类路径上获取文件.
我的Facelet中有以下代码片段:
<h:commandLink id="cmdbtn">
<f:ajax event="click" execute="@form"
listener="#{screenShotBean.takeScreenshot}" />
</h:commandLink>
Run Code Online (Sandbox Code Playgroud)
它工作正常,但当我像这样取消它,
<!-- <h:commandLink id="cmdbtn"> -->
<!-- <f:ajax event="click" execute="@form" -->
<!-- listener="#{screenShotBean.takeScreenshot}" /> -->
<!-- </h:commandLink> -->
Run Code Online (Sandbox Code Playgroud)
然后它抛出以下异常:
javax.el.PropertyNotFoundException: Property 'takeScreenshot' not found on type monstage.test.com.ScreenShotBean
at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:237)
at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:214)
at javax.el.BeanELResolver.property(BeanELResolver.java:325)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:85)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
at com.sun.faces.facelets.el.ELText$ELTextVariable.toString(ELText.java:217)
at com.sun.faces.facelets.el.ELText$ELTextComposite.toString(ELText.java:157)
at com.sun.faces.facelets.compiler.CommentInstruction.write(CommentInstruction.java:77)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:424)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at …Run Code Online (Sandbox Code Playgroud) 我参与了使用Spring Security 4.x和使用Facelets的JSF 2.2的项目.我只是注意到这个版本中的spring安全性默认情况下启用了使用请求令牌来防止跨站点请求伪造,情况是你必须将标记<sec:csrfMetaTags>放在许多页面中(如果没有,春天拒绝请求),lib spring-faces是在2.4.1中没有Facelets(XHTML)的这些标签.
我试图找到一个实现,以便使用这些框架来工作我的项目,但我找不到任何,你知道任何改编吗?
在我的情况下,我只调整了我需要的部分(此时),如果没有公共改编,我很乐意将它放入一个开源项目并尝试调整所有库.
谢谢.
UPDATE
我创建了一篇博客文章解释我的解决方案:http: //halexv.blogspot.mx/2015/07/spring-security-4x-csrf-protection-for.html