1

I am quite crude on client side, so may be this is a very easy problem for who is more founded than me in JSF (very very easy! :D ) but I am loosing my head from some days.. lucky just in my spare time. But I need help at that (dead) point. Please help or I will stay all my nights glued to the keyboard!

I made a .xhtml page with two forms and the second one points to a Session Bean that initialize the object to create and redirect to the page with the form to assign values to its variable.

This is the first .xhtml page:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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">
    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Modify A Cafeteria Element</title>        
    </h:head>
    <h:body>

        <f:view>
            <h:form>
                <h1><h:outputText value="Modify A Cafeteria Element"/></h1>
                <h:panelGrid columns="2">
                    <h:outputLabel value="Description:" for="description" />
                    <h:inputText id="description" value="#{cafeteriaElementBean.cafeteriaElement.description}" title="Description" />                   

                </h:panelGrid>

                <p:commandButton action="#{cafeteriaElementBean.saveOrEdit()}" value="Save" />
                <p:commandButton action="#{cafeteriaElementBean.edit()}" value="Edit" />
                <p:button outcome="cafeteriaElementList" value="Back" />
            </h:form>
        </f:view>
        <br/>
        #{cafeteriaElementBean.cafeteriaElement.description} periodicity list:
        <br/>

        <f:view>
            <h:form>
                <h1><h:outputText value="List"/></h1>
                <h:dataTable value="#{elementPeriodBean.filteredPerElement(cafeteriaElementBean.cafeteriaElement)}" var="item">
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="MaxAbsoluteForPeriod"/>
                        </f:facet>
                        <h:outputText value="#{item.maxAbsoluteForPeriod}"/>
                    </h:column>                   
                    <!-- code omissed for brevity-->
                </h:dataTable>

                <p:commandButton action="#{elementPeriodBean.create(cafeteriaElementBean.cafeteriaElement)}"  value="Add a new Periodicity"/> 

            </h:form>
        </f:view>



    </h:body>
</html> 

This is a print screen of it enter image description here

