1

I am trying to do a simple test before I dive into a large activity. But, here is where I was stuck. The test is to submit the JSF form, but the managed bean action never gets triggered.

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ice="http://www.icesoft.com/icefaces/component">
<f:view>    
<head>
<title>A B C</title>
</head>
<body>
      <h:form id="test">
        <h:inputText value="demo"/>
        <h:commandButton type="submit" value="A button" action="#{User.better}" immediate="true" />
      </h:form>
</body>
</f:view>
</html>

Here is my managed bean

 public class User {

        public String send() {
            System.out.println("Submitting data.....");

            return null;

        }
        public void better() {
            System.out.println("In better...");

        }

    }

I have set all the configurations correctly. I could be able to see the page. But,the control never gets into action method. How come? Any suggestions would be great.

UPDATE: Here is my faces-conig.xml

<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
    <application>
        <view-handler>com.icesoft.faces.facelets.D2DFaceletViewHandler</view-handler>
    </application>
 <managed-bean>
  <managed-bean-name>User</managed-bean-name>
  <managed-bean-class>com.srk.beans.User</managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope>
 </managed-bean>
</faces-config>

I have changed the managed-bean-name from User to user(small case) and changed the same in the .xhtml page as well, but seems to be same problem still.

srk
  • 4,857
  • 12
  • 65
  • 109
  • 1
    Check if the bean is properly generated printing something out in your facelet (`h:outputText value="#{user.hello}"`). – Aritz Jul 28 '14 at 08:28
  • @XtremeBiker: Ya, it works, i.e.., accessing some property like user.hello works, but still command button action is not fired. – srk Jul 28 '14 at 17:11
  • Debug your server-side and see if the `FacesServlet` is being hit when you click on the button. If not, debug the client side and see if the browser is sending the request. Check also any possible filter you could have in your application which might be affecting the behaviour. – Aritz Jul 29 '14 at 05:58

2 Answers2

3

Try user instead of User.Thus, try put user.better instead of User.better. Are you using jsf 2 or no? Also, post your faces-config file

Periklis Douvitsas
  • 2,431
  • 1
  • 13
  • 14
  • Periklis: I am using JSF1.2, I have updated faces-config.xml file as an UPDATE. I tried changing the User to user and checked, but not luck. – srk Jul 28 '14 at 00:57
  • 1
    The function better is of type void. In your action you should specify a function that returns String. Maybe, you wanted to write action="#{User.send}" – Periklis Douvitsas Jul 28 '14 at 06:25
  • I tried this way as well,i.e.., calling #{User.send} but it isn't working. – srk Jul 28 '14 at 17:17
1

Support for an action method with a void return type did not show up in JSF until v2.x. You must specify a return type of at least Object for better

public Object better() {
    System.out.println("In better...");

    return null;
}
kolossus
  • 20,559
  • 3
  • 52
  • 104
  • True, the problem is that control is not getting into any of the action method. – srk Jul 29 '14 at 02:26