0

i have a rare situation in my page i have a "p:autoComplete" which is bind to a backing bean i can read that auto complete item form the backing bean. but the problem is the selected value from that auto complete need to be passed as a parameter, when user pressed the button, with some other parameters. which i really don't know how to do it?

this is my page which has the autocomplete

<p:panel header="Employee sales" style="width:500px"
                toggleable="true" toggleSpeed="500" closeSpeed="500">

                <p:autoComplete id="user_auto_complete"
                    value="#{salesReportMainController.userFromAutoComplete}"
                    completeMethod="#{salesReportMainController.completeUser}"
                    var="user" itemLabel="#{user.userName}" itemValue="#{user}"
                    converter="#{userConverter}" forceSelection="true" />

                <p:commandButton id="Search" value="Generate"
                    action="admin_common_barchart">
                    <f:param name="todaysDate"
                        value="#{salesReportMainController.todaysDate}" />
                    <f:param name="beforDate"
                        value="#{salesReportMainController.dateBeforOneYear}" />
                    <f:param name="employeeName"
                        value="#{salesReportMainController.userFromAutoComplete.userName}" />

                </p:commandButton>


            </p:panel>

and this is the backing bean that binds to that page

@ViewScoped
public class SalesReportMainController implements Serializable{
    private static final long serialVersionUID = 1L;

    @ManagedProperty(value = "#{userService}")
    public UserService userService;
    public DateTime todaysDate;
    public DateTime dateBeforOneYear;
    public DateTime dateBeforsixMonths;
    public List<User> allUsers;
    public List<User> acFilterdUsers;

    public User userFromAutoComplete;


    @PostConstruct
    public void init(){
        int oneYear = ConstantConfiguration.YearsInMonths.ONE_YEAR.getValue();
        int sixMonths = ConstantConfiguration.YearsInMonths.SIX_MONTH.getValue();
        todaysDate = new DateTime();
        dateBeforOneYear = new DateTime(todaysDate).minusMonths(oneYear);
        dateBeforsixMonths = new DateTime(todaysDate).minusMonths(sixMonths);
    }

//  public String buttonClick(){
//      System.out.println("aaaaaaaa");
//      return null;
//  }

    public List<User> completeUser(String query) {
        allUsers = userService.getAllUsers();
        acFilterdUsers = new ArrayList<User>();

        for (User user : allUsers) {
            if(user.getUserName().toLowerCase().startsWith(query)){
                acFilterdUsers.add(user);
            }
        }

        return acFilterdUsers;
    }

    public String getAutoCompleteUser() {
        if (userFromAutoComplete != null) {
            //i can get the value of the selected item form auto complete
        }
        return null;
    }

    //getters and setters
}

and this is the page that i want to load

     <h:form id="common_chart_form" prependId="flase">
        <p:growl id="growl" showDetail="true" autoUpdate="true"
            sticky="false" />
            <p:outputLabel id="labelvalue" value="aaaaaaaaaa"/>

            <p:chart id="chart" type="bar"
                model="#{commonChartController.barModel}" style="height:600px" />

        <p:commandButton value="Print" type="button" icon="ui-icon-print">
            <p:printer target="chart" />
        </p:commandButton>

        <p:commandButton value="Back" action="admin_sales_reports" />
    </h:form>

and this the backing bean of the above page

@Component
@ManagedBean
@RequestScoped
public class CommonChartController implements Serializable{
    private static final long serialVersionUID = 1L;
    @ManagedProperty(value = "#{orderService}")
    public OrderService orderService;
    @ManagedProperty(value = "#{userService}")
    public UserService userService;
    List<MonthSales> salesList;
    private BarChartModel barModel;


    @PostConstruct
    public void init() {
        String dateTo = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("todaysDate");
        String dateFrom = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("beforDate");
        String employeeName = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("employeeName");

        System.out.println("user Name : "+employeeName);

        if(employeeName != null && !employeeName.equals("")){
            User user = userService.getUserByUserName("admin");
            salesList = orderService.getMonthlySalesByUserName(UserUtility.stringDateToJodaDateTime(dateFrom).toDate(), UserUtility.stringDateToJodaDateTime(dateTo).toDate(), user);
            createBarModel(salesList, user);
        }else {
            salesList = orderService.getMonthlySales(UserUtility.stringDateToJodaDateTime(dateFrom).toDate(), UserUtility.stringDateToJodaDateTime(dateTo).toDate());
            createBarModel(salesList);
        }
//              
//        salesList = orderService.getMonthlySales(UserUtility.stringDateToJodaDateTime(dateFrom).toDate(), UserUtility.stringDateToJodaDateTime(dateTo).toDate());
//        createBarModel(salesList);
    }
}

i can read the "dateTo" param and "dateFrom" param. problem is "employeeName" param is alwayas null

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user2567005
  • 271
  • 1
  • 13
  • 27
  • Obvious question: When you select a user from the autocompletion list, `salesReportMainController.userFromAutoComplete` is filled and this user has a `userName` set? – Smutje Aug 15 '14 at 05:27
  • ye so how should i passed its value then – user2567005 Aug 15 '14 at 06:33
  • i just make my "SalesReportMainController" into SessionScope that also didnt work – user2567005 Aug 15 '14 at 06:59
  • Yes, I mean have you verified it by debugging? It seems OK for me. – Smutje Aug 15 '14 at 07:33
  • You're misusing the `p:commandButton`. Here you need to perform a plain GET request for the destination page, passing some view params. Replace it with a `p:button`. You may find [this](http://stackoverflow.com/questions/13070537/difference-between-hbutton-and-hcommandbutton) post useful. – Aritz Aug 15 '14 at 21:29

0 Answers0