Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set class or ID on <h:inputHidden> in JSF

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!

like image 469
Tudor Gafiuc Avatar asked Nov 01 '13 08:11

Tudor Gafiuc


1 Answers

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');
like image 127
Jonathas Pacífico Avatar answered Nov 15 '22 09:11

Jonathas Pacífico