0
votes

Im using a primefaces FieldSet component and have a button field specified inside the field set. I have a requirement, Where, when I click on the command button, a h:selectonemenu & an inputtext should be displayed and On further click, the h:selectOnemenu &inputtext should be hidden. Below is the code that I have written to show & hide. The show part works fine. But when I try to click on the button to hide, it does not work.

xhtml code

<h:panelGrid id="grid1" columns="3">
    <p:fieldset id="GlobalAdjustment" legend="GlobalAdjustment"  style="font-size:12px !important;width:30%" >
    <h:commandButton  id="globalAdjustID"  image="#{review.imageUrl}" actionListener="#{review.showUpdateList}" />  
    </p:fieldset>

    <h:selectOneMenu id="SelectID"   value="#{review.reviewList}"  rendered="#{demandReview.selectoneRenderer}">
        <f:selectItems id="FilterSelectListID"   value="#{review.reviewListIDs}" style="font-size:12px !important"></f:selectItems>
    </h:selectOneMenu>
    <h:inputText id="fieldUpdateID" required="false" rendered="#{review.inputTextRenderer}"></h:inputText>
</h:panelGrid>

ManagedBean ActionListener method

public void showUpdateList(ActionEvent event)
{
    System.out.println("entering the Action Method:");
    Map<String, Object> idMap = new HashMap<String, Object>() ;
    idMap = event.getComponent().getAttributes();
    String url = (String) idMap.get("image");
    System.out.println("The url is :"+url);
    if(url.equals("/images/add_data_button.png")){
        //upbean.setImageUrl("/images/remove_data_button.png") ;
        imageUrl ="/images/remove_data_button.png" ;
        selectoneRenderer = true;
        inputTextRenderer = true;
    }else
    {
        imageUrl ="/images/add_data_button.png" ;
        selectoneRenderer = false;
        inputTextRenderer = false;
    }
}

When I click the command button inside the fieldset for the first time, it works fine and displays the selectoneMenu & the textbox. Once further clicks, the ActionListener is not getting invoked. Please help me resolve the issue.

Thanks

2
It could be that JSF's INVOKE APPLICATION phase is not reached because conversion or validation fails. Do you have an h:messages tag on your page to display errors? If not, add one to see what happens.Matt Handy

2 Answers

1
votes

You can try another approach. Use p:commandButton with an update attribute like this:

<h:panelGrid id="grid1" columns="3">
    <p:fieldset id="GlobalAdjustment" legend="GlobalAdjustment"  style="font-size:12px !important;width:30%" >
    <p:commandButton  id="globalAdjustID"  image="#{review.imageUrl}" actionListener="#{review.showUpdateList}" update="grid1"/>  
    </p:fieldset>

    <h:selectOneMenu id="SelectID"   value="#{review.reviewList}"  rendered="#{demandReview.selectoneRenderer}">
        <f:selectItems id="FilterSelectListID"   value="#{review.reviewListIDs}" style="font-size:12px !important"></f:selectItems>
    </h:selectOneMenu>
    <h:inputText id="fieldUpdateID" required="false" rendered="#{review.inputTextRenderer}"></h:inputText>
</h:panelGrid>

This way you'll use partial processing and the conditional renderization of the panel's inner components will be done through AJAX.

Also, it could be a good idea to check your server's console to see if there are any messages in the queue that were not displayed.

0
votes

Does the requirement specify using the server side? For something like this, I would have thought a simple Javascript script would have been better suited.

For example, use the jQuery library to do something like:

<h:commandButton id="xyz" onclick="$('#elementId').toggle();"/>