[英]PrimeFaces inputText not rendering sometimes
我之所以在這里,是因為我在應用程序中遇到了一個非常奇怪的問題,它是:我有一個使用JSF和EJB的電子商務應用程序,並且我試圖用用戶信息填寫表單。 問題是,當有一個登錄用戶時,我的表單無法很好地顯示;當我沒有登錄時,他的顯示也很好:O我正在使用托管bean(MB)進行處理,並且他正在存儲一個表示以下內容的帳戶對象用戶登錄的帳戶。 我正在使用jsf Composite創建表單並為xhtml頁面創建模板。
此外,我還收到了玻璃魚的以下警告:
由於未渲染,因此我使用螢火蟲對其進行了檢查。
這是我的XHTML頁面代碼(用戶可以訪問/Form.xhtml):
<ui:composition template="template/common/commonLayout.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:component="http://java.sun.com/jsf/composite/component">
<ui:define name="title">Formulaire</ui:define>
<ui:define name="content">
<ui:fragment rendered="#{dataManagedBean.connected}">
<component:FormValidateCartComponent title="Valider mon panier" first_name="yann" />
</ui:fragment>
<ui:fragment rendered="#{not dataManagedBean.connected}">
<component:FormValidateCartComponent title="Valider mon panier" first_name="NoName" />
</ui:fragment>
</ui:define>
</ui:composition>
這是我的表單組件:
<?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"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<composite:interface>
<composite:attribute name="title" />
<composite:attribute name="first_name"/>
<!--ajouter des attributs pour le cas ou l'utilisateur est connecté -->
</composite:interface>
<composite:implementation>
<h:form id="form" class="span5 offset4">
<h2>#{cc.attrs.title}</h2>
<p:panel header="Adresse de Livraison">
<h:panelGrid id="gridpanel" columns="2" style="margin-bottom:10px">
<h:outputLabel for="firstName" value="Prenom : " />
<p:inputText id="firstName" value="#{cc.attrs.first_name}" binding="#{firstName}"/>
<h:outputLabel for="lastName" value="Nom : " />
<p:inputText id="lastName" binding="#{lastName}"/>
<h:outputLabel for="street" value="Rue : " />
<p:inputText id="street" binding="#{street}" />
<h:outputLabel for="postalCode" value="Code Postale : " />
<p:inputText id="postalCode" binding="#{postalCode}" />
<h:outputLabel for="city" value="Ville : "/>
<p:inputText id="city" binding="#{city}"/>
<h:outputLabel for="pbutton"/>
<h:commandButton id="pbutton" class="paypal-button"
action="Cart.xhtml"
actionListener="#{dataManagedBean.creatOrder(firstName.value,lastName.value,street.value,postalCode.value,city.value)}" />
</h:panelGrid>
</p:panel>
<ui:fragment rendered="#{!dataManagedBean.connected}">
<p:panel header="Connexion">
<h:panelGrid id="grid" columns="2" style="margin-bottom:10px">
<h:outputLabel for="login" value="Login : "/>
<p:inputText id="login" binding="#{login}" />
<h:outputLabel for="password" value="Mot de passe : "/>
<p:inputText id="password" binding="#{password}" />
<h:outputLabel for="accountCreationButton"/>
<h:commandButton id="accountCreationButton" value="Créer un compte" action="Cart.xhtml" actionListener="#{dataManagedBean.createAccount(login.value,password.value,dataManagedBean.creatOrder(firstName.value,lastName.value,street.value,postalCode.value,city.value))}"/>
</h:panelGrid>
</p:panel>
</ui:fragment>
</h:form>
</composite:implementation>
</html>
目前,我只是試圖設置first_name,但是就像我之前登錄時所說的那樣,html渲染中缺少每個inputText。 這怎么可能 ? 當我斷開連接並訪問該表單時,一切都很好...謝謝您的幫助,我真的不知道為什么會這樣...我的連接和斷開連接功能只是通過JPA獲得,要求使用登錄名和密碼的帳戶,並且斷開連接是只需在托管bean中將account設置為null。
編輯:通過使用c:if我的問題解決了! 為什么,我不知道...讓我知道你是否有線索:)
托管Bean部分代碼:
public void connect(String login, String password) {
account = client.connect(login, password);
}
public String disconnect() {
if (account != null) {
account = null;
}
return "index.xhtml?faces-redirect=true";
}
public boolean isConnected() {
return account != null;
}
UI片段會給視圖范圍和某些屬性帶來一些麻煩,我只是簡單地用ah:panelGroup來更改ui:frament,如果您只將呈現的屬性JSF不會生成span或div,則只會渲染內部內容編輯:就像balusC所說,ui:fagment無法解決問題,在快速閱讀后我找不到錯誤,您使用的范圍是什么?它是CDI托管bean還是舊面孔bean?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.