1

I have commandButton component on my JSF page:

initial button

<p:commandButton id="period"
    value="#{myBean.isMonthly == false ? 'Yearly' : 'Monthly'}"
    action="#{myBean.doSomeOtherStuff()}"
    update="period myDataTable">
</p:commandButton>

I'm trying to update a dataTable upon a click on the button above. When I click it, the dataTable is updated as desired whereas the commandButton behaves weirdly, resulting in a display like:

button after update

Can someone help me understand the causes of such a weird situation and also tell a solution if possible?

NOTES:

  • JSF implementation and version: Mojarra (javax.faces-2.1.11.jar)
  • View technology: Facelets (XHTML)
  • Copy'n'paste'n'runnable example! (SSCCE) listed below:

FilterBean.java:

package com.turkcell.mdealer.bean.impl;

import org.springframework.stereotype.Component;

@Component
public class FilterBean {
    private boolean monthly = true;

    public String applyPeriod(String caller) {
        monthly = !monthly;
        return caller;
    }

    public boolean isMonthly() {
        return monthly;
    }

    public void setMonthly(boolean monthly) {
        this.monthly = monthly;
    }
}

sample.xhtml:

<f:view xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:turkcell="http://turkcell.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui"
    xmlns:of="http://omnifaces.org/functions"
    xmlns:pm="http://primefaces.org/mobile" contentType="text/html"
    renderKitId="PRIMEFACES_MOBILE">
    <pm:page title="Bayi Raporlari">
        <pm:view id="FaturasizAktivasyon" swatch="c">
            <p:outputPanel id="FaturasizPanel">
                <h:form id="FaturasizForm">
                    <pm:content>
                        <p:commandButton id="period"
                            value="#{filterBean.monthly == false ? 'Yearly' : 'Monthly'}"
                            action="#{filterBean.applyPeriod('sample')}" update="period">
                        </p:commandButton>
                    </pm:content>
                </h:form>
            </p:outputPanel>
        </pm:view>
    </pm:page>
</f:view>

General view of libraries:

enter image description here

Juvanis
  • 25,802
  • 5
  • 69
  • 87
  • 1
    I can't reproduce your problem with PF 3.5 and Mojarra 2.1.14. Which versions of Primefaces and JSF are you using? – partlov Mar 28 '13 at 08:08
  • @partlov I'm using _primefaces-3.5.jar_ and _javax.faces-2.1.11.jar_ – Juvanis Mar 28 '13 at 08:21
  • Is it possible to update Mojarra version and check if problem disappears? If not, than it is probably side effect of some other part of page. In that case post whole page source. – partlov Mar 28 '13 at 08:23
  • Additionally you can try to replace update of `period` by update of `@this`. If it doesn't help, possible workaround is to update naming container of this button. – partlov Mar 28 '13 at 09:03
  • is your button inside a datatable? What do you do in your backingbean method? Please share some code? – Kerem Baydoğan Mar 28 '13 at 09:28
  • @KeremBaydoğan hi Kerem, see my edit please. – Juvanis Mar 28 '13 at 09:35
  • An [SSCCE](http://stackoverflow.com/tags/jsf/info) would be helpful. – BalusC Mar 28 '13 at 10:34
  • This may not related, but just try, I use comma separate ids in update or maybe you need : add to it. I found this @BalusC [answer](http://stackoverflow.com/a/4474853/1692632). – Darka Mar 28 '13 at 11:09
  • @Darka: commaseparated IDs is leftover from PF 2.x; prefixing with naming container separator character is only mandatory if the target components are outside the form which doesn't seem to be the case. – BalusC Mar 28 '13 at 11:10
  • I know from your answer :) just guessed it. Guessing sometimes helps. – Darka Mar 28 '13 at 11:18
  • What if change myBean.isMonthly into String value? – Darka Mar 28 '13 at 11:19
  • As said, an [SSCCE](http://stackoverflow.com/tags/jsf/info) would be helpful. – BalusC Mar 28 '13 at 11:27
  • @BalusC what is missing in my post? I think I've given all required information. – Juvanis Mar 28 '13 at 11:31
  • Yes, we need more code, as someone here said, problem can be in some other part. – Darka Mar 28 '13 at 11:34
  • The code posted so far is not copy'n'paste'n'runnable without making changes and stubbing data ourselves. However, once we do that, we can't reproduce the problem. So your problem is caused elsewhere. That can only best be identified by creating an SSCCE which reproduces the problem for us (and yourself!) when copy'n'paste'n'running in a blank playground environment without making any non-obvious changes. – BalusC Mar 28 '13 at 11:43
  • @BalusC I've added whole source of the page. As in my first comment, I'm using _primefaces-3.5.jar_ and _javax.faces-2.1.11.jar_. Additionally, I'm using _primefaces-mobile-0.9.3.jar_ under WEB-INF/lib. So using mobile and non-mobile tags together might be causing such problems? – Juvanis Mar 28 '13 at 12:01
  • 1
    I'm sorry, but it seems that you failed to understand the point of SSCCE. Have you followed the "SSCCE" link in the previous comments for hints how to create a proper one? Imagine that you're us, trying to reproduce your problem. Create a blank playground project. Copypaste the "whole source" in there and run it. Does it run without errors and actually reproduce the problem? No? Please fix the "whole source" accordingly! Further, also please try to reduce code noise. For example, is the presence of those `` absolutely mandatory in order to still reproduce the problem? – BalusC Mar 28 '13 at 12:14
  • @BalusC Thanks for your help. I've read SSCCE. And I've tried to make a simple and concise example demonstrating my problem. I've created a mini project and reproduced the same error. Details are on my edit. – Juvanis Mar 28 '13 at 13:51
  • @Juvanis What a coincidence we are working in the same corporation :) You can reach me from internal communicator :) – Kerem Baydoğan Mar 28 '13 at 14:12
  • @KeremBaydoğan yes Kerem, I've just noticed that =) Expecting your helps.. – Juvanis Mar 28 '13 at 14:24
  • would be nice to know solution. – Darka Mar 28 '13 at 14:36

1 Answers1

1

I don't know the reason of the weird behaviour

However, you can use two conditionally rendered button to achieve the same effect:

<p:panelGroup>
    <p:commandButton value="Monthly"
        action="#{myBean.doSomeOtherStuff()}"
        update="myDataTable @parent" rendered="#{myBean.isMonthly}" />
    <p:commandButton value="Yearly"
        action="#{myBean.doSomeOtherStuff()}"
        update="myDataTable @parent" rendered="#{not myBean.isMonthly}" />
</p:panelGroup>
Juvanis
  • 25,802
  • 5
  • 69
  • 87
Kerem Baydoğan
  • 10,475
  • 1
  • 43
  • 50
  • Thanks a lot dear Kerem. This is the accepted answer till someone finds the reason of the nested buttons. – Juvanis Mar 28 '13 at 14:53