Reputation: 145
I'm trying to set a class or id parameter on a <h:inputHidden>
in JSF. The code looks like this:
<h:inputHidden value="#{getData.name}" class="targ" />
But in the browser, the class isn't set:
<input type="hidden" name="j_idt6" value="j_idt6">
I need to set a class to this parameter, because I have a JavaScript autocomplete function for a <h:inputText>
that sets a value in the hidden input, which needs to be passed in the next page.
Any ideas? Thanks!
Upvotes: 6
Views: 4457
Reputation: 1
None of these answers here satisfied my needs (need the PrimeFaces component, need class not ID, wrapping is too much work), so here's what I came up with:
pass:hidden-class="blah"
(in my case, it's xmlns:pass
up top)[attribute=value]
selector:
That basically boils down to using something like this (because h:inputHidden
becomes a regular input
): document.querySelector("input[hidden-class=" + blah + "]")
Upvotes: 1
Reputation: 668
I know it's a little bit late, but it can help someone in the future. As inputHidden shows nothing in the browser there's no sense to allow it to have a class. You can use the Id but as the Id could change as you change the component parents using it would bring some headache.
I'd suggest as a workaround, you can give it a parent so you can manipulate it by javascript.
Exemple:
JSF
<h:panelGroup styleClass="someCssClass">
<h:inputHidden id="someId" value="someValue" />
</h:panelGroup>
Javascript (using jQuery, you could use pure javascript also)
$('.someCssClass input[type=hidden]').val('yourNewValue');
Upvotes: 5
Reputation: 145
In the end, I used a standard HTML <input type="hidden">
tag, as I had no advantages for using the JSF one. If you're trying to set a value in a hidden input with JavaScript, I recommend using this workaround.
Upvotes: 0
Reputation: 1
Please, see similar question - How can I know the id of a JSF component so I can use in Javascript
You can sed "id" property, but in final html code it can be not the same, but composite: for example, if your input with id="myhidden"
is inside form with id="myform"
, final input will have id="myform:myhidden"
.
Upvotes: 0