How to pass int or Integer parameter in <pe:remoteCommand>

Community Driven Extensions Project
Post Reply
schlebe
Posts: 212
Joined: 25 Sep 2015, 13:32
Location: Colmar-Berg (Luxembourg)

03 Jan 2017, 09:11

Hello,

recently I will use <pe:remoteCommand> to pass 2 parameters: 1 String and 1 int or Integer

The xhtml code I use FIRST is

Code: Select all

<pe:remoteCommand   
    name="updateFilterCounter"
    process="@this" 
    actionListener="#{alignmentManagerController.updateFilterCounter}" 
    > 
    <pe:methodSignature parameters="java.lang.String, java.lang.Integer"/>  
    <pe:methodParam name="name"/>  
    <pe:methodParam name="counter"/>  
</pe:remoteCommand>
and Javascript code that activate this widget is

Code: Select all

<script language='javascript'>

function afterFilter(oItem)
    {
    ...
    var sWidgetVarName = "ColorNameWidget";
    var oWidgetVar = PF(sWidgetVarName);    
                    
    var iCounter = oWidgetVar.inputs.filter(':checked').length;
    updateFilterCounter(sWidgetVarName,iCounter);
    }

</script>
The code of the function called on server is

Code: Select all

public void updateFilterCounter(String name, Integer counter)
    {
    if (false);
    else if (name.equals("RegulationFilter"))
        {
        iRegulationFilterNrChecked = counter;
        }
When I use these codes, Web Application crash because there is mismatch for passing iCounter variable !

Since I found no solution; I have replaced Integer type by String type.

The new code is

Code: Select all

<pe:remoteCommand   
    name="updateFilterCounter"
    process="@this" 
    actionListener="#{alignmentManagerController.updateFilterCounter}" 
    > 
    <pe:methodSignature parameters="java.lang.String, java.lang.String"/>  
    <pe:methodParam name="name"/>  
    <pe:methodParam name="counter"/>  
</pe:remoteCommand>
and Javascript code that activate this widget is

Code: Select all

<script language='javascript'>

function afterFilter(oItem)
    {
    ...
    var sWidgetVarName = "ColorNameWidget";
    var oWidgetVar = PF(sWidgetVarName);    
                    
    var iCounter = oWidgetVar.inputs.filter(':checked').length;
    updateFilterCounter(sWidgetVarName,iCounter.toString());
    }

</script>
The code of the function called on server is

Code: Select all

public void updateFilterCounter(String name, String counter)
    {
    int iCounter = Integer.parseInt(counter);
        
    if (false);
    else if (name.equals("RegulationFilter"))
        {
        iRegulationFilterNrChecked = iCounter;
        }
This work but is not very beautiful :|

My question is: How to pass Integer parameter in <pe:remoteCommand> ?
PrimeFaces 6.2.4
Mojarra 2.2.13
Glassfish 4.1

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

03 Jan 2017, 11:27

I already answered your in the other thread that it's possible to attach converters and that you should try it :P
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

schlebe
Posts: 212
Joined: 25 Sep 2015, 13:32
Location: Colmar-Berg (Luxembourg)

03 Jan 2017, 14:12

@tandraschko

first of all, best whish for 2017 :-)

For this problem, it is true that you propose to use a converter to pass an Integer but I have already a solution in passing a String !!!

I have posted this isssue

1. to communicate a problem
2. to verify if a simple solution to this problem already exist because my code is incorrect

but NOT to find another workaround to my problem !

Passing an integer in converting it to String or to another type is a workaround !

I think that if nothing is done to correct it, I'm not the last to encounter this problem.
PrimeFaces 6.2.4
Mojarra 2.2.13
Glassfish 4.1

schlebe
Posts: 212
Joined: 25 Sep 2015, 13:32
Location: Colmar-Berg (Luxembourg)

03 Jan 2017, 14:18

For those who read this post, I have implemented the workaround proposed by tandraschko and this work correclty.

I have used a standard JSF converter and not a custom converter like done in <pe:remoteCommand> example.

The HTML code is ...

Code: Select all

<pe:remoteCommand   
    name="updateFilterCounter"
    process="@this" 
    actionListener="#{alignmentManagerController.updateFilterCounter}" 
    > 
    <pe:methodSignature parameters="java.lang.String, java.lang.Number"/>  
    <pe:methodParam name="sName"/>  
    <pe:methodParam name="nCounter">  
        <f:convertNumber integerOnly="true"/>
    </pe:methodParam>  
</pe:remoteCommand>  
and the Java Controller code is ...

Code: Select all

    public void updateFilterCounter(String sName, Number nCounter)
        {
        int iCounter = nCounter.intValue();
        
        if (false);
        else if (sName.equals("RegulationFilter"))
            {
            iRegulationFilterNrChecked = iCounter;
            }
        }
PrimeFaces 6.2.4
Mojarra 2.2.13
Glassfish 4.1

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

03 Jan 2017, 14:45

Happy new year ;)

I don't think thats an workaround.
It's maybe just a missing feature to automatically "lookup" an converter.
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

Post Reply

Return to “Extensions”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests