0

尝试从页面使用我的控制器方法时遇到问题。

我已经尝试过 action 和 actionListener,我已经将这两个与 ajax="true" 和 immediate="true" 混合在一起,所以没有更多的可能性。

起初我认为它没有采用 bean,但它确实呈现了测试属性。

我怎么能调用这些方法?

我知道我可以使用 p:url 但我更喜欢使用 commandButton 。

我的控制器:

@Controller
@RequestMapping("/orderService")
@ManagedBean(name="orderServiceController")
@SessionScoped
public class OrderServiceController implements Serializable{

    private static final long serialVersionUID = -8694892885365853014L;

    @Autowired
    private OrderService orderService;
    @Autowired
    private OrderContainer container;

    public String test = "test";

    public String getTest() {
        return test;
    }
    @RequestMapping("/waiterInformed/{tableNumber}")
    public String waiterInformed(@PathVariable Integer tableNumber ){
        log.info("##>> OrderServiceController waiterInformed INI on table " + 
            tableNumber + "<<");
        orderService.waiterInforme(tableNumber);
        return "redirect:/orderService/";
    }
    (...)
}

面孔-config.xml

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

<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    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_2_1.xsd"
    version="2.1">
    <application> 
        <el-resolver>
            org.springframework.web.jsf.el.SpringBeanFacesELResolver
        </el-resolver> 

        <locale-config>
            <default-locale>en</default-locale>
            <supported-locale>es</supported-locale> 
        </locale-config>

        <resource-bundle>
            <base-name>messages.messages</base-name>
            <var>msg</var>
        </resource-bundle>
    </application>

</faces-config>

最后在我的 app-config 中映射了“order.xhtml”

<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:p="http://primefaces.org/ui"
     xmlns:c="http://java.sun.com/jsp/jstl/core"
     >
<h:head>

    <script type="text/JavaScript">

        function timedRefresh(timeoutPeriod) {
            setTimeout("location.reload(true);",timeoutPeriod);
        }
    </script>


</h:head>
    <h:body onload="JavaScript:timedRefresh(15000);"> <!-- Reload every 15 secs -->

        <h2>#{msg['order.label.title']}</h2>

        <h3>List</h3>
        <!-NOT WORKING (log is not showing any message --> 
        <p:commandButton value="test" action="#{orderServiceController.waiterCalled}">
            <f:param name="tableNumber" value="1"/>
        </p:commandButton>
        <p:commandButton value="test" action="#{orderServiceController.waiterCalled}">
            <f:attribute name="tableNumber" value="1"/>
        </p:commandButton>

        <!-WORKING--> 
        <h:outputText value="#{orderServiceController.test}"/>
  (...)
</h:body> 
</html> 
4

0 回答 0