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

  • SEARCH
  • Home
  • 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 8689103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:33:18+00:00 2026-06-12T23:33:18+00:00

I have following xhtml document: <h:body> <ui:composition template=templates/layout.xhtml> <ui:define name=content> <c:if test=#{sessionBean.userCode > 0}>

  • 0

I have following xhtml document:

  <h:body>
   <ui:composition template="templates/layout.xhtml">
      <ui:define name="content">
        <c:if test="#{sessionBean.userCode > 0}">
          <h:form id="findStudentForm">
            <p:outputPanel id="resultsPanel">
              <c:if test="#{studentsBean.student != null}">
                <h2><h:outputText value="#{studentsBean.student.fullName}"/></h2>
                <h3>Personal data</h3>
                  . . .
                <p align="center">
                <p:commandButton value="Search students" update="@form">
                  <f:setPropertyActionListener value="#{null}" 
                    target="#{studentsBean.student}"/>
                </p:commandButton>
                </p>
              </c:if>
              <c:if test="#{studentsBean.student == null}">
                <h2>Student search</h2>
                  . . .
                <p align="justify">
                  First name
                  <h:inputText value="#{studentsBean.pattern}"/>
                  <p:commandButton value="Поиск" update="resultsPanel"/>                  
                </p>
                <p:dataTable id="resultsTable" var="student" 
                   value="#{studentsBean.studentsList}" 
                             widgetVar="studentsTable" emptyMessage="No records found">
                  . . . 
                  </p:column>
                  <p:column headerText="Actions">
                    <p:commandButton value="Details" update="@form">
                      <f:setPropertyActionListener value="#{student}" 
                        target="#{studentsBean.student}"/>
                    </p:commandButton>
                  </p:column>  
                </p:dataTable>
              </c:if>
            </p:outputPanel>
          </h:form>
        </c:if>
        <c:if test="#{sessionBean.userCode == 0}">
          <ui:include src="templates/include/error.xhtml"/>
        </c:if>
      </ui:define>  
    </ui:composition>
  </h:body>

Also I have following Managed Bean (StudentsBean):
. . .

@Named(value = "studentsBean")
@RequestScoped
public class StudentsBean {

  @Inject
  SessionBean session;
  private Student student = null;
  private String pattern = "";
  private String groupName = "";
  @Inject
  private StudentInterface studentProvider;

  . . .

  public String getPattern() {
    return pattern;
  }

  public void setPattern(String pattern) {
    this.pattern = pattern;
  }

  public List<Student> getStudentsList() {
    List<Student> result = new ArrayList<Student>();
    if (studentProvider != null) {
      try {
        result = studentProvider.findStudents(pattern);
      } catch (StudentException e) {
        session.printError(e.getMessage());
      }
    }
    return result;
  }
  . . .

And finally, I have a class StudentsProvider:

public class StudentProvider implements StudentInterface {

  private Connection connection = null;

   . . .

  @Override
  public List<Student> findStudents(String pattern) throws StudentException {
    List<Student> result = new ArrayList<Student>();
    String addon = "";
    if (pattern.trim().isEmpty()) {
      addon = "TOP 10 ";
    }
    try {
      PreparedStatement statement = connection.prepareStatement(
              "SELECT " + addon + "st_pcode, gr_Name, st_FullName "
              + "FROM students, groups WHERE (st_grcode = gr_pcode) AND (st_FullName LIKE ?) "
              + "ORDER BY gr_Name, st_FullName;", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      statement.setString(1, pattern + "%");
      ResultSet rs = statement.executeQuery();
      while (rs.next()) {
        result.add(getStudent(rs.getString("st_pcode")));
      }
      rs.close();
      statement.close();
    } catch (Exception e) {
      throw new StudentException("Error reading list: " + e.getMessage());
    }
    return result;
  }

  public StudentProvider() throws StudentException {
    try {
    ConnectionProvider provider = new ConnectionProvider();
    connection = provider.getConnection();
    } catch (ConnectionException e) {
      throw new StudentException("Connect error: " + e.getMessage());
    }
  }

  @Override
  public void finalize() throws Throwable {
    connection.close();
    super.finalize();
  }
}

If variable “pattern” an empty string, PreparedStatement returns 10 “first” records. But if the “pattern” has a content – PreparedStatement finds some records. During debug, seems like PreparedStatement works well and returns result set, but no records shows in the re”sultsTable”. In additional, I found, that while updating process method

studentProvider.findStudent(pattern)

calling many times. I think, that number of method calls depends of number of records in the “resultsTable”.

Before injection, with hard linked objects everything works fine. What’s wrong?

By the way, I can’t understand one thing. Say, I have a button

<p:commandButton value="Details" update="@form">
    <f:setPropertyActionListener value="#{student}" 
        target="#{studentsBean.student}"/>
</p:commandButton>

in the each record of “resultsTable” (see xhtml listing before for more details). I found, that this button sometimes doesn’t work.
If resultsTable is empty at the beginning – button doesn’t work, but if resultsTable is NOT empty – button work. So how can I make button always working?

  • 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-12T23:33:20+00:00Added an answer on June 12, 2026 at 11:33 pm

    A better way to do this would be (just a sketch):

    // an action method in your backing bean.
    // This will call your search method and set the values behid your dataTable
    public void searchStudents(String pattern) {
        setStudentsList(findStudent(pattern));
    }
    

    After the call finished update your dataTable:

    <p:commandButton update="resultsTable" action=#{studentProvider.findStudent(pattern)}"
    

    To answer your second question: Why JSF calls getters multiple times, which implies that putting your business logic methods into getters (without lazy loading) seems to be a bad idea (another related question: JSF calling setter & getter multiple times).

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

Sidebar

Related Questions

I have the following within an XHTML document: <script type=text/javascript id=JSBALLOONS> function() { this.init
I have the following code : <html xmlns=http://www.w3.org/1999/xhtml> <body style=height: 1336px> <input type=hidden id=loadingtime/>
I have the following XML document <?mso-infoPathSolution name=urn:schemas-microsoft-com:office:infopath:TCM-TCP:-myXSD-2012-02-20T14-33-22 solutionVersion=1.0.0.65 productVersion=14.0.0.0 PIVersion=1.0.0.0 href=https://devcoop.oceanspray.com/sites/TCM2/FormServerTemplates/TCM-TCP.xsn?> <?mso-application progid=InfoPath.Document
Suppose we have the following HTML file: <html xmlns=http://www.w3.org/1999/xhtml> <head> <title>Test iframe download</title> <script
I have the following form: <form action= method=get> <input name=form1 type=radio onclick=document.forms[0].testbox.value='0.00'; /> <input
Let's say I have following table like this <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0
Trying to use JSTL but have the following problem: Index.xhtml page: <?xml version=1.0 encoding=UTF-8?>
In my xhtml page I have the following tag included: <f:view locale=#{languageBean.locale}> ... </f:view>
I have the following code: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> <html
I have the following code: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> <html

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.