2

I have a <p:tabView> on my screen where one of the tabs(<p:tab>) has several <pe:inputNumber> with minValue attribute set to -9999999999.99. When I enter any value be it positive or negative and switch between the tabs, the input value resets to its initial value whereas for the inputs with no minValue set, it retains the entered value after switching between the tabs.

Is there attribute i am missing to set ? Or is there a workaround for the same?

Edit : I'm using primefaces 5.3 and primefaces-extensions 4.0.0. My code for tabs is as shown below :

<p:tabView id="sections" style="width:inherit;background-color: #F0F0F0;">
        <p:ajax event="tabChange" listener="#{tabbedViewManagedBean.onTabChange}" />
        <p:ajax event="tabClose" listener="#{tabbedViewManagedBean.onTabClose}" />

        <p:tab title="First Tab" id="firsttab">
            <ui:include src="firsttab.xhtml" />
        </p:tab>

        <p:tab title="Second Tab" id="secondtab">
            <ui:include src="secondtab.xhtml" />
        </p:tab>
 </p:tabView>

The tabbed view managed bean gets data for that tab when switching between the tabs. Each tab has its own session scoped managed beans.

The code for secondtab.xhtml is :

    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:c="http://java.sun.com/jstl/core"
        xmlns:p="http://primefaces.org/ui"
        xmlns:pe="http://primefaces.org/ui/extensions">

      <h:outputText value="Net Loss :" />
        <pe:inputNumber value="#{secondTabMB.netLoss}" 
           symbol="$ " minValue="-99999999999999.99" />

    </ui:composition>

Here's how my screen looks

Ashish
  • 117
  • 1
  • 13

2 Answers2

1

This may be helps:

<pe:inputNumber value="#{secondTabMB.netLoss}" 
       symbol="$ " minValue="-99999999999999.99">
    <p:ajax event="blur" global="false" />
</pe:inputNumber>
flyasky
  • 81
  • 4
0

I tried to recreate your problem with this code, but the code below works as expected. I can switch tabs without losing values:

bean

@ManagedBean
@ViewScoped
public class Test {

    private Double input1;
    private Double input2;

//Getters & Setters
}

html

<h:form>
    <p:tabView>
        <p:tab title="Input1">
            <h:outputText value="Net Loss :" />
            <div class="form-element-wrapper">
                <pe:inputNumber value="#{test.input1}" symbol="$ " >
                    <p:ajax process="@this"/>
                </pe:inputNumber>
            </div>

        </p:tab>
        <p:tab title="Input2">
            <h:outputText value="Net Loss :" />
            <div class="form-element-wrapper">
                <pe:inputNumber value="#{test.input2}" symbol="$ " minValue="-99999999999999.99" >
                    <p:ajax process="@this"/>
                </pe:inputNumber>
            </div>
        </p:tab>
    </p:tabView>
</h:form>

I added process="@this" just for doing an ajax submit on losing focus.

Can u provide the following code from your ajax request?:

<p:ajax event="tabChange" listener="#{tabbedViewManagedBean.onTabChange}" />
XiCoN JFS
  • 628
  • 3
  • 12
  • I have made a change to my code similar to what you mentioned but '' . But I think this is something prime faces has to look into as we are explicitly updating the component which is not a good practice. As I had to Ajax update most of the components in my tab while switching I need to either pre-load all the data in tabs when the screen is called or have a p:ajax as I stated. – Ashish Feb 13 '16 at 12:52
  • can u please provide the listener of `` and the Scope `tabbedViewManagedBean` is running in? the code above works even without ``, so `` doesn't solve your problem, it just covers a bad design of your view. – XiCoN JFS Feb 15 '16 at 10:43
  • Second thought: Why did u choose to set your managed beans for each tab in sessionscope? please read this article for better understanding scopes - [SO - How to choose the right bean scope?](http://stackoverflow.com/questions/7031885/how-to-choose-the-right-bean-scope) – XiCoN JFS Feb 15 '16 at 10:59
  • We are done with the project now so I don't have access to that code anymore. This issue had nothing to do with the scope as I even tried changing the scopes. And regarding the Ajax update not helping me is wrong as it is definitely working and I have tested it multiple times. – Ashish Feb 15 '16 at 16:33
  • I didn't say that it might not help your problem, but it definitely does not go to the root of your problem... nevermind, just wanted to help.... close this question plz – XiCoN JFS Feb 15 '16 at 16:52