problem with p:outputpanel and rendered

UI Components for JSF
jadsonb
Posts: 32
Joined: 01 Jul 2010, 22:03

15 Feb 2011, 15:11

Hello again,

i am using p:outputpanel to "control" the visibility of an p:datatable.

it works great, unless i want to show a modal panel, it kinda break the modal panel and dont update the "selectedCar".

Code: Select all

<p:outputPanel rendered="#{myBean.rendered}" >

           <p:dataTable var="car" value="#{tableBean.cars}" paginator="true" rows="10">  
           ...
         <p:column>  
            <f:facet name="header">  
                <h:outputText value="Color" />  
            </f:facet>  
            <h:outputText value="#{car.color}" />  
        </p:column>  
  
         <p:column>  
            <p:commandButton update="display" oncomplete="carDialog.show()"  
                    image="ui-icon ui-icon-search">  
                <f:setPropertyActionListener value="#{car}"  
                    target="#{tableBean.selectedCar}" />  
            </p:commandButton>  
        </p:column>
        </p:dataTable> 
</p:outputPanel>
and my dialog box

Code: Select all

  <p:dialog header="Car Detail" widgetVar="carDialog" resizable="false"  
              width="200" showEffect="explode" hideEffect="explode">  
  
        <h:panelGrid id="display" columns="2" cellpadding="4">  
  
            <f:facet name="header">  
                <p:graphicImage value="/images/cars/#{tableBean.selectedCar.manufacturer}.jpg"/>  
            </f:facet>  
  
            <h:outputText value="Model:" />  
            <h:outputText value="#{tableBean.selectedCar.model}" />  
  
            <h:outputText value="Year:" />  
            <h:outputText value="#{tableBean.selectedCar.year}" />  
  
            <h:outputText value="Manufacturer:" />  
            <h:outputText value="#{tableBean.selectedCar.manufacturer}" />  
  
            <h:outputText value="Color:" />  
            <h:outputText value="#{tableBean.selectedCar.color}" />  
        </h:panelGrid>  
    </p:dialog>  
seems the

Code: Select all

               <f:setPropertyActionListener value="#{car}"  
                    target="#{tableBean.selectedCar}" />  
isnt updating, passing null parameters ( if i remove the rendered = "...", it works like a charm ).

anyone has a similar problem or know how to solve it?
PrimeFaces 3.0.M2, Mojarra 2.1.2, Tomcat 6.0.26/7.0.8, Eclipse, IE 8

fiktion
Posts: 100
Joined: 25 Aug 2010, 17:47

15 Feb 2011, 15:30

I am confused by your code. You talk about a modal panel but I don't see a modal anywhere set to true in your dialog. Where is the dialog? In the same view as the datatable? Also what is myBean.rendered? Is that either true or false? Null? If you could place some of your backing bean code in there so we can see what you are trying to do

jadsonb
Posts: 32
Joined: 01 Jul 2010, 22:03

15 Feb 2011, 15:52

forget about modal, was a typo.. i mean, dialog.

the mybean.rendered starts with false, then after page submit (and return to the same page ) it receives true.

basically, the "effects" of rendered works oks. cause when i first view page, its invisible the h:datatable,..

after submiting with the data i want, the h:datatable is visible, and working perfect all the stuff.


when the mybean.rendered isnt there on the rendered of p:outputpanel, the dialog works fine, the value is passed and it shows on the dialog the data.
when there is the rendered atribute, the dialogs appears but with the data null.
PrimeFaces 3.0.M2, Mojarra 2.1.2, Tomcat 6.0.26/7.0.8, Eclipse, IE 8

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

15 Feb 2011, 15:59

What is the scope of your mybean?

jadsonb
Posts: 32
Joined: 01 Jul 2010, 22:03

15 Feb 2011, 17:01

scope is session.
PrimeFaces 3.0.M2, Mojarra 2.1.2, Tomcat 6.0.26/7.0.8, Eclipse, IE 8

fiktion
Posts: 100
Joined: 25 Aug 2010, 17:47

15 Feb 2011, 17:17

You really need to show your backing bean code, All you have here is view code. I have no idea how you are setting your rendered variable and many other things. Please show some of your backing bean code so we can at least see what is going on.

jadsonb
Posts: 32
Joined: 01 Jul 2010, 22:03

15 Feb 2011, 17:48

ok, basically before the p:outputpanel, i have a p:graphicimage ( jfreechart ) working perfectly.

Code: Select all

<p:outputPanel id="tempz"  rendered="#{myBean.rendered}" >
				<p:graphicImage value="#{myBean.chartImage}" usemap="#imgMap" style="align:center; border: none;" >
					<h:outputText id="outMap4" escape="false"  value="#{myBean.mapCode}" />
				</p:graphicImage>
</p:outputPanel>
here is the mybean.

mybean

Code: Select all

...
        private boolean rendered;
	public void setRendered(boolean rendered) {
		this.rendered = rendered;
	}
	public boolean isRendered() {		
		return rendered;
	}
..
   private String mapCode;  
   public String getMapCode() {

  try{
     ....
     ChartUtilities.writeChartAsPNG(outputStream,chart,larg,alt, info);  
     pw = null;
     pw = new PrintWriter(outputStream);
     mapCode = CustomImageMapUtilities.writeImageMap(pw, "imgMap", info, true);	            
     pw.close();
     outputStream.close();
     rendered = true;
   }catch(Exception e){
   ....
       System.out.println("e+"+e.getMessage());
       rendered = false;
   }
   return mapCode;
}
i supressed some stuff, cause this are the only ones that are with the attribute rendered.
PrimeFaces 3.0.M2, Mojarra 2.1.2, Tomcat 6.0.26/7.0.8, Eclipse, IE 8

fiktion
Posts: 100
Joined: 25 Aug 2010, 17:47

15 Feb 2011, 19:00

Please post your command button code that is doing that actual submit. The one that has the call to "getMapCode();"

From what you have submitted I can already see one issue; You should not have any logic in your getter method. The getter method should just return the string variable mapCode as the setter method should only set the map code like this.

Code: Select all

public String getMapCode() {
       return mapCode;
}

public void setMapCode(String mapCode) {
       this.mapCode = mapCode;
}
You should then have a method that will populate the mapCode varaible that can be called on an actionListener attribute like so.

Code: Select all

public void populateMapCode() {
    String code = "";
    try{
         ....
         ChartUtilities.writeChartAsPNG(outputStream,chart,larg,alt, info); 
         pw = null;
         pw = new PrintWriter(outputStream);
         code = CustomImageMapUtilities.writeImageMap(pw, "imgMap", info, true);              
         pw.close();
         outputStream.close();
         this.setRendered(true);
   } catch(Exception e){
       ....
       System.out.println("e+"+e.getMessage());
       this.setRendered(false);
   }
   return code;
}
For readability sake it might be a good idea to create a isRendered method to get the rednered boolean val instead of just directly accessing the variable like so..

Edit** you already have this sorry I didn't see this in your code.**

Code: Select all

public boolean isRendered() {
     return this.rendered;
}
Then you could this as your rendered code

Code: Select all

<p:outputPanel id="tempz"  rendered="#{myBean.isRendered}" >
Your commandButton should look something like this

Code: Select all

<p:commandButton actionListener="#{myBean.populateMapCode()" update="YourView" />
This way your mapCode() is populated before the view is rendered and therefore the rendered boolean value should be set. I hope this helps.

jadsonb
Posts: 32
Joined: 01 Jul 2010, 22:03

15 Feb 2011, 19:28

just one thing i didnt understand:

Code: Select all

<p:commandButton actionListener="#{myBean.populateMapCode()" update="YourView" />
updating "YourView"?

the other stuff u said, i am changing it to the way you post.
PrimeFaces 3.0.M2, Mojarra 2.1.2, Tomcat 6.0.26/7.0.8, Eclipse, IE 8

fiktion
Posts: 100
Joined: 25 Aug 2010, 17:47

15 Feb 2011, 19:33

sorry it should be

Code: Select all

<p:commandButton actionListener="#{myBean.populateMapCode()" update="tempz" />
if we are going off of your example

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 45 guests