开发者

Problem with a validator used with JSF

开发者 https://www.devze.com 2023-03-26 07:00 出处:网络
I\'am using JSF2.0 I have used a validator that valid an input text ,but no msg appear to indicate that the input is wrong!

I'am using JSF2.0

I have used a validator that valid an input text ,but no msg appear to indicate that the input is wrong!

Update:

Are Their a way that validate inputtext before submitting ,just after typing the inputText?

The JSF code:

 <h:form id="form3">
      <p:panel visible="#{bean.form3Visible}" style="width: 900px;">
         <h:panelGrid width="width: 900px;"    columns="1">
         <p /> 
               <h:selectOneMenu value="#{bean.platform}">
                 <f:selectItem itemLabel="-- Select Plateform-- " itemValue="0"/> 
                 <f:selectItems value="#{bean.getMyListPaltform()}" />
                 <f:ajax listener="#{bean.UpdateChangeEnvironment()}"  render="Environment" />
                </h:selectOneMenu>
             


<h:panelGrid width="width: 160px;" columns="9">                               开发者_如何学编程            
 <h:inputText id="ssFrom" value="#{bean.ssFrom}" required="true"  style="width: 18px" >    <f:validateLongRange   minimum="0" maximum="24"/>
 </h:inputText>
 <h:message  for="ssFrom" id="msgg" style="color:red" />
    </h:panelGrid>                                                                                       
      </p:panel>    
   </h:form>



  

I have solved my problem this is the answer perhaps it can help others :

      <h:selectOneMenu value="#{bean.availabilityDisplay}" id="Display">
          <f:selectItem itemLabel="-- Select Display-- " itemValue="0"/> 
          <f:selectItems value="#{bean.getMyListDisplays()}"/>
          <f:ajax render="Target" />
      </h:selectOneMenu>
         
            
    <p:outputPanel id="Target">
      <h:selectOneMenu value="#{bean.frequency}" id="frequency" rendered="#{bean.availabilityDisplay == 'Availibility Histogramme' or bean.availabilityDisplay == 'Availibility line'}">
        <f:selectItem itemLabel="-- Select Frequency-- " itemValue="0"/>
        <f:selectItems  value="#{bean.getMyListFrequency()}"/>
     </h:selectOneMenu>
   </p:outputPanel>

Thank you


You need to add either a h:message oder a h:messages tag to display the error message.

<h:inputText value="#{bean.ssFrom}" required="true" style="width: 18px" id="ssFrom"> 
    <f:validateLongRange minimum="0" maximum="59"/>
</h:inputText>

<h:message for="ssFrom" />
<!-- OR -->
<h:messages />

h:message is used to display errors for a single field (connected by the for attribute). h:messages can be used to display all error messages of the page. If you set globalOnly="true", it will display only messages that are not "caught" by a h:message tag.


Can you please paste the whole page code.

However possible problems may be:

  • You haven't used a h:message or h:messages tag in the page. Messages are only shown if anyone of these is used in the page
  • Or your text field may not be enclosed with in a h:form
  • Also note that range validators are not triggered when the text field is left empty.
  • For useful messages, use requiredMessage="whatever" validatorMessage="whatever" attributes in the text field


In order to validate <h:inputText> without submitting the form, you need to add ajax capabilities.

<h:inputText id="ssFrom" value="#{bean.ssFrom}" required="true"  style="width: 18px" >    
<f:validateLongRange   minimum="0" maximum="24"/>
<f:ajax execute="@this" event="keyup"/>
</h:inputText>

The f:ajax tag will update your ssForm variable on every key up event and if a validation error occurs, it will be displayed in the <h:message for="ssFrom" /> as Mulmoth said.

0

精彩评论

暂无评论...
验证码 换一张
取 消