You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Joel Wilson <jo...@devotionmedia.com> on 2005/08/24 18:38:02 UTC

Method binding calls not being made

I am trying to create an admin section for an online database, right  
now I'm simply trying to create basic add/edit/remove functionality.  
Almost everything seems to work, except that my bound methods only  
call sometimes. There is not logical reason I am seeing for this,  
there is nothing in my logs about it. When I have my SelectOneListBox  
bound to a property it pretty much ignores it, once in a while it  
will try to call the getter, but it has never called the setter.

I have tried every combination of things to try and get it working  
but most seem to have no effect. Does anyone else know if maybe it's  
the Apple JDK or the Spring Framework's DelegatingVariableResolver,  
the Tomahawk extensions, maybe even the fact that I have multiple  
commandXX's in the form?

Page backing Bean

/*
* Created on Aug 23, 2005
*
*/
package com.devotion.jra.website.pagebeans;

import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.devotion.jra.website.dao.SpringBeanGetter;
import com.devotion.jra.website.databeans.Location;

public class Locations {

     private static final Log log = LogFactory.getLog(Locations.class);
     private HibernateTemplate dao;
     public static final String SELF = "viewLocations";

     private Location currentItem = new Location();
     private Integer currentlySelected = null;

     // page methods
         // constructor
     public Locations() {
         dao = SpringBeanGetter.getDao(FacesContext.getCurrentInstance 
());
     }

         // we are asked to create a new location
     public String newItem() {
         System.out.println("Creating new current item");
         currentItem = new Location();
         return SELF;
     }

         // we are asked to pull the current one from the list
     public String editItem() {
         System.out.println("Getting currently selected item");
         if (currentlySelected != null)
             setCurrentItem((Location) dao.get(Location.class,  
currentlySelected));
         return SELF;
     }

         // we are asked to delete the currently selected one
     public String removeItem() {
         System.out.println("Removing currently selected item");
         if (currentlySelected != null)
             dao.delete(dao.get(Location.class, currentlySelected));
         currentlySelected = null;
         return SELF;
     }

         // we are asked to save the current item
     public String saveItem() {
         System.out.println("Saving current item");
         dao.saveOrUpdate(currentItem);
         return SELF;
     }

     public void listen(ActionEvent e) {
         System.out.println("Action Event Fired");
         System.out.println("Source: " + e.getSource());
         System.out.println(e.toString());
     }
     public void listen(ValueChangeEvent e) {
         System.out.println("Value Change Event Fired");
         System.out.println("Source: " + e.getSource());
         System.out.println(e.toString());
     }

     // ------------------ end page methods

     // getters and setters
     public Location getCurrentItem() {
         System.out.println("Returning current item");
         return currentItem;
     }

     public void setCurrentItem(Location currentItem) {
         System.out.println("Setting current item");
         this.currentItem = currentItem;
     }

     public Integer getCurrentlySelected() {
         System.out.println("Returning selection index");
         return currentlySelected;
     }

     public void setCurrentlySelected(Integer currentlySelected) {
         System.out.println("Setting selection index");
         this.currentlySelected = currentlySelected;
     }
}



JSP File

<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://myfaces.apache.org/extensions" prefix="x"%>
<h:outputText value="Locations" styleClass="adminPageHeading"/>
<x:aliasBean alias="#{simpleElementBean}" value="#{LocationsBean}">
<x:aliasBean alias="#{dao}" value="#{LocationsDao}">
<x:aliasBean alias="#{type}" value="location">
<h:panelGrid columns="1">
<h:form>
     <h:panelGrid columns="2" styleClass="controlPanelPaneSubPanel">
         <h:selectOneListbox size="5"  value="# 
{simpleElementBean.currentlySelected}"">
             <f:convertNumber type="int"/>
             <f:selectItems value="#{dao.selectItems}"/>
         </h:selectOneListbox>
         <h:panelGroup>
             <h:commandLink value="Create new #{type}" action="# 
{simpleElementBean.newItem}" actionListener="# 
{simpleElementBean.listen}"/><f:verbatim><br /></f:verbatim>
             <h:commandLink value="Edit selected #{type}" action="# 
{simpleElementBean.editItem}" actionListener="# 
{simpleElementBean.listen}"/><f:verbatim><br /></f:verbatim>
             <h:commandLink value="Remove selected #{type}" action="# 
{LocationBean.removeItem}" actionListener="#{LocationBean.listen}"/>
         </h:panelGroup>
     </h:panelGrid>
