user182944
user182944

Reputation: 8067

<h:CommandButton> action attribute not working in JSF 1.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.

Upvotes: 2

Views: 3437

Answers (2)

Piyush Sanghani
Piyush Sanghani

Reputation: 21

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>

Upvotes: 0

darthbinamira
darthbinamira

Reputation: 544

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.

Upvotes: 3

Related Questions