While using reRender, rendered object will not update without a page refresh - jsf

I have a h:selectonemenu that is populated by a list. When a specific value is selected, a h:datatable should be rendered. When I select that "specific" value, the h:datatable does not render until I refresh the page. What am I doing wrong?
<tr class="portlet-table-body" >
<td width="20%" class="porlet-padding-left"><h:outputText value="${operatorProgramBundle.NextGenerationWorkflow}" /></td>
<td width="450px">
<h:selectOneMenu id="ngw" styleClass="portlet-dropdown" value="${CRUDOperatorProgram.selectedNextGenWorkflow}">
<f:selectItems value="${CRUDOperatorProgram.nextGenWorkflowList}" />
<a4j:support event="onchange" ajaxsingle = "true" reRender="customTable" ></a4j:support>
</h:selectOneMenu>
</td>
</tr>
<h:panelGroup id="customTable">
<h:dataTable id="DispatchConfigurationCustom" columnClasses="portlet-table-same portlet-table-cell"
headerClass="portlet-table-same portlet-table-cell" value="#{CRUDOperatorProgram.workflowConfigList}" var="workflowConfig" width="100%" rendered="#{CRUDOperatorProgram.selectedNextGenWorkflow == 0}">
<h:column>
<f:facet name="header">
<h:outputText value="Include" />
</f:facet>
<h:selectBooleanCheckbox id="includeInd" value="#{workflowConfig.isIncludedInd}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Automate" />
</f:facet>
<h:selectOneRadio id="onOff" value="#{workflowConfig.isAutomatedInd}">
<f:selectItem id="onButton" itemLabel="On" itemValue="0" />
<f:selectItem id="offButton" itemLabel="Off" itemValue="0" />
</h:selectOneRadio>
</h:column>
</h:dataTable>
</h:panelGroup>
Updated Code:
<tr class="portlet-table-body" >
<td width="20%" class="porlet-padding-left"><h:outputText value="${operatorProgramBundle.NextGenerationWorkflow}" /></td>
<td width="450px">
<h:selectOneMenu id="ngw" styleClass="portlet-dropdown" value="#{CRUDOperatorProgram.selectedNextGenWorkflow}" valueChangeListener="#{CRUDOperatorProgram.nextGenWorkflowChanged}">
<f:selectItems value="#{CRUDOperatorProgram.nextGenWorkflowList}" />
<a4j:support event="onchange" reRender="customTable"></a4j:support>
</h:selectOneMenu>
</td>
</tr>
<h:panelGroup id="customTable">
<h:dataTable id="DispatchConfigurationCustom" columnClasses="portlet-table-same portlet-table-cell"
headerClass="portlet-table-same portlet-table-cell" value="#{CRUDOperatorProgram.workflowConfigList}" var="workflowConfig" width="100%">
<h:column>
<f:facet name="header">
<h:outputText value="Include" />
</f:facet>
<h:selectBooleanCheckbox id="includeInd" value="#{workflowConfig.isIncludedInd}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Automate" />
</f:facet>
<h:selectOneRadio id="onOff" value="#{workflowConfig.isAutomatedInd}">
<f:selectItem id="onButton" itemLabel="On" itemValue="0" />
<f:selectItem id="offButton" itemLabel="Off" itemValue="0" />
</h:selectOneRadio>
</h:column>
</h:dataTable>
</h:panelGroup>
Back Bean (Relevant parts) ...
private List<WorkflowConfig> workflowConfigList = new ArrayList<WorkflowConfig>();
private List<SelectItem> nextGenWorkflowList;
public void nextGenWorkflowChanged(ValueChangeEvent event) {
workflowConfigList.clear();
//the value is a long, so make it a string and check
if(event.getNewValue() != null && event.getNewValue().toString().equals("0")){
loadWorkFlowConfigs();
}else{
//Do not show the datatable
workflowConfigList.clear();
}
}
public List<WorkflowConfig> getWorkflowConfigList(){
return this.workflowConfigList;
}
private void loadWorkFlowConfigs() {
Query query = em.createNamedQuery("findAllWorkflowSteps");
List<WorkflowStep> step = (List<WorkflowStep>) query.getResultList();
for(WorkflowStep workflowStep : step){
WorkflowConfig workflowConfig = new WorkflowConfig();
workflowConfig.setWorkflowStep( workflowStep );
workflowConfigList.add(workflowConfig);
}
}
I implemented a valueChangeListener like you said. I tried this example (with the h:panelGroup) and the example without a h:panelGroup explained in the documentation. Each require a page refresh... Can you see anything I'm doing wrong?

