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 7948975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:52:12+00:00 2026-06-04T01:52:12+00:00

i am using jsf 2.1.1 and primefaces 3.0.M4. i have a sample jsf page

  • 0

i am using jsf 2.1.1 and primefaces 3.0.M4. i have a sample jsf page that used to post country comments. i use f:viewparam tag with converter to view country pages. here are the codes:

country.xhtml:

<f:metadata>
        <f:viewParam name="country" value="#{countryBean2.selectedCountry}" converter="countryConverter" required="true"/>
    </f:metadata>

    <h:head>
        <title>Country</title>
    </h:head>

    <h:body>
        <h:form id="form">
            <h:outputText value="#{countryBean2.selectedCountry.countryName}" />
            <br/><br/>
            <h:outputText value="Comment:" />
            <h:inputText value="#{countryBean2.comment}" />
            <br/>
            <p:commandButton value="Send" action="#{countryBean2.sendComment}" update="@this" />
        </h:form>
    </h:body>

CountryBean2.java:

@Named("countryBean2")
@SessionScoped
public class CountryBean2 implements Serializable {
    private EntityCountry selectedCountry;
    private String comment;

    public EntityCountry getSelectedCountry() { return selectedCountry; }
    public void setSelectedCountry(EntityCountry newValue) { selectedCountry = newValue; }

    public String getComment() { return comment; }
    public void setComment(String newValue) { comment = newValue; }

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("testPU");

    public void sendComment() {
        EntityManager em = emf.createEntityManager();
        try {
            FacesMessage msg = null;
            EntityTransaction entr = em.getTransaction();
            boolean committed = false;
            entr.begin();
            try {
                EntityCountryComment c = new EntityCountryComment();
                c.setCountry(selectedCountry);
                c.setComment(comment);
                em.persist(c);
                committed = true;
                msg = new FacesMessage();
                msg.setSeverity(FacesMessage.SEVERITY_INFO);
                msg.setSummary("Comment was sended");
            } finally {
                if (!committed) entr.rollback();
            }
        } finally {
            em.close();
        }
    }
}

CountryConverter.java:

public class CountryConverter implements Converter {
    public static EntityCountry country = new EntityCountry();

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("testPU");


    @Override
    public EntityCountry getAsObject(FacesContext context, UIComponent component, String value) {
        EntityManager em = emf.createEntityManager();
        Query query = em.createQuery("SELECT c FROM EntityCountry c WHERE c.countryName = :countryName")
                .setParameter("countryName", value);
        country = (EntityCountry) query.getSingleResult();
        return country;
    }


    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        EntityCountry c = (EntityCountry) value;
        return c.getCountryName();
    }
}

i want to call “setComment” setter without calling CountryConverter, when i am using commandbutton to post comment. how can i do that ?

  • 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-06-04T01:52:13+00:00Added an answer on June 4, 2026 at 1:52 am

    Unfortunately, that’s by design of the <f:viewParam> component. It will convert the request parameter and set the property on every HTTP request, also on postbacks. In order to change this behaviour, you would need to extend <f:viewParam> with a custom component which doesn’t remember the initial request parameter in its state. It’s relatiely simple, instead of delegating the setSubmittedValue() and getSubmittedValue() to StateHelper, you just need to make it an instance variable. This is described in detail in this blog.

    @FacesComponent("com.my.UIStatelessViewParameter")
    public class UIStatelessViewParameter extends UIViewParameter {
    
        private String submittedValue;
    
        @Override
        public void setSubmittedValue(Object submittedValue) {  
            this.submittedValue = (String) submittedValue;
        }
    
        @Override
        public String getSubmittedValue() { 
            return submittedValue;
        }   
    }
    

    OmniFaces has an ready-to-use component for this in flavor of <o:viewParam>. Here is the live example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using JSF 2 and PrimeFaces 2.1 on GlassFish. I have a page that
I'm using JSF 2.0 and PrimeFaces library. I have a page with several inputs
I have a (JSF 2.0/ Primefaces 2.2RC-SNAPSHOT) app that has <p:layout> I use a
I'm using JSF 2.0 and primefaces. I have one page with several inputs inside
I have a PrimeFaces checkbox on a JSF page that I'd like to check/uncheck
I have a JSF 2.0 page that I want to allow a GET parameter
I have a problem using JSF 2.0, PrimeFaces and the tuckey.org UrlRewriteFilter. The problem
I have a inputTextarea that I refresh using PrimeFaces' AJAX poll. When the inputTextarea
I am using JSF 2.0 and PrimeFaces. I have a selectOneMenu and a selectManyCheckbox.
Hi there Im just learning JSF 2 using Primefaces. I have a question regarding

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.