Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3615534
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:23:08+00:00 2026-05-18T22:23:08+00:00

I am using Seam 2.2 with Facelets and I need to validate 2 fields

  • 0

I am using Seam 2.2 with Facelets and I need to validate 2 fields from a JPA entity comparing both to check its values before insert.

Here is fragment from my enttity:

@Entity
@Scope(ScopeType.CONVERSATION)
@Name("metaAbastecimento")
public class MetaAbastecimento  implements Serializable{
 private float abastecimentoMinimo;

 private float abastecimentoMaximo;


 @Column
 public float getAbastecimentoMinimo() {
  return abastecimentoMinimo;
 }

 @Column
 public float getAbastecimentoMaximo() {
  return abastecimentoMaximo;
 }

 public void setAbastecimentoMinimo(float abastecimentoMinimo) {
  this.abastecimentoMinimo = abastecimentoMinimo;
 }

 public void setAbastecimentoMaximo(float abastecimentoMaximo) {
  this.abastecimentoMaximo = abastecimentoMaximo;
 }
}

Than I have an xhtml which persists this entity:

<rich:panel>
        <f:facet name="header">Detalhe de Meta de Abastecimento</f:facet>


        <s:decorate id="abastecimentoMinimo" template="../layout/display.xhtml">
            <ui:define name="label">Meta(R$) de Abastecimento M&iacute;nimo</ui:define>
            <h:outputText value="#{metaAbastecimentoHome.instance.abastecimentoMinimo}">
            </h:outputText>
        </s:decorate>

        <s:decorate id="abastecimentoMaximo" template="../layout/display.xhtml">
            <ui:define name="label">Meta(R$) Abastecimento M&aacute;ximo</ui:define>
            <h:outputText value="#{metaAbastecimentoHome.instance.abastecimentoMaximo}"/>
        </s:decorate>

        <div style="clear:both"/>

    </rich:panel>

I need to compare these 2 fields before I persist them and check if they are different than 0f and also if abastecimentoMinimo is smaller than abastecimentoMaximo. How can I do this using Seam + Facelets + JPA?

[]s

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:23:09+00:00Added an answer on May 18, 2026 at 10:23 pm

    Cross field validation in JSF 1 is not possible. So you have to do this manually.

    This can in your case either be done by using the @PrePersist and @PreUpdate, or you can do this in your action method manually.

    One tip for you. Avoid having Entity beans as seam components. It’s better to make a separate seam component.

    The reasons for this are:

    Entity beans may be bound to a context variable and function as a seam component. Because entities have a persistent identity in addition to their contextual identity, entity instances are usually bound explicitly in Java code, rather than being instantiated implicitly by Seam.

    Entity bean components do not support bijection or context demarcation. Nor does invocation of an entity bean trigger validation.
    Entity beans are not usually used as JSF action listeners, but do often function as backing beans that provide properties to JSF components for display or form submission. In particular, it is common to use an entity as a backing bean, together with a stateless session bean action listener to implement create/update/delete type functionality.
    By default, entity beans are bound to the conversation context. They may never be bound to the stateless context.

    Note that it in a clustered environment is somewhat less efficient to bind an entity bean directly to a conversation or session scoped Seam context variable than it would be to hold a reference to the entity bean in a stateful session bean. For this reason, not all Seam applications define entity beans to be Seam components.

    @Entity
    public class MetaAbastecimento {
      .....
    
        //If check fails you can throw exception, thus rollback will occur, and commit will not be made
        @PrePersist
        @PreUpdate
        public void check() {
          if(abastecimentoMinimo == 0f || abastecimentoMaximo == 0f && abastecimentoMinimo > abastecimentoMaximo) 
            throw new RuntimeException("Failed!");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there such a thing as JspC in the Seam/JSF/Facelets world? I used the
I'm using these classes: ShoppingCart <-ManyToMany-> Item <-ManyToOne-> ItemCategory All of them are JPA
I am learning facelets and Seam and I'm facing the following problem: I have
I generated a new form using sean-gen (seam new-form) and added another field to
Using Seam 2.1.2 and JSF 1.2 I wonder how to store the users login
I am using Seam to inject beans to my controller using @In annotation. The
I am using seam with EJB3 + JSF and I would like to add
Does Facelets have any features for neater or more readable internationalised user interface text
Ok, I've run across my first StackOverflowError since joining this site, I figured this
I'm wrestling with a strange problem: When I make a change to a POJO

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.