0
votes

I am facing a peculiar issue with input text field behavior. I have created a jsf page using template. The final loaded page has a header to show logo and menu. The content page has a option field and one input text box (h:inputText) and there is commandLink (Search) component. When I enter any value in the input text field and click on the Search(commandLink), I am making a ajax call to get the value entered in the input text field and drop down select, the method associated to the ajax call in the backing bean is called but getting null value for both the fields. This case is happening when I am loading the home page first and then clicking on the menu to load that particular page. But when I am loading the page directly by providing the url in the browser address field or navigate to some other page using the menu and comeback to this particular page, everything is working fine as I am getting both values in the backing bean. I couldn't find the way to resolve it and need your help.

Here are some important points in terms of implementations. 1. There is just one h:form which is mentioned in the master template and no multiple forms can be found when the page gets loaded. 2. The Menu navigation is done through redirect instead of forward. 3. Backing bean is in viewScoped with import javax.faces.bean.ViewScoped and same package for managed bean annotation. 4. There is no where mentioned immediate=true attribute in the page with any jsf components. 5. There are public getter/setter methods for the input text box and select drop down. 6. I am using mojarra JSF library API as primary JSF component, weblogic 10.3.6 as app server and IE v8 as browser.

1. JSF page code snippet

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" xmlns:o="http://openfaces.org/">

<ui:composition
template="/resources/common/templates/rsaMasterTemplate.xhtml">
<ui:define name="content">
    <f:view>
<h:outputScript name="js/security.js" library="common" />
<h:panelGroup>
<table width="50%">
    <tr class="scrollerTable border">
        <td><h:outputLabel styleClass="fieldLabelText"
                value="#{message['application.common.label.searchBy']}" /></td>
        <td class="cellSpacer"></td>
        <td><h:selectOneMenu id="selOneMenu_SearchCriteria"
                styleClass="entryfieldText"
                value="#{urlMaintenanceManagedBean.selectedSearchCriteria}">
                <f:selectItems
                    value="#{urlMaintenanceManagedBean.searchCriteriaList}" />
            </h:selectOneMenu></td>
        <td class="cellSpacer"></td>
        <td><h:inputText id="iptTxt_SearchValue"
                styleClass="entryfieldText" size="30"
                value="#{urlMaintenanceManagedBean.searchValue}"></h:inputText>
        </td>
        <td class="cellSpacer"></td>
        <td><h:commandLink styleClass="buttonOrange">
                <f:ajax event="click"
                    execute="selOneMenu_SearchCriteria iptTxt_SearchValue"
                    render="panGrp_UrlSearchResults"
                    listener="#{urlMaintenanceManagedBean.search}" />
                <span>#{message['application.common.button.search']}</span>
            </h:commandLink></td>
        <td class="cellSpacer"></td>
        <td><h:commandLink styleClass="buttonOrange"
                onclick="clear('iptTxt_SearchValue')">
                <span>#{message['application.common.button.clear']}</span>
            </h:commandLink></td>
    </tr>
</table>
</h:panelGroup>

2. Backing bean method

public void search(AjaxBehaviorEvent event) {

    // TODO Temporary hard coding. To be removed once the value passing to
    // bean gets resolved.
    System.out.println("selectedSearchCriteria= " + selectedSearchCriteria);
    System.out.println("SearchValue= " + searchValue);

    // reset urlList
    if (urlList != null && !urlList.isEmpty()) {
        urlList = null;
    }
    // Call to service layer for search operation starts here
    }
    public String getSelectedSearchCriteria() {
    return selectedSearchCriteria;
}

public void setSelectedSearchCriteria(String selectedSearchCriteria) {
    this.selectedSearchCriteria = selectedSearchCriteria;
}

public String getSearchValue() {
    return searchValue;
}

public void setSearchValue(String searchValue) {
    this.searchValue = searchValue;
}

The SOP lines above give null value for the fields which have getter/setter methods and assigned against the field when the "Search" commandLink is clicked.

Looking for your suggestions.

3

3 Answers

0
votes

I'm pretty new to JSF myself,but considering theres no answer yet I figure why not give it a shot.

According to https://stackoverflow.com/a/3681276/2277482 if you assign a property in the backing bean to a h:inputtext it will update in the backing bean if changed on the page.So you can check if it works this way without the ajax on the inputtext.

For h:selectOneMenu I found https://stackoverflow.com/a/13327653/2277482. So if you want to implement that answer without primefaces try f:ajax.

I can't test this at the momemnt though so I'm just giving suggestions blindly.

Would've commented this,but my rep is too low :(

0
votes

I think you are just missing the <h:form> tag around your fields. Without that, giving execute=xy is useless, because there is no form to be executed.

0
votes

create a constructor for your bean

public beanname() { }