Showing posts with label PrimeFaces. Show all posts
Showing posts with label PrimeFaces. Show all posts

Friday, 24 February 2012

JSF: Changes made to submitted value by the Managed Bean are not rendered after ajax call and using immediate="true"

The goal and problem

In a facet form I have a value. When I click the commandButton it calls an action on the Managed Bean which changes the submitted value. The updated value should be rendered on the view...but it doesn't! Note that I use immediate="true" to skip the validation phase (because validation error may be shown).
[Actually what I want to do is render some numerical values and randomize them each time I click the commandButton] Managed Bean Foo.java:
public void submit() {
   this.val = 3; //the new value
}
Facelet:
<h:form>
<p:inputText value="#{fooBean.val}"></p:inputText>

<p:commandButton value="Submit"
  action="#{fooBean.submit()}" 
  update="@form"
  immediate="true" />
</h:form>

The solution

Skipping validation doesn't mean that the input value is not submitted!! In the Managed Bean I change the value foobean.val and indeed changes but the component p:inputText preserves the old value because its attribute submittedValue is the old one. The solution is to use the attribute process="@this" because this way we don't submit the value!. The correct Facelet is the following:
<h:form>
<p:inputText value="#{fooBean.val}"></p:inputText>

<p:commandButton value="Submit"
  action="#{fooBean.submit()}" 
  update="@form"
  immediate="true"
  process="@this" />
</h:form>

Thursday, 16 February 2012

PrimeFaces: How to style (css) a menu in an accordionPanel

Tested with PrimeFaces 3.1

Before (with default css)

<p:accordionPanel>  
 <p:tab title="Foo tab title">  
  <p:menu>  
    <p:menuitem value="Foo menu item title" url="#" />
  </p:menu>
  </p:tab>
</p:accordionPanel>
Result:

After (with overriden css)

Just add the class "accordionMenu" to the accordionPanel:
<p:accordionPanel styleClass="accordionMenu">  
 <p:tab title="Foo tab title">  
  <p:menu>  
    <p:menuitem value="Foo menu item title" url="#" />
  </p:menu>
  </p:tab>
</p:accordionPanel>
.accordionMenu .ui-menu {
 width:100% !important; 
 
}
.accordionMenu .ui-accordion-content {
 padding:0 !important;
 overflow:inherit !important;
}

.accordionMenu .ui-helper-clearfix:after {
 height:inherit !important;
}
Result:

Monday, 13 February 2012

PrimeFaces: Many problems with p:editor...it is not displayed right!

How is <p:editor> rendered (initialized)?:

The PrimeFaces <p:editor widgetVar="myeditor"> in order it is rendered right it calls the javascript function myeditor.init().

Common problems:

When we place the editor in a Tab, Accordion, etc it may not be initialized right (why is init() not called?). Moreover when we submit a form with ajax the editor may also not be rendered right.

Solutions proposed (that have worked for me...):

Editor in a tab:

If the editor is in a tab then make the tab dynamic (<p:tabView dynamic="true">).

Another solution that may work for you is initializing the editor when you change the tab:
<p:ajax event="tabChange" oncomplete="myeditor.init()"></p:ajax>

References

Friday, 27 January 2012

PrimeFaces:Dashboard: When a dashboard remains without any panels it is deleted

Solution: add in css the following:
<style type="text/css">
.ui-dashboard-column {
  width: 400px;
}
</style>

Thursday, 19 January 2012

Primefaces <p:button> java.lang.NullPointerException

Exception
java.lang.NullPointerException
 at org.primefaces.component.button.ButtonRenderer.buildOnclick(ButtonRenderer.java:128)
 at org.primefaces.component.button.ButtonRenderer.encodeMarkup(ButtonRenderer.java:59)
Solution:<p:button> points to an invalid link..

Monday, 19 December 2011

PrimeFaces: WARNING: Target model Type is no a Collection or Array

WARNING: Target model Type is no a Collection or Array
javax.faces.FacesException: Target model Type is no a Collection or Array
 at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValuesForModel(MenuRenderer.java:392)
 at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValue(MenuRenderer.java:129)