Change the behavior of the <a4j:support> component by adding adding the action=#{someBean.someMethod} tag attribute or add a valueChangeListener in your <h:selectOneMenu>. IMO, I preffer to add a valueChangeListener. See the example in the official documentation.
As a side note, why you use ${...} instead of #{...}?

Related

Display Dynamic Checkbox in <rich:datatable and based on user selection rendered TextArea for current Object

Hi I am attaching my code, My problem i si am getting a list from the database and i am dispalying on the UI in a datatable with only checkbox.
Once user will select any of the check box then i need to renderedd on text area for that checkbox. So checkbox and textarea will be dynamic.
I have written some code in bean also but that is not working for first object it is working fine but for remaining object it is not workinhg please help to resolve problem
Bean Code:
public void addSharedMessage()
{
for(DocumentTypeDTO documentTypeDTO1 : shareGovtAgencyList)
{
System.out.println(documentTypeDTO1.getSelected());
if( documentTypeDTO1.getSelected())
{
this.setSharedMessageRendered(true);
setSharedMessageRendered(true);
} else {
this.setSharedMessageRendered(false);
}
}
}
XHTML code:
<rich:dataTable width="100%" id="searchResult" border="0" rowKeyVar="
value="#{myBean.sharedList}" var="item"
headerClass="head" cellpadding="2"
rowClasses="odd,even" cellspacing="0" bgcolor="#FFFFFF">
<rich:column style="text-align:center; background-color:#FFFFFF" width="1%">
<h:selectBooleanCheckbox id="khudh" value="#{item.selected}" immediate="true" >
<a4j:support event="onchange" action="#{myeBean.addSharedMessage}" reRender="committeemenbersname" />
</h:selectBooleanCheckbox>
</rich:column>
<rich:column style="background-color:#FFFFFF" id="committeemenbersname" >
<h:outputText value="#{item.documentName}" />
<rich:separator lineType="none" />
<h:inputTextarea id="shareProfileComment" rows="2" cols="45"
rendered="#{myBean.isSharedMessageRendered}" >
<f:validateLength maximum="200" />
</h:inputTextarea>
</rich:column>
</rich:dataTable>
Don't iterate all the values every time. you did any one value is true, and all the remaining should be false. I think this is the problem.
Try this,
public String addSharedMessageAction()
{
DocumentTypeDTO documentTypeDTO1 = shareGovtAgencyList.get(dataTableIndex);
System.out.println(documentTypeDTO1.getSelected());
if (documentTypeDTO1.isSelected())
{
documentTypeDTO1.setSharedMessageRendered(true);
}
else
{
documentTypeDTO1.setSharedMessageRendered(false);
}
return null;
}
XHTML code:
<rich:dataTable id="dataTableID"
value="#{Sample.sampleList}"
rendered="#{Sample.sampleDataTableRendered}"
var="sampleBean"
width="600"
rowKeyVar="currentIndex">
<f:facet name="header">
<rich:columnGroup>
<rich:column>
<h:outputText value="select"/>
</rich:column>
<rich:column>
<h:outputText value="Comment"/>
</rich:column>
</rich:columnGroup>
</f:facet>
<rich:column >
<h:selectBooleanCheckbox id="checkboxId"
value="#{sampleBean.selected}">
<a4j:support action="#{Sample.addSharedMessageAction}"
event="onclick" reRender="dataTableID">
<a4j:actionparam name="actionParemId"
value="#{currentIndex}"
assignTo="#{Sample.dataTableIndex}"/>
</a4j:support>
</h:selectBooleanCheckbox>
</rich:column>
<rich:column >
<h:inputTextarea value="#{sampleBean.comment}"
rendered="#{sampleBean.isSharedMessageRendered}"/>
</rich:column>
</rich:dataTable>

Checkbox won't update rendered value in table