</h:form>
<h:form>
     <h:panelGrid columns="2" styleClass="controlPanelPaneSubPanel">
         <h:outputLabel for="itemName" value="Name"/>
         <h:inputText id="itemName" value="# 
{simpleElementBean.currentItem.name}" valueChangeListener="# 
{simpleElementBean.listen}" size="30" required="true" >
             <f:validateLength minimum="3" maximum="30"/>
         </h:inputText>
         <h:commandLink value="Save" action="# 
{simpleElementBean.saveItem}" actionListener="# 
{simpleElementBean.listen}"/>
         <h:message for="itemName" />
     </h:panelGrid>
</h:form>
</h:panelGrid>
</x:aliasBean>
</x:aliasBean>
</x:aliasBean>



Re: Method binding calls not being made

Posted by Mike Kienenberger <mk...@gmail.com>.
Possibly validation is failing and the lifecycle never reaches the
point where it would execute your action.

You might try sticking in 

<h:messages globalOnly="true"/>
<h:messages globalOnly="false"/>

and see if anything shows up.

Otherwise set a breakpoint in LifecycleImpl.execute() and see what
phases are being executed.


On 8/24/05, Joel Wilson <jo...@devotionmedia.com> wrote:
> I am trying to create an admin section for an online database, right now I'm
> simply trying to create basic add/edit/remove functionality. Almost
> everything seems to work, except that my bound methods only call sometimes.
> There is not logical reason I am seeing for this, there is nothing in my
> logs about it. When I have my SelectOneListBox bound to a property it pretty
> much ignores it, once in a while it will try to call the getter, but it has
> never called the setter.
> 
> I have tried every combination of things to try and get it working but most
> seem to have no effect. Does anyone else know if maybe it's the Apple JDK or
> the Spring Framework's DelegatingVariableResolver, the Tomahawk extensions,
> maybe even the fact that I have multiple commandXX's in the form?
> 
> Page backing Bean
> 
> /*
>  * Created on Aug 23, 2005
>  *
>  */
> package com.devotion.jra.website.pagebeans;
> 
> import javax.faces.context.FacesContext;
> import javax.faces.event.ActionEvent;
> import javax.faces.event.ValueChangeEvent;
> 
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> import
> org.springframework.orm.hibernate3.HibernateTemplate;
> 
> import com.devotion.jra.website.dao.SpringBeanGetter;
> import com.devotion.jra.website.databeans.Location;
> 
> public class Locations {
> 
>     private static final Log log = LogFactory.getLog(Locations.class);
>     private HibernateTemplate dao;
>     public static final String SELF = "viewLocations";
>     
>     private Location currentItem = new Location();
>     private Integer currentlySelected = null;
> 
>     // page methods
>         // constructor
>     public Locations() {
>         dao = SpringBeanGetter.getDao(FacesContext.getCurrentInstance());
>     }
>       
>         // we are asked to create a new location
>     public String newItem() {
>         System.out.println("Creating new current item");
>         currentItem = new Location();
>         return SELF;
>     }
>     
>         // we are asked to pull the current one from the list
>     public String editItem() {
>         System.out.println("Getting currently selected item");
>         if (currentlySelected != null)
>             setCurrentItem((Location) dao.get(Location.class,
> currentlySelected));
>         return SELF;
>     }
>     
>         // we are asked to delete the currently selected one
>     public String removeItem() {
>         System.out.println("Removing currently selected item");
>         if (currentlySelected != null)
>             dao.delete(dao.get(Location.class, currentlySelected));
>         currentlySelected = null;
>         return SELF;
>     }
> 
>         // we are asked to save the current item
>     public String saveItem() {
>         System.out.println("Saving current item");
>         dao.saveOrUpdate(currentItem);
>         return SELF;
>     }
>     
>     public void listen(ActionEvent e) {
>         System.out.println("Action Event Fired");
>         System.out.println("Source: " + e.getSource());
>         System.out.println(e.toString());
>     }
>     public void listen(ValueChangeEvent e) {
>         System.out.println("Value Change Event Fired");
>         System.out.println("Source: " + e.getSource());
>         System.out.println(e.toString());
>     }
>     
>     // ------------------ end page methods 
> 
>     // getters and setters
>     public Location getCurrentItem() {
>         System.out.println("Returning current item");
>         return currentItem;
>     }
> 
>     public void setCurrentItem(Location currentItem) {
>         System.out.println("Setting current item");
>         this.currentItem = currentItem;
>     }
> 
>     public Integer getCurrentlySelected() {
>         System.out.println("Returning selection index");
>         return currentlySelected;
>     }
> 
>     public void setCurrentlySelected(Integer currentlySelected) {
>         System.out.println("Setting selection index");
>         this.currentlySelected = currentlySelected;
>     }
> }
> 
> 
> 
> JSP File
> 
> <%@ page language="java" pageEncoding="UTF-8"%>
> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
> <%@ taglib uri="http://myfaces.apache.org/extensions"
> prefix="x"%>
> <h:outputText value="Locations" styleClass="adminPageHeading"/>
> <x:aliasBean alias="#{simpleElementBean}" value="#{LocationsBean}">
> <x:aliasBean alias="#{dao}" value="#{LocationsDao}">
> <x:aliasBean alias="#{type}" value="location">
> <h:panelGrid columns="1">
> <h:form>
>     <h:panelGrid columns="2" styleClass="controlPanelPaneSubPanel">
>         <h:selectOneListbox size="5" 
> value="#{simpleElementBean.currentlySelected}"">
>             <f:convertNumber type="int"/>
>             <f:selectItems value="#{dao.selectItems}"/>
>         </h:selectOneListbox>
>         <h:panelGroup>
>             <h:commandLink value="Create new #{type}"
> action="#{simpleElementBean.newItem}"
> actionListener="#{simpleElementBean.listen}"/><f:verbatim><br
> /></f:verbatim>
>             <h:commandLink value="Edit selected #{type}"
> action="#{simpleElementBean.editItem}"
> actionListener="#{simpleElementBean.listen}"/><f:verbatim><br
> /></f:verbatim>
>             <h:commandLink value="Remove selected #{type}"
> action="#{LocationBean.removeItem}"
> actionListener="#{LocationBean.listen}"/>
>         </h:panelGroup>
>     </h:panelGrid>
> </h:form>
> <h:form>
>     <h:panelGrid columns="2" styleClass="controlPanelPaneSubPanel">
>         <h:outputLabel for="itemName" value="Name"/>
>         <h:inputText id="itemName"
> value="#{simpleElementBean.currentItem.name}"
> valueChangeListener="#{simpleElementBean.listen}" size="30" required="true"
> >
>             <f:validateLength minimum="3" maximum="30"/>
>         </h:inputText>
>         <h:commandLink value="Save" action="#{simpleElementBean.saveItem}"
> actionListener="#{simpleElementBean.listen}"/>
>         <h:message for="itemName" />
>     </h:panelGrid>
> </h:form>
> </h:panelGrid>
> </x:aliasBean>
> </x:aliasBean>
> </x:aliasBean>
> 
> 
>