1

JSF:

<h:form>
    <h:inputHidden id="promo" value="promo-motopair"/>
    <h:commandButton value="#{m.buy}" action="#{showProducts.buy}"/>
</h:form>


<h:form>
    <h:inputHidden id="promo" value="promo-northduck"/>
    <h:commandButton value="#{m.buy}" action="#{showProducts.buy}"/>
</h:form>

Bean, where get clicked id:

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

Can't get it because id is equal promo, but prepended with prefix, looks like j_idt40:promo

How to handle such situation?

I need get item by key. I suppose,that key(which is id in inputhidden) should be single. I should rely on promo value only.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
sergionni
  • 13,290
  • 42
  • 132
  • 189

1 Answers1

3

Don't use <h:inputHidden>. It's unsuitable for your particular functional requirement. Just use standard HTML <input type="hidden">.

<h:form>
    <input type="hidden" name="promo" value="promo-motopair"/>
    <h:commandButton value="#{m.buy}" action="#{showProducts.buy}"/>
</h:form>

<h:form>
    <input type="hidden" name="promo" value="promo-northduck"/>
    <h:commandButton value="#{m.buy}" action="#{showProducts.buy}"/>
</h:form>

It's in a request scoped bean by the way also available by just

@ManagedProperty("#{param.promo}")
private String promo;

without the need to manually grab it from the request parameter map.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • BalusC,hi .Thank you for hint,and the problem is showProducts bean is `SessionScoped` – sergionni May 25 '12 at 14:02
  • 1
    Use `` then. See also http://stackoverflow.com/questions/6377798/what-can-fmetadata-and-fviewparam-be-used-for You can also just stick to the request parameter map grabbing approach :) – BalusC May 25 '12 at 14:02
  • @BalusC: How about getting the component from ActionEvent and then getParent#findComponent("promo")? – Ravi Kadaboina May 25 '12 at 14:06