So heres the skinny of it. I have a rendered tag on my selectOneMenu. I've tried it in various ways, this last one updating the form in the boolean checkbox with the "#form". I am all out of ideas, been working on it for a few days. What am I missing so I can render/unrender based on the selection of the checkbox? Thanks.
<rich:dataTable id="catalogview" width="100%" style="width: 100% !important"
columnClasses="lcolumnCatalog,columnCatalog,columnCatalog,columnCatalog,columnCatalog,columnCatalog,columnCatalog,columnCatalog,columnCatalog,columnCatalog,columnCatalog,columnCatalog,columnCatalog,columnCatalog,columnCatalog,columnCatalog,columnCatalog,columnCatalog"
value="#{pcnAlerts.notifications}" var="pcn" rows="20"
headerClass="headerCatalog" styleClass="table1" footerClass="footer_td" >
<h:column>
<h:selectBooleanCheckbox value="#{pcn.checked}" update="#form" >
<f:ajax listener="#{pcnAlerts.selectItem}" render=":popupForm:popupPanelContents" />
</h:selectBooleanCheckbox>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Status" />
</f:facet>
<h:outputText value="#{pcn.status}" />
<h:selectOneMenu id="StatusMenu" value="#{pcnAlerts.newStatus}" rendered="#{pcn.checked}">
<a4j:ajax update="StatusMenu" listener="#{pcnAlerts.saveStatus()}" />
<f:selectItem itemValue="" itemLabel="New" />
<f:selectItem itemValue="Pending" itemLabel="Pending" />
<f:selectItem itemValue="Complete" itemLabel="Complete" />
<f:selectItem itemValue="Archive" itemLabel="Archive" />
<f:selectItem itemValue="Disregard" itemLabel="Disregard" />
</h:selectOneMenu>
</h:column>
</rich:dataTable>
You must also update catalogview in order to render the components inside the table. Also, make sure your <rich:dataTable> is inside a <h:form>:
<h:form id="frmCatalog">
<rich:dataTable id="catalogview" value="#{pcnAlerts.notifications}" var="pcn">
<h:column>
<h:selectBooleanCheckbox value="#{pcn.checked}">
<f:ajax listener="#{pcnAlerts.selectItem}"
render=":popupForm:popupPanelContents :frmCatalog:catalogview" />
</h:selectBooleanCheckbox>
</h:column>
</rich:dataTable>
</h:form>

<h:dataTable value is not null, but the page is empty

