2

I am using JSF 1.2 for my application.

In the below code, the action attribute of the Account Detailsbutton is not working, i.e. the method is not getting invoked and nothing happens when I click the button.

<h:panelGrid columns="2">
    <h:outputLabel id="lblCustomerDetails" value="Details of CustomerId: "></h:outputLabel>
    <h:outputText id="txtCustomerId" value="#{customerInfo.customerId }"></h:outputText>
    <h:outputLabel id="lblCustomerName" value="Customer name: "></h:outputLabel>
    <h:outputText id="txtCustomerName" value="#{customerInfo.customerNAme }"></h:outputText>
    <h:outputLabel id="lblAccounts" value="Accounts: "></h:outputLabel>
    <h:selectOneMenu id="drpdownAccounts">
        <f:selectItems value="#{customerInfo.accounts }"/>
    </h:selectOneMenu>      
    <h:outputLabel id="lblEmail" value="Email: "></h:outputLabel>
    <h:outputText id="txtEmail" value="#{customerInfo.email }"></h:outputText>
    <h:outputLabel id="lblAccountDetails" value="Select an account no. for details"></h:outputLabel>
    <h:commandButton id="btnAcountDetails" value="Account Details" action="#{accountBean.accountDetails }"></h:commandButton>
    <h:messages></h:messages>
</h:panelGrid>  

Below is the AccountBean:

public class AccountBean {

private int accountNo;
private String customerName;
private double accountBalance;
private String accountType;

    //Getters and setters

public String accountDetails(){
   //Some logic and return
       return "success"; 

}
}

This is the managed bean present in the faces-config fie:

<managed-bean>     
    <managed-bean-name>customerInfo</managed-bean-name>
    <managed-bean-class>com.bean.CustomerInfo</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>        
</managed-bean>

<managed-bean>     
    <managed-bean-name>accountBean</managed-bean-name>
    <managed-bean-class>com.bean.AccountBean</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>        
</managed-bean> 

There might be somethng silly I am missing in the code but not able to figure it out, wasted a lot of time with this and hence thought of posting. Pointers are appretiated.

user182944
  • 7,897
  • 33
  • 108
  • 174
  • 5
    Please exclude the causes listed here http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked/2120183#2120183 First suspect: where's the ``? How would you submit a form without a form? This is however shown in chapter 1 of every sane JSF tutorial, so it would be a bit *too* obvious mistake indicating a lack of understanding of basic HTML (which you'd preferably learn first before diving into JSF as JSF is ultimately basically "just" a HTML code generator). – BalusC Apr 11 '13 at 03:30

2 Answers2

3

I don't see the whole markup you have, but could it just be a missing <form> tag somewhere in your page? AFAIK in MyFaces Trinidad, form controls and buttons don't do anything unless they are inside a <tr:form> tag.

Hope that solves your problem.

darthbinamira
  • 524
  • 4
  • 9
  • I didn't see BalusC's comment before answering this... the answer from his link looks like it has everything including the kitchen sink, so yeah go there!! :) – darthbinamira Apr 11 '13 at 03:37
0

If pasting your code inside

<h:form>

and still you are not able to solve your problem then try to use

<a4j:JsFunction>

It will solve your problem for JSF 1.2

<h:form>
<h:commandbutton onclick = "clickme()" />
<a4j:JsFunction name = "clickme" action = "#{yourBean.YourMethod}"  /> 
</h:form>