简体   繁体   中英

How apply CSS on a <h:inputText>?

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 any class attribute by default. You can add a the class attribute by defining a styleClass attribute in the JSF tag

<h:inputText id="name" styleClass="text-input" value="#{contact.client.name}" >
</h:inputText>

See the reference for details

The CSS class selector start with . , you should try the following:

.text-input{
   border:solid 1px #e0e0e0;
}

Take a look at the API . There is an attribute styleClass which can be set

In most cases it's more appropriate to use h:outputLabel. I've not had problems applying css to h:outputLabel, but have had similar css application woes as you using h:outputText.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM