Jsf Primefaces:条件渲染组件不';我不能提交
我有一个基于下拉列表有条件呈现的字段。所有这些都没有问题,但是当我提交新呈现的组件应该是其中一部分的表单时,它没有被提交 代码相当简单:Jsf Primefaces:条件渲染组件不';我不能提交,jsf,jsf-2,rendered-attribute,Jsf,Jsf 2,Rendered Attribute,我有一个基于下拉列表有条件呈现的字段。所有这些都没有问题,但是当我提交新呈现的组件应该是其中一部分的表单时,它没有被提交 代码相当简单: <h:form id="form"> <p:layout id="layout"> ... <p:layoutUnit id="layoutUnit"> ... <p:panel id="panel">
<h:form id="form">
<p:layout id="layout">
...
<p:layoutUnit id="layoutUnit">
...
<p:panel id="panel">
<p:outputPanel id="container1">
<p:selectOneMenu id="value1" value="#{bean.value1}">
<f:selectItem itemValue="1"/>
<f:selectItem itemValue="2"/>
<f:selectItem itemValue="3"/>
<f:selectItem itemValue="18"/>
<p:ajax event="change" update="container2"/>
</p:selectOneMenu>
</p:outputPanel>
<p:outputPanel id="container2">
<p:inputText id="value2"
value="#{bean.value2}"
rendered="#{bean.value1 eq 18}"
>
</p:inputText>
</p:outputPanel>
</panel>
<div id="buttons">
<p:commandButton id="commandButton" action="#{bean.save}" value="save" />
</div>
</layoutUnit>
</layout>
</form>
...
...
尝试过的可能解决方案:
- @JSF的ViewScope不可用,因为它与CDI冲突
我使用WAS8.5(SoJSF2.0)、Primefaces和CDI。除了@Named之外,还使用CDI的@ConversationScope是一种解决方案。该范围的工作原理与JSF中的@ViewScope相当 为了让它正常工作,我只添加了示例中的代码。简言之: java
@Named
@ConversationScoped
public class Bean implements Serializable{
@Inject
private Conversation conversation;
Bean values, getters & setters
public void initConversation(){
if (!FacesContext.getCurrentInstance().isPostback() && conversation.isTransient()) {
conversation.begin();
}
}
public String endConversation(){
if(!conversation.isTransient()){
conversation.end();
}
}
public String navigateAwayFromScreen(){
endConversation();
}
}
beanOutput.xhtml
<?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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<f:event listener="#{bean.initConversation}" type="preRenderView"/>
<h:form id="form">
<p:layout id="layout">
...
<p:layoutUnit id="layoutUnit">
...
<p:panel id="panel">
<p:outputPanel id="container1">
<p:selectOneMenu id="value1" value="#{bean.value1}">
<f:selectItem itemValue="1"/>
<f:selectItem itemValue="2"/>
<f:selectItem itemValue="3"/>
<f:selectItem itemValue="18"/>
<p:ajax event="change" update="container2"/>
</p:selectOneMenu>
</p:outputPanel>
<p:outputPanel id="container2">
<p:inputText id="value2"
value="#{bean.value2}"
rendered="#{bean.value1 eq 18}"
>
</p:inputText>
</p:outputPanel>
</panel>
<div id="buttons">
<p:commandButton id="commandButton" action="#{bean.navigateAwayFromScreen}" value="Go away!" />
</div>
</layoutUnit>
</layout>
</form>
</html>
...
...
现在,一个对话在打开页面时开始(因为initConversation是从beanOutput.xhtml的顶部调用的),在单击按钮navigateAwayFromScreen时结束
(但是,如果您能够使用JSF2.2,则可以将@ViewScoped与CDI结合使用。(我说“应该”:我不需要升级。但它可能对其他人的检查很有用。)除了@Named之外,使用CDI的@ConversationScoped是一个解决方案。该范围的工作原理与JSF中的@ViewScope相当 为了让它正常工作,我只添加了示例中的代码。简言之: java
@Named
@ConversationScoped
public class Bean implements Serializable{
@Inject
private Conversation conversation;
Bean values, getters & setters
public void initConversation(){
if (!FacesContext.getCurrentInstance().isPostback() && conversation.isTransient()) {
conversation.begin();
}
}
public String endConversation(){
if(!conversation.isTransient()){
conversation.end();
}
}
public String navigateAwayFromScreen(){
endConversation();
}
}
beanOutput.xhtml
<?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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<f:event listener="#{bean.initConversation}" type="preRenderView"/>
<h:form id="form">
<p:layout id="layout">
...
<p:layoutUnit id="layoutUnit">
...
<p:panel id="panel">
<p:outputPanel id="container1">
<p:selectOneMenu id="value1" value="#{bean.value1}">
<f:selectItem itemValue="1"/>
<f:selectItem itemValue="2"/>
<f:selectItem itemValue="3"/>
<f:selectItem itemValue="18"/>
<p:ajax event="change" update="container2"/>
</p:selectOneMenu>
</p:outputPanel>
<p:outputPanel id="container2">
<p:inputText id="value2"
value="#{bean.value2}"
rendered="#{bean.value1 eq 18}"
>
</p:inputText>
</p:outputPanel>
</panel>
<div id="buttons">
<p:commandButton id="commandButton" action="#{bean.navigateAwayFromScreen}" value="Go away!" />
</div>
</layoutUnit>
</layout>
</form>
</html>
...
...
现在,一个对话在打开页面时开始(因为initConversation是从beanOutput.xhtml的顶部调用的),在单击按钮navigateAwayFromScreen时结束
(但是,如果您能够使用JSF2.2,则可以将@ViewScoped与CDI结合使用。(我说“应该”:我不需要升级。但它可能对其他人检查有用)。“因为它与CDI冲突”嗯?换句话说,您还没有使用JSF2.2,无法升级?JSF2.2有一个与CDI兼容的
@ViewScoped
注释。描述UI应该如何工作,您在UI中做什么,以及您的期望在什么时候失败。不清楚您的呈现的绑定应该完成什么。@VsevolodGolovanov:OP的案例失败,因为他的bean是请求范围而不是视图范围。现在,OP基本上是询问如何在不使bean视图限定范围的情况下保持视图限定范围的状态。“少数情况”清单毫无意义。它已经解释了很长时间,特别是OP提到的第二个链接(因此本质上是问题当前形式的重复,只要OP没有详细说明他在@ViewScoped上的具体问题),我们使用的是WAS8.5,因此是JSF2.0。我不确定是否可以升级到2.2,所以我正在寻找另一个解决方案。使用@Viewscoped时,AJAX组件中的更改会导致类似javax.faces.FacesException:使用路径验证组件时出现异常…
,或者这与此无关?当您实际使用WAS 8.5(不是java ee 7)时,为什么最初会用(不必要的)[java-ee-7]
标记来标记问题?您是通过JSF@ManagedBean
还是CDI@Named
管理bean?有了那个“冲突”,你的意思是你特别面对那个例外?(在保持@viewscope
btw的同时,这确实有潜在的关联性和可解释性)该异常与“与CDI冲突”有何关联?“因为它与CDI冲突”Hm?换句话说,您还没有使用JSF2.2,无法升级?JSF2.2有一个与CDI兼容的@ViewScoped
注释。描述UI应该如何工作,您在UI中做什么,以及您的期望在什么时候失败。不清楚您的呈现的绑定应该完成什么。@VsevolodGolovanov:OP的案例失败,因为他的bean是请求范围而不是视图范围。现在,OP基本上是询问如何维护视图范围的stat