1
我有以下的JSF UI的一部分 - 它與輸入字段簡單的搜索表單並提交:無法在JAVA後臺獲得JSF輸入字段值
<h:form>
<h:commandButton action="#{operation.found}" value="#{msg.search}" />
<h:inputText name="searchParam"/>
</h:form>
相應的,在後臺,我試圖獲得價值的輸入字段旁邊道:
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;
}
和空名稱被傳遞到後端。
似乎在.jsf一部分問題,但是從第一眼看上去確定...
見請全部搜索方法上。 配置好的託管bean。 我已經將searchParam屬性添加到bean。 一種現在UI看起來像: \t \t \t \t \t的 \t \t \t的 \t \t 但是在後端仍然是空的。 –
sergionni
2009-11-28 18:59:04
action方法應該是void,你應該使用'operation.getFound'而不是operation.found。 – Bozho 2009-11-28 19:01:00
也許我不需要searchParam for bean? 似乎我只需要從請求中獲取輸入值並將其傳遞給HQL查詢。 從Portlet和JSP的角度來看,這是明確的操作,但對於JSF和受管Bean來說不是那麼清楚。 – sergionni 2009-11-28 19:04:04