I’m trying to apply CSS to my <h:inputText> but without success so far :
<h:form id="contactform">
<h:panelGrid columns="3">
<h:outputLabel for="name">Name</h:outputLabel>
<h:inputText id="name" value="#{contact.client.name}" >
<f:ajax event="blur" render="nameMessage"></f:ajax>
</h:inputText>
<h:message id="nameMessage" for="name" />
<h:commandButton value="Send" action="#{contact.sendMessage}">
<f:ajax execute="@form" render="@form" />
</h:commandButton>
<h:messages globalOnly="true" layout="table" />
</h:form>
My CSS:
#contactform .text-input{
background-color:#fbfbfb;
border:solid 10px #000000;
margin-bottom:8px;
width:178px;
padding:8px 5px;
color:#797979;
}
If i try to apply this CSS style in some HTML input field it works, but not in JSF 2.0.
EDIT:
Update this part of my code in JSF:
<h:inputText id="name" styleClass="text-input" value="#{contact.client.name}" >
Insert this code in my CSS file:
text-input{
border:solid 1px #e0e0e0;
}
But it seems the same thing, nothing change.
Output:
<form id="j_idt35" name="j_idt35" method="post" action="/brainset/contact.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_idt35" value="j_idt35" />
<table class="contactform">
<tbody>
<tr>
<td><label for="j_idt35:name"> Name</label></td>
<td><input id="j_idt35:name" type="text" name="j_idt35:name" class="text-input" onblur="mojarra.ab(this,event,'blur',0,'j_idt35:nameMessage')" /></td>
<td><span id="j_idt35:nameMessage"></span></td>
</tr>
</form>
EDIT 2:
There is something weird here.
Update my code with the help of you guys:
<h:form>
<h:panelGrid id="contactform" styleClass="contactform" columns="3">
<h:outputLabel for="name">Nome</h:outputLabel>
<h:inputText id="name" value="#{contact.client.name}" >
<f:ajax event="blur" render="nameMessage"></f:ajax>
</h:inputText>
<h:message id="nameMessage" for="name" />
</h:panelGrid
</h:form>
so my CSS style is now this way:
.contactform .text-input{
background-color:#fbfbfb;
border:solid 50px #000000;
margin-bottom:8px;
width:178px;
padding:8px 5px;
color:#797979;
}
if i apply the css style in a specific input-text it works, but it shouldn’t apply to all input-text below in my table ?
Any idea?
The output
<h:inputText ...>should not have anyclassattribute by default. You can add a theclassattribute by defining astyleClassattribute in the JSF tagSee the reference for details