1

I have following UI part on JSF - it's simple search form with input field and submit:

    <h:form>
        <h:commandButton action="#{operation.found}" value="#{msg.search}" />
        <h:inputText name="searchParam"/>
    </h:form>

And correspondingly, on backend, i attempt to get value of input field next way:

public List<Store> getFound() {

    String name = (String) FacesContext.getCurrentInstance()
            .getExternalContext().getRequestParameterMap().get(
                    "searchParam");

    SessionFactory sessionFactory = new Configuration().configure()
            .buildSessionFactory();

    HibernateTemplate hbt = new HibernateTemplate();

    hbt.setSessionFactory(sessionFactory);

    foundStores = hbt.find(BEAN_PATH + " WHERE name = ?",
            new Object[] { name });

    return foundStores;

}

And null name is passed to backend.

It seems that problem in .jsf part, but from first glance looks ok...

1 Answer 1

2

You must point the <h:inputText> to a managed-bean property:

<h:inputText name="searchParam" value="#{searchBean.searchParam}" />

and define in your bean:

private String searchParam;
public String getSearchParam() {..}
public void setSearchParam(String searchParam) {..}

and then use the searchParam in your getFound() method;

Of course, you need to have the bean defined as managed bean, but I assume you have done it:

<managed-bean>
    <managed-bean-name>searchBean</managed-bean-name>
    <managed-bean-class>mypackage.SearchBean</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

You can check a JSF tutorial (like this, for example)

Sign up to request clarification or add additional context in comments.

5 Comments

See,please, full method for search upper. Managed bean configured ok. I've added searchParam property to bean. An now UI looks like: <h:form> <h:commandButton action="#{operation.found}" value="#{msg.search}" /> <h:inputText name="searchParam" value="#{store.searchParam}" /> </h:form> But still get null on backend.
the action method should be void, and you should use operation.getFound, instead of operation.found.
perhaps i needn't searchParam for bean? it seems that i need just get input value from request and pass it to HQL query. from point of Portlets and JSP it's clear actions, but not so clear for JSF and managed beans.
JSF doesn't put the input parameters in the request in an predictable way. You don't have to get the request at all. Go check some tutorial - this for example - exadel.com/tutorial/jsf/jsftutorial-kickstart.html
thank you for answers, i managed do it with getBean() and serachParam property

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.