0

I am building a web app based on ICEmobile with JSF 2.1 and Maven. I'm running into this problem when my jsf page doesn't look for its bean but I still can build and deploy the project with no errors, I deploy the project via run configuration in Eclipse: clean tomcat7:run-war. Even if I declare the bean via annotation or applicationContext.xml, the page still doesn't call the bean correctly. I can get the value of the field in the bean but cannot call the method within that bean System.out.println("Pressed"); gives no output to the console. I'm guessing it must be something to do with my configuration but I don't know where to look into. Please give me some hints. Thanks

<!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:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:util="http://java.sun.com/jsf/composite/components"
    xmlns:mobi="http://www.icesoft.com/icefaces/mobile/component"
    xmlns:ice="http://www.icesoft.com/icefaces/component"
    xmlns:icecore="http://www.icefaces.org/icefaces/core">
<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
    <meta name="viewport"
        content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />

    <title>ICEfaces Mobile Showcase</title>
    <mobi:deviceStylesheet media="screen" />
</h:head>
<h:body>
    <mobi:pagePanel>
        <f:facet name="body">
            <h:form>
                    <mobi:commandButton value="#{buttonBean.buttonName}" buttonType="important" actionListener="#{buttonBean.buttonPress}">
                <f:attribute name="buttonState" value="change"/>
            </mobi:commandButton>   
            </h:form>
        </f:facet>
    </mobi:pagePanel>
</h:body>
</html>

The Bean:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;

@ManagedBean(name = ButtonBean.BEAN_NAME)
@SessionScoped
public class ButtonBean implements Serializable {

    private static final long serialVersionUID = 1L;

    public static final String BEAN_NAME = "buttonBean";

    private String buttonName = "0";

    public String getButtonName() {
        return buttonName;
    }

    public void setButtonName(String buttonName) {
        this.buttonName = buttonName;
    }

    public void buttonPress(ActionEvent event){
        System.out.println("Pressed");
        String buttonState = (String)event.getComponent().getAttributes().get("buttonState");
        if (buttonState.equals("change") && buttonName.equals("0")) buttonName = "1";
        else if (buttonState.equals("change") && buttonName.equals("1")) buttonName = "0";
    }  
}
Duc
  • 511
  • 1
  • 4
  • 18
  • Could you please also add the bean declaration including annotations. Remove content in methods if it's bulky – Aksel Willgert Nov 21 '12 at 17:27
  • I have updated the xhtml and the bean. Apparently, I found out that the jsf page does pick up the bean, it loads the buttonName and displays the "0" but it just doesn't call the method. – Duc Nov 21 '12 at 17:48
  • Just curious, do you have any reason to annotate this bean with `@SessionScoped` instead of `@RequestScoped`? Hope this is because of a piece of information you've left out, otherwise I would advice you to read this post by BalusC: http://stackoverflow.com/questions/7031885/how-to-choose-the-right-bean-scope/7031941#7031941 – Menno Nov 21 '12 at 21:34
  • I just followed the example from ICE: [link](http://mobileshowcase.icesoft.org/mobileshowcase/showcase.jsf). I will try your suggestion. Thanks. – Duc Nov 22 '12 at 08:59
  • @Aquillo as the post by BalusC stated, I don't think it is what causing the problems here since this is a basic example. I gave it a go but it doesn't change anything. – Duc Nov 22 '12 at 09:23

1 Answers1

0

I found out that my web.xml was set as version 2.5. Change to version 3.0. All works now

Duc
  • 511
  • 1
  • 4
  • 18