Solution: should have used p:selectOneRadio (accepts only one selection) instead of p:selectManyCheckbox (accepts one or more selections)

Friday, 16 December 2011

PrimeFaces p:button vs HTML button (or: why does p:button re-GETs the page?)

// NOT GET; NOT POST
<button onclick="foo()">My button</button>

function updateAllCells() {
 ...
 //returns nothing
}
//CAUSES GET; page is redisplayed
<p:button onclick="foo();" value="My button" />
// NOT GET; NOT POST
<p:button onclick="foo();return false;" value="My button" />

Thursday, 15 December 2011

PrimeFaces: showing p:dialog problem

Problem description:
If you name the p:dialog 'status' the dialog will not be showed.


Code example(doesn't work):
Show the dialog... <p:dialog widgetvar="status"> ... </p:dialog>

 Solution: do not give the widgetVar the name 'status' (is it reserved by javascript??)

Code example(works):
<p:dialog widgetvar="sth_not_status"> ... </p:dialog>

PrimeFaces: localize components Calendar and Schedule

http://wiki.primefaces.org/display/Components/PrimeFaces+Locales

PrimeFaces error: "java.lang.IllegalArgumentException: Setter not found for property class"

Actually my problem was the same as on http://duckranger.com/2010/05/facelets-setter-not-found-for-property-class/. I.e. I used class instead of styleClass!

Tuesday, 13 December 2011

JSF+PrimeFaces: how to download Excel (with actionListener)

public void exportExcelActionListener(ActionEvent event) {
  try {
    String filename = "myexceltodownload.xls";
         
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    externalContext.setResponseContentType("application/vnd.ms-excel");
      
    // http://stackoverflow.com/questions/3592058/how-to-send-byte-as-pdf-to-browser-in-java-web-application
    // attachment (pops up a "Save As" dialogue) or inline (let the web browser handle the display itself)
    externalContext.setResponseHeader("Content-Disposition", "attachment; filename=\""+filename+"\"");
 
    getWorkbook().write(externalContext.getResponseOutputStream()); //get workbook
    facesContext.responseComplete(); //if I don't call responseComplete() => IllegalStateException
      
    return null; //remain on same page
  } catch(Exception e) {
    // handle exception...
    return null; //remain on same page
   }
}

  
    
  

Note: To experiment with the download commandbutton of primefaces...
Note: Strangely didn't work for me....

Tuesday, 29 November 2011

How to nest forms in Tabs if a Tab is conditionally disabled/rendered

If a tab is conditionally disabled or rendered then the solution proposed on PrimeFaces: How to nest a form in each Tab (hint: this is a lie) won't work. To be more concrete the following will not work:

  
    
      ...
    
    
       ... 
    
  

or

  
    
      ...
    
    
       ... 
    
  

Soluton

For the moment I have removed disabled/rendered on tabs (I have moved it in the nested h:PanelGrid and p:CommandButton) of the Tab and it seems to work... i.e. getObject() of the Converter is called!

Update on 15 Dec 2011:Should try with

PrimeFaces: How to nest a form in each Tab (hint: this is a lie)

1st attempt (failure)


  
    
    ...
    
  
  
    
       ... 
    
  

Error:Method getAsObject() of Converter myconverter is not executed

2nd attempt (failure)


  
    
      ...
    
    
       
         
            ... 
         
       
    
  

Error:Again the same.

3rd attempt (success)

Note:TabView must be enclosed in a (see 1, 2)

  
    
      ...
    
    
       ... 
    
  

Error:Again the same.

PrimeFaces:datatable: set size of column

<p:dataTable id="footable" ...>
...
</p:dataTable>

/* Make 1st column equal to 20px */
.fooTable td:nth-child(1) {
  width: 20px;
}

Sunday, 27 November 2011

PrimeFaces Carousel render problems

Solution

tabView with activeIndex bound on request parameter causes javax.el.PropertyNotWritableException


Attempt #1 (failure)




Attempt #2 (success)


public class MyBean implements Seriializable {

private Integer tabIndex;
public Integer getTabIndex() { return tabIndex; }
public void setTabIndex(Integer tabIndex) { this.tabIndex = tabIndex; }