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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:30:42+00:00 2026-05-27T00:30:42+00:00

I’m having some problems with bean initialization. I have an edit form to update

  • 0

I’m having some problems with bean initialization. I have an “edit” form to update
some user data. The user is previously created in the database and
I retrieve successfuly the data and put it in the form.

This is the form with id parameter 1 (/cms/admin/users/edit.jsf?id=1):

<h:panelGrid styleClass="general-form" columns="3" id="ajaxForm">
<h:outputLabel for="name" value="#{cms['users.add.name']}" />
<p:inputText required="true" id="name"
    value="#{editUserController.user.name}"
    label="#{cms['users.add.name']}">
    <f:validateLength minimum="3" />
</p:inputText>
<p:message for="name" />

<h:outputLabel value="#{cms['users.add.lastname']}" />
<p:inputText id="lastname" label="#{cms['users.add.lastname']}"
    required="true" value="#{editUserController.user.lastname}">
    <f:validateLength minimum="3" />
</p:inputText>
<p:message for="lastname" />

<h:outputLabel value="#{cms['users.add.username']}" />
<p:inputText id="username" required="true"
    label="#{cms['users.add.username']}"
    value="#{editUserController.user.username}">
    <f:validateLength minimum="3" />
</p:inputText>

<p:message for="username" />

<h:outputLabel value="#{cms['users.add.password']}" />
<p:password id="password" required="true"
    value="#{editUserController.user.password}"
    promptLabel="#{cms['users.error.enterPassword']}"
    weakLabel="#{cms['users.error.weakPassword']}"
    goodLabel="#{cms['users.error.goodPassword']}"
    strongLabel="#{cms['users.error.strongPassword']}"
    binding="#{password}" label="#{cms['users.add.password']}">
    <f:validateLength minimum="6" />
</p:password>
<p:message for="password" />

<h:outputLabel value="#{cms['users.add.confirmPassword']}" />
<p:password id="passwordConfirm" required="true"
    value="#{editUserController.confirmPassword}"
    promptLabel="#{cms['users.error.enterPassword']}"
    weakLabel="#{cms['users.error.weakPassword']}"
    goodLabel="#{cms['users.error.goodPassword']}"
    strongLabel="#{cms['users.error.strongPassword']}"
    label="#{cms['users.add.confirmPassword']}">
    <f:validateLength minimum="6" />
    <f:validator validatorId="passwordValidator" />
    <f:attribute name="password" value="#{password.value}" />
</p:password>
<p:message for="passwordConfirm" />

<h:outputLabel value="#{cms['users.add.active']}" />
<h:selectOneMenu value="#{editUserController.user.active}">
    <f:selectItem itemValue="true" itemLabel="Sí" />
    <f:selectItem itemValue="false" itemLabel="No" />
</h:selectOneMenu>
<h:outputText value="" />

<h:outputLabel value="#{cms['users.add.role']}" />
<h:selectOneMenu value="#{editUserController.securityRole}">
    <f:selectItems value="#{editUserController.securityRoles}" />
</h:selectOneMenu>
<h:outputText value="" />

<h:outputText value="" />
<p:commandButton action="#{editUserController.saveUser}"
    style="margin-top:20px;" ajax="false"
    value="#{cms['general.save']}"></p:commandButton>

This is the Managed Bean (EditUserController.java):

public class EditUserController extends GeneralController implements
    Serializable {

private static final long serialVersionUID = 1L;

@ManagedProperty("#{param.id}")
private Integer id;

private UserService userService;

private SecurityRoleService securityRoleService;

private User user;

private String confirmPassword;

private Map<String, SecurityRole> securityRoles;

private String securityRole;

@PostConstruct
public String checkUser() {
    try {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        this.id = Integer.parseInt(facesContext.getExternalContext().getRequestParameterMap().get("id"));

        setUser(userService.findById(id));
        Map<String, SecurityRole> secRoles = new ListUtils<String>().toMap(
                securityRoleService.findAll(0, 30, "", ""), "name");

        setSecurityRoles(secRoles);

        setSecurityRole(user.getSecurityRole().getId().toString());

        return "edit";
    } catch (EntityNotFoundException e) {
        return FATAL;
    } catch (NoSuchMethodException e) {
        return FATAL;
    } catch (InvocationTargetException e) {
        return FATAL;
    } catch (IllegalAccessException e) {
        return FATAL;
    }
}

public String saveUser() {
    try {   
        System.out.println("User saved!!");
        return SUCCESS;
    } catch (Exception e) {
        FacesContext.getCurrentInstance().addMessage(
                null,
                new FacesMessage(MessageProvider.getMessageProvider()
                        .getValue("cms", "general.error")));
        return ERROR;
    }
}

//getters and setters ...

With the @Postconstruct method I initialize the user variable according to the id param.
Then the form is displayed correctly with all data prefilled. But when I click in the
commandButton I get an exception:

Error creating bean with name 'editUserController': Invocation of init method failed; nested exception is java.lang.NumberFormatException: null

I understand where is the error. In the @Postconstruct method the variable id has not
been “initialized” because there is not any id parameter in the request. I know I can solve this
scoping the bean to session or application, but it does not make any sense to have the bean there
just to perform this simple action.

How can I do this simple form? I just want to get an id parameter, show a form with prefilled data
then give the posibility to change the data an finally submit the form to save the new values
into the DB

Thank you all

  • 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-27T00:30:43+00:00Added an answer on May 27, 2026 at 12:30 am

    If putting the bean in the view scope and using <f:viewParam> is not an option, then you’d need to pass the parameter back to the next request by including it as <f:param> in the UICommand component:

    <p:commandButton action="#{editUserController.saveUser}"
        style="margin-top:20px;" ajax="false"
        value="#{cms['general.save']}">
        <f:param name="id" value="#{editUserController.id}" />
    </p:commandButton>
    

    See also:

    • ViewParam vs @ManagedProperty(value = "#{param.id}")
    • Communication in JSF 2.0 – Processing GET request parameters
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.