Button不会在Primefaces中调用托管bean方法

时间:2015-03-04 10:54:18

标签: jsf primefaces

嗨试图按下按钮点击方法,但它不起作用我也试过onclick而不是动作它也不起作用。我无法理解哪里有错误请帮帮我

这是我的托管bean

package com.primefaces.managedbean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;

import com.primefaces.domain.KenLocation;
import com.primefaces.service.ILocationService;

@ManagedBean(name = "locationbean")
@ViewScoped
public class LocationBean implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = 1101264226039168006L;

/**
 * 
 */

@ManagedProperty(value = "#{LocationService}")
private ILocationService locationService;

private List<KenLocation> locationList = new ArrayList<KenLocation>();

KenLocation kenLocation;

private String locationName;

private String address1;

private String address2;

private String city;

private String pincode;

private String state;

private String contactNo;

private String organisationName;

@PostConstruct
private void init() {
    locationList = locationService.onLoad();
}

public void addnewlocation() {
    System.out.println("I am inside newlocation");

    kenLocation = new KenLocation();
    kenLocation.setLocationName(locationName);
    kenLocation.setAddress1(address1);
    kenLocation.setAddress2(address2);
    kenLocation.setCity(city);
    kenLocation.setPincode(Integer.parseInt(pincode));
    kenLocation.setPhone(contactNo);
    System.out.println(kenLocation);
}

public String getLocationName() {
    return locationName;
}

public void setLocationName(String locationName) {
    this.locationName = locationName;
}

public String getAddress1() {
    return address1;
}

public void setAddress1(String address1) {
    this.address1 = address1;
}

public String getAddress2() {
    return address2;
}

public void setAddress2(String address2) {
    this.address2 = address2;
}

public String getCity() {
    return city;
}

public void setCity(String city) {
    this.city = city;
}

public String getPincode() {
    return pincode;
}

public void setPincode(String pincode) {
    this.pincode = pincode;
}

public String getState() {
    return state;
}

public void setState(String state) {
    this.state = state;
}

public String getContactNo() {
    return contactNo;
}

public void setContactNo(String contactNo) {
    this.contactNo = contactNo;
}

public String getOrganisationName() {
    return organisationName;
}

public void setOrganisationName(String organisationName) {
    this.organisationName = organisationName;
}

public ILocationService getLocationService() {
    return locationService;
}

public void setLocationService(ILocationService locationservice) {
    this.locationService = locationservice;
}

public List<KenLocation> getLocationList() {
    return locationList;
}

public void setLocationList(List<KenLocation> a_locationList) {
    locationList = a_locationList;
}

}

和JSF

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<ui:composition 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:ui="http://java.sun.com/jsf/facelets">

<h5>Product List {9 Products can be added per mail}</h5>
<p:separator></p:separator>

<p:growl id="growlLocationtable"></p:growl>

<p:commandButton id="new_location" title="CreateLocation" type="button"
    icon="ui-icon-document" onclick="PF('dlg1').show()" />
<p:commandButton id="edit_location" title="EditLocation"
    icon=" ui-icon-pencil" />
<p:commandButton id="delete_location" title="DeleteLocation"
    icon="ui-icon-trash" />


<h:form id="Locationdataform">
    <h:panelGrid columns="2" id="Locationdatatablepanel" resizable="false"
        size="600">

        <p:dataTable id="Locationdatatable" var="odt"
            value="#{locationbean.locationList}">


            <p:column headerText="Location Name">
                <h:outputText value="#{odt.locationName}" />
            </p:column>

            <p:column headerText="Address Line1">
                <h:outputText value="#{odt.address1}" />
            </p:column>
            <p:column headerText="Address Line2">
                <h:outputText value="#{odt.address2}" />
            </p:column>
            <p:column headerText="City">
                <h:outputText value="#{odt.city}" />
            </p:column>
            <p:column headerText="Pincode">
                <h:outputText value="#{odt.pincode}" />
            </p:column>
            <p:column headerText="State">
                <h:outputText value="#{odt.state}" />
            </p:column>
            <p:column headerText="Contact No">
                <h:outputText value="#{odt.phone}" />
            </p:column>
            <p:column headerText="Organisation Name">
                <h:outputText value="#{odt.ken_Org_ID.name}" />
            </p:column>


        </p:dataTable>
    </h:panelGrid>


</h:form>


<!-- dialog -->
<p:dialog header="Add Location" widgetVar="dlg1" minHeight="40"
    modal="true">
    <h:form id="addLocationForm">
        <h:panelGrid columns="2" id="grid">

            <h:outputLabel value="Location Name"></h:outputLabel>
            <p:inputText id="txt_Name" value="#{locationbean.locationName}" />
            <h:outputLabel value="Address1"></h:outputLabel>
            <p:inputText id="txt_address1" value="#{locationbean.address1}" />
            <h:outputLabel value="Address2"></h:outputLabel>
            <p:inputText id="txt_address2" value="#{locationbean.address2}" />
            <h:outputLabel value="City"></h:outputLabel>
            <p:inputText id="txt_city" value="#{locationbean.city}" />
            <h:outputLabel value="Pincode"></h:outputLabel>
            <p:inputText id="txt_pincode" value="#{locationbean.pincode}" />
            <h:outputLabel value="State"></h:outputLabel>
            <p:inputText id="txt_state" value="#{locationbean.state}" />
            <h:outputLabel value="Contactno"></h:outputLabel>
            <p:inputText id="txt_contactno" value="#{locationbean.contactNo}" />
            <h:outputLabel value="Organistaion name"></h:outputLabel>
            <p:inputText id="txt_orgname"
                value="#{locationbean.organisationName}" />


            <p:commandButton id="addlocatin_btn" value="Save"
                action="#{locationbean.addnewlocation}" type="submit" />

        </h:panelGrid>
    </h:form>

</p:dialog>

0 个答案:

没有答案