2017-05-30 56 views
0

我使用NetBeans GlassFish的commandLink动作不叫

在我.xhtml文件,有我期望调用链接动作shopBean.instructorScheduleById()

<p:commandLink styleClass="tooltip tour-sched" 
    rendered="#{shopBean.instructorSchedule!=null}" 
    update=":dialogFormTS" action="# 
    {shopBean.instructorScheduleById()}"            
    oncomplete="dlgTS.show()" process="@this"            
    ajax="true">TS<h:outputText styleClass="tooltiptext" 
    value="#{shopBean.instructorSchedule.name}"/> 
</p:commandLink> 

Bean文件

@ManagedBean(name = "shopBean") 
@SessionScoped 
public class ShopBean { 

    public ShopBean() {} 

    public void getInstructorScheduleById(){ 
     System.out.println("hello"); 

    } 


} 

我看着我的开发人员工具在网络下我看到有一个Ajax请求,但当我在玻璃鱼输出上看,没有字hello

+0

你把你的命令组件放在一个表单里面吗? –

+0

'

回答

2

基于我在这里学到的stackoverflow,get前缀用于getter方法,这意味着它必须有一个返回值。

public void sum(){ 
    int num1 = 1; 
    int num2 = 2; 
    System.out.println(num1 + num2); 
} 
// xhtml 
<p:commandButton action="#{bean.sum()}" /> 
如果你想从一个getter方法获得的价值

pivate int sum; 
public int getSum(){ 
    return this.sum; 
} 
public void setSum(sum){ 
    this.sum = sum; 
} 
// xhtml 
<p:outputText value="#{bean.sum}" /> 

有关问题的快速解决方案是删除get前缀在 豆。

+1

你确定你回答正确的问题吗? – Kukeltje