JSF field highlighting with ajax posts?

北慕城南 提交于 2019-12-06 20:03:27
BalusC

That article was more targeted on JSF 1.x. JSF 2.x offers now a lot of advantages of which the following are beneficial for your particular requirement:

  • You can refer the current component in EL by #{component}. In case of input components this is the UIInput which in turn has an isValid() method. This could be used in styleClass attribute.
  • You can use <f:ajax> to re-render parts of the view, also <script> elements.

1+1 is...

<h:inputText id="input1" value="#{bean.input1}" required="true" styleClass="#{component.valid ? '' : 'error'}">
    <f:ajax render="@this input1message focus" />
</h:inputText> 
<h:message id="input1message" for="input1" />
...
<h:inputText id="input2" value="#{bean.input2}" required="true" styleClass="#{component.valid ? '' : 'error'}">
    <f:ajax render="@this input2message focus" />
</h:inputText> 
<h:message id="input2message" for="input2" />
...
<h:panelGroup id="focus"><script>jQuery(":input.error:first").focus();</script></h:panelGroup>

No need for a PhaseListener anymore. You could if necessary wrap the input markup boilerplate in a composite component or a tag file.


Back to your concrete question about the onevent attribute, check this answer: JSF 2: How show different ajax status in same input?

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