Clickin on "new periodicity" button drive to nothing: debugger doesn´t sense it, server terminal doesn´t write anything. Neither the browser redirect to the second page. :(

The Session Bean is the following: (with some cuts)

package com.cafeteria.business;

import com.cafeteria.facades.ElementPeriodFacade;
import com.cafeteria.model.CafeteriaElement;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
import com.cafeteria.model.ElementPeriod;
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;

@Named
@SessionScoped
public class ElementPeriodBean implements Serializable, CRUD <ElementPeriod>{

    private ElementPeriod elementPeriod;

    @Inject
    ElementPeriodFacade elementPeriodFacade;

    public List <ElementPeriod> getAll(){
        return elementPeriodFacade.findAll();
    }

    public List <ElementPeriod> filteredPerElement(CafeteriaElement cafeteriaElement){
        return elementPeriodFacade.findForElement(cafeteriaElement);
    }

    public String create(){
       this.elementPeriod = new ElementPeriod();
        return "newElementPeriod";
    }

    public String create(CafeteriaElement cafeteriaElement){
        this.elementPeriod = new ElementPeriod();
        this.elementPeriod.setCafeteriaElement(cafeteriaElement);
        return "newElementPeriod";
    }

    public String modify(ElementPeriod elementPeriod){
        this.elementPeriod = elementPeriod;
        return "newElementPeriod";
    }

    public String saveOrEdit(){
        elementPeriodFacade.create(elementPeriod);
        return "editCafeteriaElement";
    }

      public String edit(){
        elementPeriodFacade.edit(elementPeriod);
        return "editCafeteriaElement";
    }

    public String remove(ElementPeriod elementPeriod){
        elementPeriodFacade.remove(elementPeriod);
        return "editCafeteriaElement";
    }

    public ElementPeriod find(Long id){
        return elementPeriodFacade.find(id);
    }

    public ElementPeriod getElementPeriod() {
        if(this.elementPeriod== null) this.elementPeriod = new ElementPeriod();
        return this.elementPeriod;
    }  

    public void setElementPeriod(ElementPeriod elementPeriod) {
        this.elementPeriod = elementPeriod;
    }
}

And this is the Form page to insert data:

<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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">
    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Create periodicity for Cafeteria Element</title>        
    </h:head>
    <h:body>

        <f:view>
            <h:form>
                <h1><h:outputText value="Create/Edit Periodicity for #{cafeteriaElementBean.cafeteriaElement.description}"/></h1>

                <h:panelGrid columns="2">                 
                    <h:outputLabel value="Periodicity:" for="periodicity" />
                    <h:selectOneMenu id="periodicity" value="#{elementPeriodBean.elementPeriod.periodicity}" title="Periodicity" >
                        <!-- TODO: update below reference to list of available items-->
                        <f:selectItems value="#{periodicityBeam.all}"/>
                    </h:selectOneMenu>

                    <h:outputLabel value="MaxAbsoluteForPeriod:" for="maxAbsoluteForPeriod" />
                    <h:inputText id="maxAbsoluteForPeriod" value="#{elementPeriodBean.elementPeriod.maxAbsoluteForPeriod}" title="MaxAbsoluteForPeriod" />

                    <h:outputLabel value="MaxPercentageForPeriod:" for="maxPercentageForPeriod" />
                    <h:inputText id="maxPercentageForPeriod" value="#{elementPeriodBean.elementPeriod.maxPercentageForPeriod}" title="MaxPercentageForPeriod" />

                    <h:outputLabel value="FixValue:" for="fixValue" />
                    <h:inputText id="fixValue" value="#{elementPeriodBean.elementPeriod.fixValue}" title="FixValue" />   
                </h:panelGrid>

                <p:commandButton value="Save" action="#{elementPeriodBean.saveOrEdit()}"/>

                <!--p:button outcome="editCafeteriaElement" value="Back" /-->
            </h:form>
        </f:view>
    </h:body>
</html>

NOTES: - newElementPeriod is correctly pointing from first page page up here from faces-config.xml - newElemelPeriod.xhtml is available whether directly called from browser - other buttons works: not everywhere, as some have similar behaviour as this one

PLease help! I am getting crazy!

Thank you in advance, Andrea

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
Andrea T
  • 3,035
  • 4
  • 23
  • 39
  • what the problem you are receiving, whether the method create() has been called. – kark Nov 07 '13 at 04:11
  • There are lots of misconceptions here. I recommend to stop here and try to grasp the basics of JSF and CDI. Also, if you're working with JSF 2.0 or JSF 2.1 and CDI, I recommend adding OmniFaces to have the power of `@ViewScoped` annotation for CDI, but if you're working with JSF 2.2, then you can use `@ViewScoped` for your CDI beans as well. – Luiggi Mendoza Nov 07 '13 at 04:28
  • By the way, to detect the problems in your JSF code, add a `` inside each form so the error messages like conversion will be shown there and you (and future readers) could detect the reasons why this didn't work. – Luiggi Mendoza Nov 07 '13 at 04:32
  • 1
    I've made a test by copying/pasting/adapting OP's code and using both ``s (as in OP's current code) just to test the navigation issue and works. In my adaptation process, I just generated necessary interface and classes like `ElementPeriodFacade`, `CafeteriaElement`, `ElementPeriod` and others with necessary fields. Looks like the problem is somewhere else in *code omitted for brevity* comments. You can seek for more reasons here: http://stackoverflow.com/q/2118656/1065197 – Luiggi Mendoza Nov 07 '13 at 05:11
  • 1
    Have you also looked in browser's HTTP traffic monitor and JS console for clues? – BalusC Nov 07 '13 at 10:41

2 Answers2

0

You can have check at the link may be the process attribute of commandButton CommandButton not firing

Community
  • 1
  • 1
BholaVishwakarma
  • 581
  • 6
  • 18
-1

Why do you try to give the create method a parameter out of a session scoped bean? Try to remove the parameter and inject the other session scoped bean...

anm
  • 545
  • 3
  • 17
  • This fits more as comment rather than an answer. Also, this won't solve the problem. Since you can't post comments yet, please wait until have at least 50 rep and then post comments asking more info or giving some advises that you think they shouldn't go as answer. – Luiggi Mendoza Nov 07 '13 at 04:21
  • Well those things solved many problems at Buttons and links in my web applications, because the parameters did not work very well! Have you tried to remove it? Why you are shure it won't solve the Problem...? I do not find it vers productive to downvote all answers of people which are trying to help the author of the thread. – anm Nov 07 '13 at 05:40
  • Because I made a test and works with current OP's code, so the problem lies somewhere else. I know it can have a better design (starting by wrong usage of `@SessionScoped` beans) but your option doesn't solve the problem at all. – Luiggi Mendoza Nov 07 '13 at 06:07
  • So please comment this like that if you made a test. My answer was a try to help her out and not a comment to get more info. Just another thing which could be an error: The injcted *elementPeriodFacade* should be injected with @EJB if this is a EJB SessionBean. – anm Nov 07 '13 at 06:20