How to pass get-parameter to backing bean in jsf?

旧城冷巷雨未停 提交于 2020-01-06 03:24:15

问题


I have a get-parameter with name controller. When I try to pass it (with propertyChangeListener) to my backing bean I get null instead of the real value of that parameter:

<h:commandButton value="#{msg['mail.send']}" styleClass="mailbutton" action="#{mailSender.sendMail}">
   <f:setPropertyActionListener target="#{mailSender.controllerName}" value="{#param.controller}"/>
</h:commandButton>

So, I have two questions:

  1. What is the proper way to set bean property with a get-parameter value? Actually, I've already get the value from ExternalContext#getRequestParam but maybe there are some other solutions.
  2. More interesting question: why propertyActionListener didn't work here? What does it do actually? (again I have some thoughts about it but it would be nice to read more comprehensive explanations).

回答1:


First, a h:commandButton fires a POST request, not a GET request. To fire a GET request, you need h:outputLink. To set a GET parameter, you need f:param. To set it as a bean property, define it as <managed-property> in faces-config.xml with a value of #{param.name}. More hints and code examples can be found here.

Second, your code is invalid. The f:setPropertyActionListener value should have been #{param.controller}. And to get it to work, the #{param.controller} should already be there during the initial request. It does not automagically set the value in the subsequent request as you seem to expect. For that you need <h:inputHidden value="#{mailSender.controllerName}"/> instead.



来源:https://stackoverflow.com/questions/2539437/how-to-pass-get-parameter-to-backing-bean-in-jsf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!