a4j:commandButton does nothing on first click, works on second
sand.kamath Jan 20, 2013 7:34 PMI am using richfaces 4.3, JSF 2.2
My requirement is simple, once i login a page is displayed which consists of 2 panel only one of which is displayed initially.
On selecting some value from combo box when i click on button it should execute some statements. I have used action="#{myBeam.makeBDEntry}" for it.
Then it should render another panel which displays the values selected after some calculation. I have used render="out" for it.
I am new to JSF & richfaces..
is there something like onclick="document.getElementById(this).submit()" where i can render panel on click but after executing some statements(calculation).
in the below example i have combobox to select hours & mins and a button.
After clicking button
- The hours & mins are added to current time.
- Database entry is done.(I am doing it in makeBDEntry() of myBeam )
- The target time is displayed to user.
first time when I click nothing happens .works correctly from next time onwards...
Please help me with the code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j">
<h:body>
<h:form>
<div id="container">
<!--// header contains another a4j:commandButton for logout... //-->
<div id="content">
<rich:panel>
<h:panelGrid columns="2" columnClasses="mainPanelColumn">
<h:outputText value="Enter the Hours" />
<h:selectOneMenu value="#{myBeam.hours}">
<f:selectItem itemLabel="1 hour" itemValue="1" />
<f:selectItem itemLabel="2 hour" itemValue="2" />
<f:selectItem itemLabel="3 hour" itemValue="3" />
<f:selectItem itemLabel="4 hour" itemValue="4" />
<f:selectItem itemLabel="5 hour" itemValue="5" />
</h:selectOneMenu>
<h:outputText value="Enter the Minutes" />
<h:selectOneMenu value="#{myBeam.minutes}">
<f:selectItem itemLabel="00 min" itemValue="0" />
<f:selectItem itemLabel="15 min" itemValue="15" />
<f:selectItem itemLabel="30 min" itemValue="30" />
<f:selectItem itemLabel="45 min" itemValue="45" />
</h:selectOneMenu>
<br />
<a4j:commandButton value="Submit" action="#{myBeam.makeBDEntry}"
render="out" />
</h:panelGrid>
</rich:panel>
<br />
<a4j:outputPanel id="out">
<rich:panel rendered="#{not empty myBeam.entryTime and myBeam.checkFlag}">
<p>current time + (hours and minutes entered by user) is displayed as target time</p>
<h:panelGrid columns="2" rendered="#{not empty myBeam.entryTime and myBeam.checkFlag}" columnClasses="mainPanelColumn">
<h:outputText value="Target Time" columnClasses="mainPanelColumn" rendered="#{not empty myBeam.targetTime and myBeam.checkFlag}" />
<h:outputText value="#{myBeam.targetTime}" rendered="#{not empty myBeam.targetTime and myBeam.checkFlag}" />
</h:panelGrid>
</rich:panel>
</a4j:outputPanel>
</div>
</div>
</h:form>
</h:body>
</ui:composition>
-
before.png 42.0 KB
-
after.png 31.0 KB