p:commandButton not working or am I missing something

UI Components for JSF
grizli
Posts: 82
Joined: 11 Nov 2009, 16:36

19 Feb 2010, 17:03

I have a page with 2-3 text fields (h:inputtext)
below is a p:datatable.
I also have p:commandButton on the page which is set to update="txtfield1, txtfield2, txtfield3, myDatable"
What I'm trying to do is have a user input parameters in text fields and then click on p:commandButton
That way backing bean sets values for text fields, since they are defined as value="#{page.txtField1}" and etc
And then datatable gets refreshed with conditions specified in text fields.

The problem is - no matter which way I try - when p:commandButton is pressed, it always goes through updating datatable first before setting any text fields values.
Is this possible? Is this by design? Or it's not working properly?
Please help :)

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

23 Feb 2010, 16:12

I couldn't understand the page clearly, can you post the code?

grizli
Posts: 82
Joined: 11 Nov 2009, 16:36

23 Feb 2010, 21:19

The JSF page:

Code: Select all

<p:accordionPanel><p:tab title="Filters">
Filter Item One: <h:inputText id="FilterFieldOne" value="#{bean.firstFilter}" /><br />
Filter Item Two: <h:inputText id="FilterFieldTwo" value="#{bean.secondFilter}" /><br />
<p:commandButton id="FltBtn" value="Filter" process="FilterFieldOne, FilterFieldTwo" update="myTable" />
</p:tab></p:accordionPanel>
<p:dataTable id="myTable" var="data" value="#{bean.myList}" paginator="true" rows="50" scrollable="true" height="500" width="100%" dynamic="true" widgetVar="cMyTable">
                <p:column id="FirstColumn" sortBy="#{data.firstDataItem}" resizable="true">
                    <f:facet name="header">
                        <h:outputText value="First Column" />
                    </f:facet>
                    <h:outputText value="#{data.firstDataItem}" />
                </p:column>
                <p:column id="SecondColumn" sortBy="#{data.secondDataItem}" resizable="true">
                    <f:facet name="header">
                        <h:outputText value="Second Column" />
                    </f:facet>
                    <h:outputText value="#{data.secondDataItem}" />
                </p:column>
                <p:column id="ThirdColumn" sortBy="#{data.thirdDataItem}" resizable="true">
                    <f:facet name="header">
                        <h:outputText value="Third Column" />
                    </f:facet>
                    <h:outputText value="#{data.thirdDataItem}" />
                </p:column>
</p:dataTable>
Backing bean:

Code: Select all

...
...definitions, getters and setters for firstFilter and secondFilter here...
private List<EachDataItem> myList;
public List<EachDataItem> getmyList() {
        if (myList == null) { myList = new ArrayList(); LoadList(); }
        return myList;
    }
private void LoadList() {
        String SqlStr = "SELECT blabla... FROM blabla WHERE bla1 = '" + getfirstFilter() + "' AND bla2 = '" + getsecondFilter() + "';
        ResultSet rs = SomeClass.getDataSet(SqlStr, false);
        while (rs.next()) { this.myList.add(new EachDataItem(blablablablabla)); }
        SomeClass.CloseSqlConnection();
}
All the blablas - I did not include since it's not very relevant :)
I hope this helps :)
Last edited by grizli on 23 Feb 2010, 22:50, edited 1 time in total.

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

23 Feb 2010, 22:07

Hello grizli,

I didn't understand why you need an update of input fiels. You have to let pass them through JSF lyfecycle. The following code should work

<p:commandButton value="Filter" process="FilterFieldOne, FilterFieldTwo" update="myTable" />

Or better

<p:commandButton value="Filter" process="FilterFieldOne, FilterFieldTwo" update="myTable" action="bean.doActionForDataTable"/>

bean.doActionForDataTable reads values from bean.firstFilter / bean.secondFilter and does something with list.

Best regards.
- Oleg.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

grizli
Posts: 82
Joined: 11 Nov 2009, 16:36

23 Feb 2010, 22:52

Thank you Oleg,
I changed the update and included process for Filter Fields.
The values now return to the bean properly and getter calls LoadList() which reads the Filter values and re-populates the myList.
For some reason, however, datatable itself did not update on the screen. :)

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

24 Feb 2010, 10:04

I think, I forgot @this in process. Try this

<p:commandButton value="Filter" process="@this, FilterFieldOne, FilterFieldTwo" update="myTable" action="bean.doActionForDataTable"/>
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

grizli
Posts: 82
Joined: 11 Nov 2009, 16:36

24 Feb 2010, 21:25

Thanks again Oleg,
I've tried that as well - no avail. Debuggers shows everything is working properly within the backing bean, but datatable is not getting updated client-side.
Would my environment cause any problems?
I'm running on Glassfish 2.1 + JSF 1.2

grizli
Posts: 82
Joined: 11 Nov 2009, 16:36

24 Feb 2010, 21:45

I opened up Error Console in FF to see what happens when CommandButton is pressed.
Error Console writes this:
Error: mismatched tag. Expected: </output>.
Source File: http://localhost:8080/TestApp/faces/index.jsp
Line: 15, Column: 3
Source Code:
</script><div><div></div><input /></div>]]></output></component></components><state><![CDATA[<input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="very long value here....

grizli
Posts: 82
Joined: 11 Nov 2009, 16:36

25 Feb 2010, 16:54

Is there a bug with javascript call that suppose to refresh the datatable?

grizli
Posts: 82
Joined: 11 Nov 2009, 16:36

01 Mar 2010, 14:34

Cagatay, is there a way anyone could look into this? It's critical for the application I'm working on and basically is a show-stopper.
I would imagine, with time, more people will have such filtering approach with datatable (after all, it's already being done with IceFaces) and will run into the same problem.
As I mentioned above - according to debugger everything is working properly. Action in the backing bean re-populates the ArrayList datatable value is binded to, but table simply does not change on the screen.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 50 guests