【发布时间】:2014-06-05 01:39:12
【问题描述】:
我有下面的代码。当用户更改文本字段中的数据(显示正确的信息,可能使用 getName、getAddress 方法等...)然后点击保存按钮时,用户将返回到 mainPage。如果我单击“编辑/查看个人...”并再次重新加载 editpersonal.xhtml 页面,则原始值在那里,而不是更改后的值。我已经检查了在 chrome 中发送的标头,并且无论出于何种原因,它们都被发送,它们没有被设置。每个字段都有一个 get 和 set 方法。
我在使用 inputText 字段来设置信息的其他页面中具有几乎相同的代码,并且它可以正常工作。我不知道为什么这不起作用。
mainPage.xhtml(此网页上的每个功能和命令都有效)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
<head>
<title>TODO supply a title</title>
</head>
<body>
<c:set var="userid" value="${CustomBuild.userid}"/>
#{CustomBuild.getCustomerDetails(userid)}
<c:set var="configs" value="#{CustomBuild.configs}"/>
Welcome <h:outputText escape="false" value="#{CustomBuild.name}"/>
<br></br>
Please choose from one of the following options below.
<br></br><br></br>
<h:form>
<h:commandButton id="editp" value="View/Edit Personal Information" action="editpersonal" />
<br></br><br></br>
<c:choose>
<c:when test="#{configs==0}">
<h:commandButton id="viewo" value="View Orders" action="vieworders" disabled="true"/>
</c:when>
<c:when test="#{configs!=0}">
<h:commandButton id="viewo" value="View Orders" action="vieworders" disabled="false"/>
</c:when>
</c:choose>
<br></br><br></br>
<h:commandButton id="createo" value="Create New Order" action="createorder" />
</h:form>
</body>
</html>
editpersonal.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<head>
<title>TODO supply a title</title>
</head>
<body>
<h:form>
<h:panelGrid>
<h:outputLabel value="Name: " style="font-weight:bold" />
<h:inputText value="#{CustomBuild.name}" />
<br></br>
<h:outputLabel value="Address " style="font-weight:bold" />
<h:inputText value="#{CustomBuild.address}" />
<br></br>
<h:outputLabel value="Phone Number: " style="font-weight:bold" />
<h:inputText value="#{CustomBuild.phone}" />
<br></br>
<h:outputLabel value="Email Address: " style="font-weight:bold" />
<h:inputText value="#{CustomBuild.email}" />
<br></br>
</h:panelGrid>
<h:commandButton id="Save" value="save" action="mainPage" />
</h:form>
<h:form>
<h:commandButton id="Cancel" value="cancel" action="mainPage" />
</h:form>
</body>
</html>
【问题讨论】:
-
我的一个页面有另一个问题,可能是相关的。我有使用发送 GET 请求的 foreach 语句动态生成的链接,即:orderID=1、orderID=2 等。当我执行 viewParam 并将值设置为 CustomBuild.chosenOrder 然后尝试在 html 中显示该值时,它显示为 0 而不是它应该是什么。这是一个“范围”问题吗?
-
我能够通过用旧的 sun 命名空间替换新的命名空间来解决第二个问题。因此,将 xmlns:f="xmlns.jcp.org/jsf/core" 更改为 xmlns:f="java.sun.com/jsf/core" 并且视图参数和获取请求现在正在工作。我尝试对原始问题的 xmlns:f 做同样的事情,但它没有帮助,数据仍然没有被设置/保存。
-
CustomBuild bean 的范围是什么? @理查德蔡斯
-
与问题无关:您可以在
disabled属性中移动条件,例如<h:commandButton id="viewo" value="View Orders" action="vieworders" disabled="#{configs==0}" />,而不是用 c:choose 和 c:when 写 8 行 -
Scope 是 Session Scoped,这是我认为的。我实际上 100% 确定这一点,因为文档让我感到困惑,但基本上我需要在浏览器打开时,在页面之间将所有内容保持在范围内。有点像会话在 PHP 中的工作方式。另外要注意的是,感谢@VasilLukach 提供有关禁用事物的提示,非常有帮助。
标签: java html jsf primefaces facelets