我不太熟悉<h:messages>在JSF中使用该元素.我正在尝试做的是使用它来显示由我的支持bean中的方法生成的不同严重性的全局消息列表.获取消息FacesContext并不是一个问题,我的代码是这样的:
FacesMessage message;
FacesContext context =
FacesContext.getCurrentInstance();
message = new FacesMessage(
FacesMessage.SEVERITY_INFO,
"test message summary 1",
"test message detail 1");
context.addMessage(null, message);
message = new FacesMessage(
FacesMessage.SEVERITY_WARN,
"test message summary 2",
"test message detail 2");
context.addMessage(null, message);
message = new FacesMessage(
FacesMessage.SEVERITY_ERROR,
"test message summary 3",
"test message detail 3");
context.addMessage(null, message);
// add more messages...
Run Code Online (Sandbox Code Playgroud)
一切正常.我的问题是尝试使<h:messages>标签的输出在页面上看起来很好.这是我的JSP文件的相关部分:
<h:panelGrid border="1" columns="1" id="messagesPanelGrid">
<h:messages
id="messagesOutput"
showSummary="true"
showDetail="true"
layout="table"
infoClass="info-message"
warnClass="warn-message"
errorClass="error-message"
fatalClass="fatal-message"
globalOnly="true" />
</h:panelGrid>
Run Code Online (Sandbox Code Playgroud)
这一直看起来像页面上的垃圾.我正在使用外部CSS样式表来定义样式类.我尝试过使用 …
我有一个XHTML页面,提交回归自己.
辅助bean是会话范围的.在重定向到自身时,页面呈现h:dataable两次并且给出了重复的id错误.我可以在视觉上看到正在呈现两次的表彼此相邻.
我重申它有一些事情,事实上,支持bean具有面向html表的属性,并在返回时它再次创建但是解决方案是什么.
以下内容大致来自JavaBeat的本教程.唯一的区别是我的支持bean是Session Scoped.
我也重申我的问题可能不会清除它,但代码应该:)这里是
支持豆
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.html.HtmlDataTable;
import javax.faces.event.ValueChangeEvent;
import com.example.common.web.bean.BaseBean;
@ManagedBean(name = "registrationBean")
@SessionScoped
public class RegisterationViewManagedBean extends BaseBean {
private String field;
private List<Employee> employees;
private Employee employee;
private HtmlDataTable htmlDataTable;
private List<Employee> list = new ArrayList();
public void setSelected(ValueChangeEvent event) {
employee = (Employee) htmlDataTable.getRowData();
list = new ArrayList<Employee>();
list.add(employee);
}
public List<Employee> getEmployees() {
return employees;
}
public void setEmployees(List<Employee> employees) {
this.employees = …Run Code Online (Sandbox Code Playgroud) 我正在使用Apache MyFaces 2.0.我注意到oam.Flash.RENDERMAP.TOKEN为每个视图创建了一个cookie ,即使我没有使用Flash范围而且我已经设置了org.apache.myfaces.DISABLE_FLASH_SCOPE=true.
我该如何删除oam.Flash.RENDERMAP.TOKENcookie?这是WebSphere特定的问题
我认为有一个索引页面(在我的例子中是index.xhtml)是一个很好的做法.我想在索引页面上传递一些操作(例如在struts中:<c:redirect url="list.do" />我转到struts动作类,没有任何链接和按钮)我知道如果我想使用导航我应该使用commandLink-s或按钮).我可以<h:commandButton>用onclick javascript函数编写,但我觉得这不是最好的选择.
我是JSF的新手(使用JSF 2.0),我需要你的建议.从索引页重定向到控制器中的操作的最佳实践是什么?
///新版本
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html 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">
<f:view>
<ui:insert name="metadata"/>
<f:viewParam name="action" value="listItems.xtml"/>
<f:event type="preRenderView" listener="#{yourBean.methodInManagedBean}" />
<h:body></h:body>
</f:view>
</html>
public class ForwardBean {
private String action;
// getter, setter
public void navigate(PhaseEvent event) {
FacesContext facesContext = FacesContext.getCurrentInstance();
String outcome = action;
facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, null, outcome);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用MyFaces 2.2.3与客户端状态保存+ PrimeFaces
在询问如何阻止BalusC告诉我在不同会话中重用ViewState之后,我可以通过覆盖渲染器来注入我自己的CSRF令牌,让值为CSRF令牌,
我正在寻找一个不会强迫我修改我的xhtml页面的解决方案:)
BalusC提出了一种通过扩展来防止CSRF攻击的更好方法ViewHandlerWrapper,并且它工作得很好,我只需要通过restoreView以下方式修改一下
public UIViewRoot restoreView(FacesContext context, String viewId) {
UIViewRoot view = super.restoreView(context, viewId);
if (getCsrfToken(context).equals(view.getAttributes().get(CSRF_TOKEN_KEY))) {
return view;
} else {
HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
if (session != null) {
session.invalidate(); //invalidate session so (my custom and unrelated) PhaseListener will notice that its a bad session now
}
try {
FacesContext.getCurrentInstance().getExternalContext().redirect("CSRF detected and blocked"); //better looking …Run Code Online (Sandbox Code Playgroud) 我有哪些选项可以从JSP页面中读取当前用户的角色?我知道visibleOnUserRole="myRole"Tomahawk组件的属性,但我需要角色来处理比简单可见性更复杂的事情.
我在循环HashMap以将其值打印到屏幕上时遇到了一些麻烦.有人可以仔细检查我的代码,看看我做错了什么.我似乎找不到任何错误,但必须有一些东西.
在servlet中,我将以下内容添加到请求中:
Map<String, String> facetValues = new HashMap<String, String>();
// Filling the map
req.setAttribute(facetField.getName(), facetValues);
Run Code Online (Sandbox Code Playgroud)
在一种情况下,"facetField.getName()"评估为"纪律".所以在我的页面中我有以下内容:
<ui:repeat value="${requestScope.discipline}" var="item">
<li>Item: <c:out value="${item}"/>, Key: <c:out value="${item.key}"/>, Value: <c:out value="${item.item}"/></li>
</ui:repeat>
Run Code Online (Sandbox Code Playgroud)
循环运行一次,但所有输出都是空白的?!?如果它已经超过循环一次,我至少会期望项目中的某些东西.检查Facelets的调试弹出窗口,纪律是在那里和循环.将它打印到屏幕会产生一些看起来像我的地图(我缩短了输出):
{300=0, 1600=0, 200=0, ... , 2200=0}
Run Code Online (Sandbox Code Playgroud)
我也尝试过ac:forEach,但我得到了相同的结果.所以有人有任何想法,我出错了吗?
谢谢你的任何意见,李
这是我试图在这里完成的后续工作/sf/ask/511974571/
我已经设法将图像作为UploadedFile对象,但我似乎无法将其保存到磁盘.我想在本地保存它(C:\Temp例如),这样当我运行我的应用程序时,我可以test.jpg从我的桌面上传文件(例如)并将其保存在服务器上(例如,在C:\Temp).
我的bean非常简单:
import org.apache.myfaces.custom.fileupload.UploadedFile;
public class PatientBB {
private UploadedFile uploadedFile;
public UploadedFile getUploadedFile(){
return this.uploadedFile;
}
.
public void setUploadedFile(UploadedFile uploadedFile){
this.uploadedFile = uploadedFile;
}
.
public String actionSubmitImage(){
//This is th part I need help with. how do I save it in my C?
}
Run Code Online (Sandbox Code Playgroud)
我非常感谢所有的帮助,谢谢!
这是我的简单示例:
Index.xhtml 在root中:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Title</title>
</h:head>
<h:body>
<h:form>
<h:inputText value="#{index.variable}"></h:inputText>
<h:commandButton action="#{index.submit()}" type="submit"></h:commandButton>
</h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
它的ManagedBean:
import java.io.IOException;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
@ManagedBean
@ViewScoped
public class Index implements Serializable {
@ManagedProperty("#{sessionBean}")
private SessionBean sessionBean; /*getter&setter*/
private String variable; /*getter&setter*/
public void submit() {
sessionBean.setAsd(variable);
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
try {
context.redirect("next");
} catch (IOException ex) { …Run Code Online (Sandbox Code Playgroud) 我的h有问题:commandButton"登录":当我使用@ViewScoped并按下此按钮时会出现ViewExpiredException,但是当我使用@SessionScoped时,没有任何错误.
堆栈跟踪:
javax.faces.application.ViewExpiredException: /pages/register.xhtmlNo saved view state could be found for the view identifier: /pages/register.xhtml
at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:132)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Run Code Online (Sandbox Code Playgroud)
我的页面:
<h:form>
<h:panelGrid columns="2" >
<h:outputLabel value="Login:"/>
<h:inputText value="#{registerController.registerLog}"/>
<h:outputLabel value="#{msg.password}"/>
<h:inputSecret id="pass" …Run Code Online (Sandbox Code Playgroud)