I have two dataTables, one nest anther. The code as below :
<h:dataTable value="#{allUserBean.userList}" var="pmUsers">
<h:column headerClass="tableHeader column8Header">
<f:facet name="header">
<h:commandLink actionListener="#{allUser.sortByEmpNo}" immediate="true">
<h:panelGrid columns="2" columnClasses="colSortText,colSortImg">
<h:outputText value="Emp No." />
<h:panelGrid rendered="#{allUserBean.sortType == 0}">
<h:graphicImage url="/images/sortup.gif" rendered="#{allUserBean.up}" />
<h:graphicImage url="/images/sortdown.gif" rendered="#{!allUserBean.up}" />
</h:panelGrid>
</h:panelGrid>
</h:commandLink>
</f:facet>
<h:outputText value="#{pmUsers.employeeNo}" />
</h:column>
<h:dataTable var="iterm" value="#{pmUsers.userMultyResumeList}"">
<h:outputText value="#{iterm}" />
</h:dataTable> `
The show successful, but the other dataTable of userMultyResumeList can't be showed.
I used the testing code , it is false. so the value is not null, i don't know why
The userList code as :
private List<User> userList;
userList = userService.getUsersByPMGroupNotIncluded("", groupIds);
<h:dataTable var="iterm" value="#{pmUsers.userMultyResumeList}"">
Please repalce this line with this
<h:dataTable var="iterm" value="#{pmUsers.userMultyResumeList}">

How to use JSF's h:selectBooleanCheckbox with h:dataTable to get selected checkboxes without submitting the page content?

In my application, I have a h:datatable which contains vehicles data and h:selectBooleanCheckBox in each of its row. I want know the selected checkbox in the datatable datatable's row in the backing bean without applying any submit button. The idea of doing this is; when any user clicks the check boxes in one application page, s/he could easily see the selected rows in other pages aswell beacause the datatable in every page contains many vehicles. Therefore, users could be able to see the selected vehicles in any page and do the related operation.
The following shows part of my JSF page.
<rich:dataTable id="vehicleTable" var="vhcl" value="#{mainPage.vehicleList}"
binding="#{mainPage.vehicleTable}" >
<rich:column id="col_sel" width="10px"
<h:selectBooleanCheckbox title="#{general.showOnMap}" onclick="showOnMap(this)" id="selectedCheckBox" />
</rich:column>
<rich:column id="trackId" label="#{general.vehicleName}" >
<f:facet name="header">
<h:outputText value="#{general.vehicleName}" id="state_name" />
</f:facet>
<h:outputText value="#{vhcl.vehicle.mtsTrackId}" id="vehicleId" title="#{general.vehicleId}" style="font-size:10px; color:blue;" />
<br/>
<h:outputText value="#{vhcl.vehicle.vehiclePlate}" id="vehiclePlate" title="#{general.licencePlate}" style="font-size:10px; color:blue"/>
</rich:column>
<rich:column id="type_col" label="#{general.vehicleType}" >
<f:facet name="header">
<h:outputText value="#{general.vehichleType}" id="vehichleTypeLabel" />
</f:facet>
<h:graphicImage value="#{vhcl.typeImage}" height="40" width="40" align="left"/>
<h:panelGrid columns="1" align="right">
<h:graphicImage id="statusImage" value="#{vhcl.statusImage}" title="#{vhcl.status}" height="15" width="15" />
<h:graphicImage id="motorStatusImage" value="#{vhcl.motorStatusImage}" title="#{vhcl.motorStatus}" height="15" width="15" />
</h:panelGrid>
</rich:column>
<rich:column id="msg_col" label="#{general.lastMessageDate}" >
<f:facet name="header">
<h:outputText value="#{general.lastMessageDate}" id="lastMsgDateLabel" />
</f:facet>
<h:outputText value="#{vhcl.messageDate}" id="lastMsgDate" />
<br />
<h:outputText value="Hız: " />
<h:outputText value="#{vhcl.instantSpeed}" id="lastSpeed" style="color:blue; font-weight:bold" />
<h:outputText value="km/s" />
</rich:column>
<rich:column id="addr_col" label="#{general.address}" >
<f:facet name="header">
<h:outputText value="#{general.address}" id="addressLabel"/>
</f:facet>
<h:outputText value="#{vhcl.address}" id="addr" />
<br />
<h:outputText value="#{vhcl.location}" id="location" style="color:blue;" />
</rich:column>
In your Vehicle class create a Boolean field and add getter and setter methods for it like this.
private Boolean selected;
public Boolean getSelected() {
return selected;
}
public void setSelected(Boolean selected) {
this.selected = selected;
}
Then bind your checkBox to that property and add a <a4j:support> tag to the checkBox as below.
<h:selectBooleanCheckbox onclick="showOnMap(this)" value="#{vhcl.selected}">
<a4j:support event="onchange" ajaxSingle="true"/>
</h:selectBooleanCheckbox
Now when you check or uncheck the checkBox the value is submitted to the bean. Then any time you can find whether the vehicle is selected like this.
if(vehicle.selected != null && vehicle.selected) {
//vehicle is selected
}
Note: Your table should be inside a form.

checkbox should be checked before clicking delete commandbutton... how to do in jsf

<h:form>
<rich:dataTable value="#{classBean.classList}" var="class"
id="classTable" style="width: 90%" rows="10">
<f:facet name="header">
<h:outputText value="class list" style="float: left"></h:outputText>
</f:facet>
<rich:column style="width: 35px">
<h:selectBooleanCheckbox
value="#{classBean.selected[class.name]}" />
</rich:column>
<rich:column>
<f:facet name="header">
class name
</f:facet>
<h:outputText value="#{class.name}" />
</rich:column>
<f:facet name="footer">
<a4j:commandButton value="add" action="#{classBean.add}" />
<a4j:commandButton value="delete" action="#{classBean.delete}" />
</f:facet>
<rich:dataTable>
<h:form>
I have to validate such as the user should select at least one checkbox before clicking delete command button.
If I use validator it will check only checked or uncheked.... I need to check the checkbox when delete commandButton clicked
Add this code in your bean
private boolean checked;
public boolean isChecked()
{
if(selected.values().contains(true))
checked=true;
else
checked=false;
return checked;
}
use a popup panel to display error message and set the rendered attribute to #{bean.checked}

Resources