views:

240

answers:

2

I am trying to implement a scenario using JSF. I have a commandExButton and when user click this button "A" it shows the panelDialog which contains the selectManyCheckBox items. I generat these items in the backend bean by parsing one file which is continuously getting updated. What I want is, whenever I click this button "A" I should get the latest selectItems by parsing the file through the backend bean. But what I get it the same selectItem which was generated when page rendered first time. So as of now I have a workaround, in which I included one refresh button which actually refresh the page and then user click "A" to get the latest selectItem by parsing the current file's content. But is it doable in anyway without adding new button and using the existing button?

Following is the code which I am using

<td>
    <hx:commandExButton id="preferenceButton" styleClass="form" value="#{nls.preferenceLink}"
        title="#{nls.preferenceLinkTitle}" type="submit" />
</td>
<td>
    <h:form id="PrefForm" rendered="#{Test.isCurrent}">
        <hx:panelDialog type="modal" id="preferenceSet" styleClass="panelDialog" for="preferenceButton"
            title="#{nls.preferenceDialogTitle}">
            <h:outputText styleClass="panelStartMessage" style="display:block;"
                value="#{nls.preferenceDialogWindowText}" />
            <h:panelGroup rendered="#{Test.hasSelectItem }"
                style="display:block;width:300px;height:360px;overflow:auto;" styleClass="panelGroup"
                id="prefPanelGroup">
                <h:selectManyCheckbox value="#{Test.selectedItems}" layout="pageDirection">
                    <f:selectItems value="#{Test.selectItems}" />
                </h:selectManyCheckbox>
            </h:panelGroup>
            <hx:panelBox styleClass="information_box" id="noCommandWindow" layout="lineDirection"
                rendered="#{!Test.hasSelectItem }">
                <h:outputText styleClass="outputText" id="cmdInfo" value="#{nls.noCommands}" />
            </hx:panelBox>
            <hx:panelBox id="buttonBox1" styleClass="panelStartBox" layout="lineDirection">
                <hx:commandExButton id="submitPref" styleClass="commandExButton" type="submit"
                    value="#{nls.submit}" action="#{Test.action}">
                    <hx:behavior event="onclick" behaviorAction="hide" targetAction="preferenceSet"
                        id="behaviorSubmitPref" />
                </hx:commandExButton>
                <hx:commandExButton id="CancelPref" styleClass="commandExButton" type="submit"
                    value="#{nls.cancel}" action="Test">
                    <hx:behavior event="onclick" behaviorAction="hide" targetAction="preferenceSet"
                        id="behaviorCancelPref" />
                </hx:commandExButton>
            </hx:panelBox>
        </hx:panelDialog>
    </h:form>
</td>

Code in Bean:

public class Test{
    private List<String> selectedItems;
    private List<SelectItem> selectItems;

    public List<SelectItem> getSelectItems() {
        // populate the selectItem here...
    }    
}
+1  A: 

Store the List<SelectItem> selectItems in a separate session scoped bean (assuming that your current one is request scoped), fill it during its construction and add a method like reload() which you invoke only after processing the selected item in the action method. You can access the session scoped bean from inside the request scoped one by @ManagedProperty.

BalusC
Hi BalusC, Thanks for your reply. My current bean is session scoped only. I tried binding the action and actionListener method to selectItems and after that panel dialog display the latest check box select item. But button is not calling the bean method at all,and here i am actually stuck. is there any alternative way?
Anil Vishnoi
"fill it during its construction and add a method like reload()"-- so which component should i bind this method ?should i add another button and attach this refresh button? but in that case it will refresh the whole page,which i want to avoid.I am new to JSF so please bear with my limited knowledge if i didn't understand anything obvious here.
Anil Vishnoi
A: 

Hi BalusC, Thanks for your reply. My current bean is session scoped only. I tried binding the action and actionListener method to selectItems and after that panel dialog display the latest check box select item. But button is not calling the bean method at all,and here i am actually stuck. is there any alternative way?

"fill it during its construction and add a method like reload()"-- so which component should i bind this method ?should i add another button and attach this refresh button? but in that case it will refresh the whole page,which i want to avoid.

I am new to JSF so please bear with my limited knowledge if i didn't understand anything obvious here.

Anil Vishnoi
it would be great help if you can give me some pseudo code.
Anil Vishnoi