0

I'm here because I'm stuck with a very strange problem in my application which is the following : I have an e-commerce application with JSF and EJB, and I'm trying to fill out a form with user's informations. The problem is that my form is not displayed well when there is a logged user and when i'm not logged he's displayed very well :O I'm using a managed bean (MB) to make treatments, and he's storing an account object representing the user logged account. I'm using jsf composite to create my form and templating for xhtml pages.

In addition I've got these warnings from glassfish :

  • WARNING: Unable to find component with ID firstName in view.
  • WARNING: Unable to find component with ID lastName in view.
  • WARNING: Unable to find component with ID street in view.
  • WARNING: Unable to find component with ID postalCode in view.
  • WARNING: Unable to find component with ID city in view.

Because they are not rendered, I checked it with firebug.

Here is my XHTML page code (/Form.xhtml accessed by the user) :

<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>

Here is my form component :

<?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>

For the moment i'm just trying to set the first_name but like said before when i'm logged every inputText is missing in the html render. How is it possible ? When I disconnect and access the form everything is OK ... Thank's for the help I really don't know why is this happening ... My connect and disconnect functions are just getting by JPA request the account with login and password and disconnect is just setting account to null in managed bean.

EDIT : By using c:if my problems are solved ! Why , I don't know ... Let me know if you have a clue :)

Managed Bean partial code :

    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;
    }
Ko2r
  • 1,541
  • 1
  • 11
  • 24

1 Answers1

0

UI fragment causes some troubles with view scoped and some properties, i sugest simply change the ui:frament with a h:panelGroup, if you just put the rendered attribute JSF will not generate a span nor a div, will just render or not the inside content Edited: Looks like balusC says, ui:fagment will not resolve the problem, after a fast reading i could not find an error, whats the scope that you use?, it's a CDI managed bean or an old faces bean?

rekiem87
  • 1,565
  • 18
  • 33
  • I've tested with h:panelGroup and the problem is the same ... So it's not UI fragment but i'll keep the panelGroup :) – Ko2r Dec 09 '13 at 19:42
  • 1
    The `` is an UI component, not a taghandler. The symptoms you describe matches taghandlers only, such as ``, ``, etc (those *not* having `rendered` attribute). This "answer" is therefore misleading and very unlikely to solve the concrete problem. – BalusC Dec 09 '13 at 19:49
  • Ok then ill check your example code and let you know if i find something, and one more thing, remember that if you use Composite components, JSF will prepend an id to each component in your composite component, so, you should check this for the "unabled to find id" warnings, @balusc, sorry, i didn't know that ui:fragment is a UiComponent, added to my knowledge now. – rekiem87 Dec 09 '13 at 19:49
  • Regarding your `disconnect()` method, it's _not_ the standard way of doing it in JSF. Your `disconnect()` method is just nullifying an object. Instead, you better use the provided `logout()` , and `invalidateSession()` methods from Faces and Servlet's API. It will ensure that the session really expires on logout, and the unused session scoped beans are dumped from the JVM during the next garbage collection. It's safer, optimize memory management, and is the standard. –  Dec 10 '13 at 02:00