New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PickList: String values are encoded on submit #4036

Closed
qnox opened this Issue Sep 11, 2018 · 10 comments

Comments

Projects
None yet
7 participants
@qnox
Copy link

qnox commented Sep 11, 2018

  1. Environment

2) Expected behavior

DualModel<String> containing strings with & is supposed to contain same string after submit

3) Actual behavior

DualModel<String> contains encoded strings with &amp; instead of & after submit

4) Steps to reproduce

Create picklist with DualModel<String> filled with strings with &

5) Sample XHTML

      <h:form>
        <p:pickList value="#{pickListModel.model}"
                    var="value"
                    itemLabel="#{value}"
                    itemValue="#{value}">
        </p:pickList>

        <p:commandButton value="Submit" action="#{pickListModel.post}" />
      </h:form>

6) Sample bean

package org.example;

import java.util.ArrayList;
import java.util.Collections;
import javax.el.MethodExpression;
import javax.faces.view.ViewScoped;
import org.primefaces.model.DualListModel;
import org.springframework.stereotype.Component;

@Component
@ViewScoped
public class PickListModel {

    private DualListModel<String> model;

    public PickListModel() {
        model = new DualListModel<>();
        model.setSource(new ArrayList<>(Collections.singletonList("&source&")));
        model.setTarget(new ArrayList<>(Collections.singletonList("&target&")));
    }

    public DualListModel<String> getModel() {
        return model;
    }

    public void setModel(DualListModel<String> model) {
        this.model = model;
    }

    public void post() {
        System.out.println(model.getTarget());
    }
}

@Rapster Rapster added the defect label Sep 12, 2018

@Rapster

This comment has been minimized.

Copy link
Member

Rapster commented Sep 12, 2018

It'd be great if you could analyse the problem and provide a PR 😉

@melloware

This comment has been minimized.

Copy link
Contributor

melloware commented Sep 15, 2018

There needs to be 2 things to fix this issue:

  1. A new property added to Picklist called "escape" like other components so you can say "escape=false" to turn off the HTML escaping.

  2. In picklist.js this line needs to check that "escape" property and choose whether or not to call PrimeFaces.escapeHTML.

escapedItemLabel = (itemLabel) ? PrimeFaces.escapeHTML(itemLabel) : ''

melloware added a commit to melloware/primefaces that referenced this issue Sep 17, 2018

melloware added a commit to melloware/primefaces that referenced this issue Sep 17, 2018

melloware added a commit to melloware/primefaces that referenced this issue Sep 18, 2018

@melloware

This comment has been minimized.

Copy link
Contributor

melloware commented Sep 18, 2018

You are right. I just checked in the fix.

melloware added a commit to melloware/primefaces that referenced this issue Sep 28, 2018

tandraschko added a commit that referenced this issue Sep 28, 2018

Merge pull request #4046 from melloware/PF4036
Fix #4036: Picklist add "escape" property.

@tandraschko tandraschko added this to the 6.3 milestone Sep 28, 2018

@tandraschko tandraschko added new feature and removed defect labels Sep 28, 2018

@orange-buffalo

This comment has been minimized.

Copy link
Contributor

orange-buffalo commented Oct 1, 2018

Thanks for the improvement, guys! Is it possible to port it to the 6.2? We have Elite subscription and need this functionality.

@tandraschko

This comment has been minimized.

Copy link
Member

tandraschko commented Oct 1, 2018

thats up to @mertsincan

@orange-buffalo

This comment has been minimized.

Copy link
Contributor

orange-buffalo commented Dec 18, 2018

@mertsincan, is it possible to include this into the 6.2.x releases?

@mertsincan mertsincan self-assigned this Dec 20, 2018

@mertsincan mertsincan added the 6.2.14 label Dec 20, 2018

@mertsincan mertsincan removed their assignment Dec 20, 2018

@mertsincan

This comment has been minimized.

Copy link
Member

mertsincan commented Dec 20, 2018

Thanks a lot for PR, @melloware ;)

@UlrichLohrmann

This comment has been minimized.

Copy link

UlrichLohrmann commented Jan 15, 2019

The change is not backward compatible. We create PickList instance using Java code and if escape property is not set a NullPointerException will occur.
A call to pickList.setEscape(...) is required after upgrading to Primefaces version 6.2.14.

@mertsincan

This comment has been minimized.

Copy link
Member

mertsincan commented Jan 15, 2019

Hi @UlrichLohrmann,
Fixed for 6.2.15. #4413

@UlrichLohrmann

This comment has been minimized.

Copy link

UlrichLohrmann commented Jan 15, 2019

Great, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment