css expression not work for primefaces

て烟熏妆下的殇ゞ 提交于 2019-12-25 05:27:08

问题


Below code not work, but it's work fine for jsf1.2. Now the framework is jsf2.0 and primefaces 3.2

<p:inputText id="pInputText4"  disabled="true" value="This is Input
Text" style="color:
expression((this.disabled==true)?'#0f0':'#f00');"/>

I have another question that why

<p:selectOneMenu id="roleId" value="#{accessPage.roleId}" required="true">
   <f:selectItem itemLabel="#{msg['label.common.selecthere']}" itemValue="#{null}" />
   <f:selectItems var="code" value="#{accessPage.roleIdList}"   
       itemLabel="#{code.codeDesc}" itemValue="#{code.codeId}" />
   <f:valueChangeListener type="com.ncs.caseconnect.base.app.utils.ValueChangeCleanUtils"/>
   <p:ajax listener="#{accessPage.roleOrModuleChanged}" update="accessRight" />
</p:selectOneMenu>

the valueChangeListener and ajax not work when we select the first null option. If we remove the required attribute it works fine. Is it conflict between required and valueChangeListener?


回答1:


You can use #{component} in any of the component's attributes to get hold of the concrete UIComponent instance of the current component. This resolves in case of <p:inputText> to an instance of UIInput which in turn has a boolean disabled property. So, this should do:

<p:inputText id="pInputText4" disabled="true" value="This is Input Text" 
    style="color: #{component.disabled ? '#0f0' : '#f00'};" />

But a better practice is to define styling in a CSS file instead of straight in the markup as it eliminates duplication and maintenance headache.

<p:inputText id="pInputText4" disabled="true" value="This is Input Text" 
    styleClass="foo" />

with

.foo {
    color: #f00;
}

.foo[disabled] {
    color: #0f0;
}

Or if you want to apply this globally on all input elements

<p:inputText id="pInputText4" disabled="true" value="This is Input Text" />

with

input {
    color: #f00;
}

input[disabled] {
    color: #0f0;
}



回答2:


My guess that eventually you will use disabled="#{someBean.someCondition}"

and in this case you will have to use EL expression in your style too m like this

<p:inputText id="pInputText4"  disabled="#{someBean.someCondition}" value="This is Input
    Text" style="color:#{someBean.someCondition ?'#0f0':'#f00'}"/>

Dunno about the expression but are you sure that you can access this and that this.disabled really gives you the value of your disabled attribute ? (try displaying it in alert(this.disabled))



来源:https://stackoverflow.com/questions/10991576/css-expression-not-work-for-primefaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!