我有这个代码:
<h:form>
<h:commandLink value="Créer un compte" onclick="dlg3.show();"/>
</h:form>
<p:dialog id="modalDialoog" widgetVar="dlg3" draggable="false" resizable="false" dynamic="true" header="Inscription">
<center>
<p:panel id="xyzBody">
<h:form id="inscri-f">
<h:panelGrid id="loginPan" columns="2" bgcolor="White">
<h:outputText value="Nom d'utilisateur :" />
<p:inputText id="username" value="#{demandeBean.login}"></p:inputText>
<h:outputText value="Mot de passe :" />
<p:password id="pwd" value="#{demandeBean.pwd}"/>
<h:commandButton value="Envoyer demande" update=":inscri-f:cr"
actionListener="#{demandeBean.envoi_dde}"></h:commandButton>
<h:commandButton value="Retour" action="page1?faces-redirect=true"></h:commandButton>
<p:outputPanel id="cr">
<h:outputText rendered="#{demandeBean.saved}" value="#{demandeBean.message}"/>
</p:outputPanel>
</h:panelGrid>
</h:form>
</p:panel>
</center>
</p:dialog>
Run Code Online (Sandbox Code Playgroud)
我的问题是当我单击 commandLink 时显示“Créer un compte”对话框并且它很快消失。
我对 EJB 和 Bean 管理事务都很陌生。在放弃互联网之后,我发现我可以编写一个 EJ 会话 Bean,它以“bean 管理的方式”执行事务,如下所示:
@TransactionManagement(value=TransactionManagementType.BEAN)
@Stateless
public class OperationBean {
@Resource
private UserTransaction userTransaction;
public void operation() {
try{
userTransaction.begin();
Op1();
Op2();
Op3();
userTransaction.commit();
} catch(Exception e){
userTransaction.rollback();
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我不明白如果 Op3() 抛出异常会发生什么。Op1() 和 Op2() 如何撤消?
另一个问题是如何将其绑定到 JSF?我需要在 JSF 中编写一个表单,将其数据发送到服务器,OperationBean 根据接收到的数据执行 3 个操作。这些操作确实涉及数据库操作(3个更新),单独来看没有意义。
谢谢!
在使用 PrimeFaces 3.3 的项目中,文件上传运行正常。我删除了 Primefaces 3.3 并添加了 3.5。从那时起,我就无法进行文件上传了。之前我添加了 commons-io 和 commons.fileupload,我不确定是否还需要它们,所以我也保留了这些 jar 文件。
错误
java.lang.NullPointerException
at org.primefaces.component.fileupload.FileUploadRenderer.decodeSimple(FileUploadRenderer.java:56)
at org.primefaces.component.fileupload.FileUploadRenderer.decode(FileUploadRenderer.java:47)
at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:836)
at javax.faces.component.UIInput.decode(UIInput.java:771)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1228)
at javax.faces.component.UIInput.processDecodes(UIInput.java:676)
at javax.faces.component.UIForm.processDecodes(UIForm.java:225)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1223)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1223)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:929)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:77)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at …Run Code Online (Sandbox Code Playgroud) 我想在错误的字段旁边显示错误。我的页面有该代码:
<!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">
<ui:composition template="/WEB-INF/templates/basic.xhtml">
<ui:define name="content">
<h:form>
<h:panelGrid columns="3">
<h:outputText value="Firstname"/>
<h:inputText id="firstName" value="#{account.firstName}" required="true">
<f:validator validatorId="stringAlphaValidator"/>
</h:inputText>
<h:message for="firstName" errorStyle="color:red; display:block"/>
<h:outputText value="Lastname"/>
<h:inputText id="lastName" value="#{account.lastName}" required="true">
<f:validator validatorId="stringAlphaValidator"/>
</h:inputText>
<h:message for="lastName" errorStyle="color:red; display:block"/>
<h:outputText value="Login"/>
<h:inputText id="login" value="#{account.login}" required="true">
<f:validator validatorId="stringAlphaValidator"/>
</h:inputText>
<h:message for="login" errorStyle="color:red; display:block"/>
<h:outputText value="Password"/>
<h:inputText id="password" value="#{account.password}" required="true">
</h:inputText>
<h:message for="password" errorStyle="color:red; display:block"/>
<h:outputText value="Address"/>
<h:inputText id="address" value="#{account.address}" required="true">
<f:validator validatorId="stringAlphaNumericValidator"/>
</h:inputText> …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中添加了一个受BalusC 代码教程启发的生命周期侦听器,并添加了时间戳以监控每个阶段花费的时间。我原以为“调用应用程序”阶段会花费最长的时间,但是日志让我意识到它花费了大约 827 毫秒,而“渲染响应”阶段花费了 2890 毫秒,然后我想知道在此期间花费了多少时间“渲染响应”阶段。
据我快速浏览后了解规范,在此阶段唯一完成的事情就是“渲染”(并且还保存响应的状态,但在这里无关紧要),而所有应用程序代码都应该更早地调用. 它总是真的吗?
例如,如果我的页面包含一个默认值为 #{myBean.valueAfterPost} 的表单,则 valueAfterPost 的 getter 是在“调用应用程序”期间还是在“渲染响应”期间调用?
什么容易在渲染响应阶段消耗大量时间?
我有 ap:inputText 其值在 PrimeFaces 的自动生成组件中,我必须设置 required="true",当 Disabled 为 true 时验证不起作用。这是我的代码:
<p:inputText id="depCode" disabled="true" required="true"
value="#{bean.depCode}"
style="width:100%"
requiredMessage="Please set a reference generator"
/>
Run Code Online (Sandbox Code Playgroud)
任何建议请
我米试图从它返回一个托管bean方法显示的图像byte[]与<o:graphicImage>使用omnifaces我部署omnifaces 2.1在WEB_INF/lib
这里是我的代码
注册.java
public byte[] getImage() throws IOException{
return Utils.toByteArray(Faces.getResourceAsStream("/resources/images/loader.gif"));
}
Run Code Online (Sandbox Code Playgroud)
主页.xhtml
<!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"
xmlns:o="http://omnifaces.org/ui">
<h:head>
<h:outputStylesheet library="css" name="style.css"></h:outputStylesheet>
<style>
.center {
align: center;
}
</style>
</h:head>
<h:body>
<h:form>
<table style="float:right;margin-top:5px;">
<tr><td><h:commandLink action="/user/second.xhtml" style="float:right;">Second page</h:commandLink></td>
<td><h:commandLink action="#{login.logout}" style="float:right;">Logout</h:commandLink></td></tr>
</table>
</h:form>
<h:form>
<div style="margin: auto;">
<h:messages globalOnly="true" infoStyle="display:none" styleClass="error" style="list-style-type:none;"/>
<h:messages globalOnly="true" errorStyle="display:none" styleClass="green" style="list-style-type:none;"/>
<h4 align="center">Welcome to JSF #{login.username} Dude</h4>
<h3 align="center">User Profile</h3> …Run Code Online (Sandbox Code Playgroud) 使用 JSF 尝试一个简单的应用程序时出现错误。
javax.el.MethodNotFoundException: Method not found: com.jsf.training.beans.TravelBean@4b6b8628.travelInfo()
at org.apache.el.util.ReflectionUtil.getMethod(ReflectionUtil.java:245)
at org.apache.el.parser.AstValue.invoke(AstValue.java:271)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:149)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:818)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
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.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Run Code Online (Sandbox Code Playgroud)
我的托管 bean 是:
@ManagedBean (name="travelBean")
@SessionScoped
public …Run Code Online (Sandbox Code Playgroud) 我可以在那里发生哪些可能的事件?谢谢你 :)
<p:inputText>
<p:ajax event="" />
</p:inputText>
Run Code Online (Sandbox Code Playgroud)
尝试查看<p:ajax> 事件列表,但文档没有列出每个组件的可能事件:p
我有一个页面有不同的计算,这是由 ajax 完成的。
在页面的末尾应该有一个提示文本,每次计算后都会更新。
为此,我使用了autoUpdatePrimefaces的功能。
当我最初加载页面时,文本显示正确。同样在第一次计算后,文本会正确刷新。但是如果我做进一步的计算,无论balanceController.getBalance()返回哪个值,文本都不会再改变。
当我调试我的代码时,我看到它balanceController.getDetails()运行正确并且还返回了所需的文本。只有我页面上的内容没有刷新。当我手动重新加载页面(使用浏览器)时,会出现正确的文本。
<p:autoUpdate/>仅在第一次计算期间执行并更新选项卡内容的原因可能是什么?
余额页面.xhtml
<p:tab title="Further details" rendered="#{balanceController.showDetails()}">
<p:autoUpdate/>
<h:outputText value="#{balanceController.details}"/>
</p:tab>
Run Code Online (Sandbox Code Playgroud)
平衡控制器.java
public String getDetails() {
if ( getBalance() >= 0 ) {
return "Your current balance is: " + Double.toString(getBalance());
} else {
return "Your credit has been used up!";
}
}
Run Code Online (Sandbox Code Playgroud) jsf ×10
primefaces ×5
ajax ×1
dialog ×1
eclipse ×1
ejb ×1
file-io ×1
file-upload ×1
java ×1
javabeans ×1
omnifaces ×1
tomcat ×1
transactions ×1
validation ×1