Pokazywanie postów oznaczonych etykietą primefaces. Pokaż wszystkie posty
Pokazywanie postów oznaczonych etykietą primefaces. Pokaż wszystkie posty

sobota, 13 lipca 2013

Icon for primefaces commandButton

I found placing my own icon in <p:commandButton> a little confusing. When I try to do this I got no icon at all, or strange mark looked like this:
When I've done a little research I found this:

I can have an icon in a three way:

#1. Button as a picture. There is no value/description visible. Only an icon/picture.
         <p:commandLink action="#{someBean.someAction()}">
            <h:graphicImage name="images/new_create.png" />
         </p:commandLink>


#2. Button with an icon/picture as a background. So one see a description like "New" and the picture of icon in background. 
<p:commandButton value="New!" styleClass="ui-back-but-new"/>
and respectively in css: 
.ui-back-but-new{
   background: url("#{resource['images/new_create.png']}") no-repeat top left !important;
}


#3. Button with an icon placed left to its description (value attrib).
<p:commandButton value="New" icon="ui-but-new-icon"/>
and respectively in css:
.ui-but-new-icon{
   background-image: url("#{resource['images/new_create.png']}") !important;
}


The problem was...:

All my problems came from wrong path to the icon image. It is probably the most frequent mistake. I have coded it as images/new_create.png in css statements. Structure of folders was /resources/images/new_create.png.

The proper path could be given in a three ways:
  • url("#{resource['images/new_create.png']}")
  • url(../resources/images/new_create.png) 
  • url(/MyAppName/resources/images/new_create.png) 
The first way is the best. It uses JSF resource identifier so it is most flexible. 

The effect #1, #2, #3:

wtorek, 20 grudnia 2011

PrimeFaces 3.0 name space

When You using NetBeans, it gives you PrimeFaces 2.2.1. When You try for example <p:selectOneMenu>, it appears, that namespace is not right.

Change it to: xmlns:p="http://primefaces.org/ui"
Of course: library itself shoud be loaded.

Explanation from primefaces.

wtorek, 20 września 2011

Przekazywanie wartości z primefaces dataTable

Aby przekazać wartości wybranego z tabeli wiersza, do na przykład formularza edycji wartości tego wiersza, wystarczy w przypadku dataTable primefaces skorzystać z zaleconego mechanizmu, np:

<p:dataTable var="car" value="#{carBean.cars}" selectionMode="single" selection="#{carBean.selectedCar}">
   
...columns
</p:dataTable>
carBean to oczywiście managed bean z właściwością/polem selectedCar, posiadającym właściwy get i set.

Wystarczy teraz umieścić przycisk wywołujący formularz, który odwoła się do pól/pola beanu carBean. np:
<p:commandButton value="Edit" action="/car/editCar"/>
Jednakże odwołanie na stronie editCar do pól beana carBean, zwrócić może niechybnie null, mimo, że dopiero co były ustawione na właściwe wartości.

Rozwiązanie tkwi w deklaracji zakresu beana, a ściślej w użytej do tej deklaracji bibliotece. Jeśli bean jest @SessionScoped, to należy użyć
import javax.enterprise.context.SessionScoped;
Natomiast użycie:
import javax.faces.bean.SessionScoped;
sprawi, że nie zobaczymy wcześniej ustawionych wartości.