Primefaces JSF页面中给出的输入并没有将该值设置为托管bean变量
我是JSF的新手。我在应用程序中使用JSF2和PrimeFaces4.0。正如标题中所述,xhtml页面中给出的输入值并没有将该值设置为ManagedBean。我已经尝试了所有可能的组合 growlMessage.xhtmlPrimefaces JSF页面中给出的输入并没有将该值设置为托管bean变量,primefaces,jsf-2,Primefaces,Jsf 2,我是JSF的新手。我在应用程序中使用JSF2和PrimeFaces4.0。正如标题中所述,xhtml页面中给出的输入值并没有将该值设置为ManagedBean。我已经尝试了所有可能的组合 growlMessage.xhtml <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form>
<p:growl id="growl" showDetail="true" sticky="true" />
<p:panel id="panelID" header="Growl">
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="msg" value="Message:" />
<p:inputText id="msg" value="#{growlView.message}" required="true" />
</h:panelGrid>
<p:commandButton value="Save" actionListener="#{growlView.saveMessage}"/>
</p:panel>
</h:form>
</h:body>
</html>
hy
换成
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form>
<p:growl id="growl" showDetail="true" sticky="true" autoUpdate="true"/>
<p:panel id="panelID" header="Growl">
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="msg" value="Message:" />
<p:inputText id="msg" value="#{pageView.message}" required="true" />
</h:panelGrid>
<p:commandButton value="Save" action="#{pageView.saveMessage}" update="growl"/>
</p:panel>
</h:form>
</h:body>
</html>
与
hy
换成
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form>
<p:growl id="growl" showDetail="true" sticky="true" autoUpdate="true"/>
<p:panel id="panelID" header="Growl">
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="msg" value="Message:" />
<p:inputText id="msg" value="#{pageView.message}" required="true" />
</h:panelGrid>
<p:commandButton value="Save" action="#{pageView.saveMessage}" update="growl"/>
</p:panel>
</h:form>
</h:body>
</html>
与
您是否有充分的理由使用JSF2.0而不是2.2?您应该使用CDI而不是JSF托管Bean,这或多或少是不推荐的。所以,使用
@Named
@ViewScoped
public class GrowlView implements Serializable
确保ViewScope注释来自javax.faces.view。xhtml的开头应该使用新的名称空间:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
您有充分的理由使用JSF2.0而不是2.2吗?您应该使用CDI而不是JSF托管Bean,这或多或少是不推荐的。所以,使用
@Named
@ViewScoped
public class GrowlView implements Serializable
确保ViewScope注释来自javax.faces.view。xhtml的开头应该使用新的名称空间:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
您的命令按钮应如下所示(根据PrimeFaces showcase):
您是否尝试过为托管bean设置更大的作用域,例如@SessionScoped
?
(仅用于测试目的)。因此,您可以排除可能的范围问题。您的命令按钮应该如下所示(根据PrimeFaces showcase):
您是否尝试过为托管bean设置更大的作用域,例如@SessionScoped
?
(仅用于测试目的)。因此,您可以排除可能的范围问题。尝试以下代码:使用
过程
和部分提交
属性:
<p:commandButton value="Save" actionListener="#{growlView.saveMessage}" update="growl" process="@form" partialSubmit="true"/>
尝试以下代码:使用
过程
和部分提交
属性:
<p:commandButton value="Save" actionListener="#{growlView.saveMessage}" update="growl" process="@form" partialSubmit="true"/>
感谢您的解决方案。不幸的是,这个解决方案不起作用。托管bean不会被解雇。请告诉我您在控制台中看到了什么,我无法得到任何结果。当我按下保存按钮时,它必须显示我输入的信息。但它什么也没用。你在控制台上看到的这个:@@@@你好?没有。S.O.P声明中给出的内容未打印出来。saveMessage()方法无法获取解决方案的InvokedTanks。不幸的是,这个解决方案不起作用。托管bean不会被解雇。请告诉我您在控制台中看到了什么,我无法得到任何结果。当我按下保存按钮时,它必须显示我输入的信息。但它什么也没用。你在控制台上看到的这个:@@@@你好?没有。S.O.P声明中给出的内容未打印出来。saveMessage()方法未被调用他为什么要这样做?JSF2.0运行良好。如果不重要的话,你不必总是在你的项目中添加像CDI这样的大东西,因为我测试了他的代码,只有在这样做的时候它才能工作。哦,因为建议转向CDI:和。对于初学者来说,开始使用JSF管理的bean毫无意义,除非您知道要维护现有系统。但是非常感谢你们的否决票。在这个简单的例子中,CDI是不必要的。谢谢大家的努力。我找到了解决方案,我的应用程序运行正常。他为什么要这样做?JSF2.0运行良好。如果不重要的话,你不必总是在你的项目中添加像CDI这样的大东西,因为我测试了他的代码,只有在这样做的时候它才能工作。哦,因为建议转向CDI:和。对于初学者来说,开始使用JSF管理的bean毫无意义,除非您知道要维护现有系统。但是非常感谢你们的否决票。在这个简单的例子中,CDI是不必要的。谢谢大家的努力。我找到了解决方案,我的应用程序运行正常