allowTypes with composite

UI Components for JSF
Post Reply
User avatar
Mayco Lucian
Posts: 30
Joined: 12 Apr 2013, 16:30
Location: Brazil

17 Mar 2014, 15:18

Hi,

I wanted to pass a dynamic value in the file upload allowTypes, for example:

composite:

Code: Select all

<p:overlayPanel id="#{idUpArq}Panel" for="#{idUpArq}" hideEffect="fade">  
	<p:fileUpload  fileUploadListener="#{value}" mode="advanced" 
	       cancelLabel="#{personalizacaoBean.getLabelValue('upload.cancelar.label')}"
               uploadLabel="#{personalizacaoBean.getLabelValue('upload.enviar.label')}" 
		label="#{personalizacaoBean.getLabelValue('upload.procurar.label')}" 
                fileLimitMessage="#{personalizacaoBean.getMessageValue('mensagemQuantidadeArq')}"
					    invalidFileMessage="#{personalizacaoBean.getMessageValue('mensagemFormatoUpload')}" invalidSizeMessage="#{personalizacaoBean.getMessageValue('mensagemTamanhoArquivo')}" 
		sizeLimit="#{sizeUpload}" fileLimit="1" allowTypes="#{type}"/>
</p:overlayPanel>
and put on my screen like this:

Code: Select all

<tec:upload label="genEmpresa.logo.label" toolTipDelArq="genEmpresa.deletar.logo.toolTip" 
        idDelArq="delLogo"	toolTipUpArq="genEmpresa.upload.logo.toolTip" 
        idUpArq="enviarLogo"  type="/(\.|\/)(gif|jpe?g|png)$/"
        value="#{genEmpresaBean.handleFileUpload}" />
but doesn't work,
Does anyone know tell me why doesn't work?

PS: returns no error, tested by firebug.
Browsers: Firefox, IE 11, e Chrome
Mayco Lucian

Primefaces 5.3

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

17 Mar 2014, 15:38

does it work without composite?
Make you can also choose another attribute name - maybe "type" is a keyword or something.
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

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

17 Mar 2014, 18:19

You need to use #{cc.attrs.type} inside the composite to access the type attribute passed. The cc.attrs prefix is needed to ensure you get the attribute declared in the cc:interface section of the composite component.

Code: Select all

  <cc:interface ...>
    <cc:attribute name="type" type="java.lang.String" default="/(\.|\/)(gif|jpe?g|png)$/"/>
  </cc:interface>

  <cc:implementation ... >
   <p:overlayPanel id="#{idUpArq}Panel" for="#{idUpArq}" hideEffect="fade">  
   <p:fileUpload  fileUploadListener="#{value}" mode="advanced" 
          cancelLabel="#{personalizacaoBean.getLabelValue('upload.cancelar.label')}"
               uploadLabel="#{personalizacaoBean.getLabelValue('upload.enviar.label')}" 
      label="#{personalizacaoBean.getLabelValue('upload.procurar.label')}" 
                fileLimitMessage="#{personalizacaoBean.getMessageValue('mensagemQuantidadeArq')}"
                   invalidFileMessage="#{personalizacaoBean.getMessageValue('mensagemFormatoUpload')}" invalidSizeMessage="#{personalizacaoBean.getMessageValue('mensagemTamanhoArquivo')}" 
      sizeLimit="#{sizeUpload}" fileLimit="1" allowTypes="#{type}"/>
    </p:overlayPanel>
</cc:implementation>
The ellipses '...' indicate some details have been left out for brevity.
Note that ALL composite attributes have to be declared in the cc:interface section of the composite component and accessed using the cc.attrs.<attributeName> form in the implementation section. It is also advisable to use EL expressions for attribute values instead of raw strings for localization values as you have used.

I recommend you reading through a JSF tutorial about composite components, it will help you a lot more than we can here especially considering this is not a PrimeFaces related issue.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

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

17 Mar 2014, 18:25

andyba wrote:You need to use #{cc.attrs.type} inside the composite to access the type attribute passed. The cc.attrs prefix is needed to ensure you get the attribute declared in the cc:interface section of the composite component.
Good catch - completely overlooked :D
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

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

17 Mar 2014, 18:34

tandraschko wrote:
andyba wrote:You need to use #{cc.attrs.type} inside the composite to access the type attribute passed. The cc.attrs prefix is needed to ensure you get the attribute declared in the cc:interface section of the composite component.
Good catch - completely overlooked :D
I do try, I do try :)
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

User avatar
Mayco Lucian
Posts: 30
Joined: 12 Apr 2013, 16:30
Location: Brazil

17 Mar 2014, 19:36

Thanks for the help,
does it work without composite?
Make you can also choose another attribute name - maybe "type" is a keyword or something.
Attribute name, I'm actually using another name, and the problem continues.
if I pass validation on own taglib works, but I need to pass parameter because I want to do something that can be used for uploads of different formats.

Code: Select all

allowTypes="/(\.|\/)(gif|jpe?g|png)$/"
You need to use #{cc.attrs.type} inside the composite to access the type attribute passed. The cc.attrs prefix is needed to ensure you get the attribute declared in the cc:interface section of the composite component.
andyba -Sorry, I was doing before with composite and now I'm making use of a taglib, but I tested what you said with the composite and also doesn't work. The biggest problem is that there's no error, and doesn't work.
Mayco Lucian

Primefaces 5.3

codeturner
Posts: 4
Joined: 14 May 2013, 18:44
Location: Utah, USA

26 Aug 2014, 22:25

I ran into this same problem. The issue is that the escape char '\' gets processed within the parameter and removed, which in turn renders an invalid javascript regex.

To fix, you'll need to escape the backslashes when setting allowTypes with a parameter. For example, change the component default to:

Code: Select all

<cc:attribute name="type" type="java.lang.String" default="/(\\.|\\/)(gif|jpe?g|png)$/"/>
PrimeFaces 3.4 | Mojarra 2.1.6 | GlassFish 3.1.2.2

User avatar
Mayco Lucian
Posts: 30
Joined: 12 Apr 2013, 16:30
Location: Brazil

17 Mar 2015, 16:54

Thanks codeturner, it took for me to see you posted, but it worked.

Was doing otherwise, but I will take your.

Tanks, :D
Mayco Lucian

Primefaces 5.3

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 37 guests