Restore text value after validation fail

眉间皱痕 提交于 2019-12-11 04:57:56

问题


I am using jQuery to bind a keyup event of an inputText, so that the value of it will be set to the span text.

<h:form id="formId">
     <script type="text/javascript">
      $(document).ready(function(){
        var portletNamespace = '#<portlet:namespace/>\\:formId\\:';             
        $(portletNamespace+'txtSimpleText').live('keyup',function(){    
             $(portletNamespace+'spanText').text($(portletNamespace+'txtSimpleText').val());    
        }); 
     });    
    </script>

    <h:inputText id="txtSimpleText" value=""/>
    <h:inputText required="true" value=""/>
    <h:outputText id="spanText"></h:outputText >
    <h:commandButton actionListener="#{myController.someAction}" value="do somthing"/>
</h:form>

It works fine, but at the first validation fail I lose my spanText text! This only happens the first time; at the second validation fail the spanText text is still there. I only need it in the view layer, and have no need to use it after the form is submitted. Please show me how to restore my spanText after validation fail!

PS: There is a reason I cannot use Ajax to store and set the value for spanText.

来源:https://stackoverflow.com/questions/11539544/restore-text-value-after-validation-fail

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