How to inactive the Tabs in Richfaces - jsf

I am using jsf with Richfaces. I've created a tabpanel using <rich:tabpanel>. I have taken 4 tabs like tab1, tab2, tab3 and tab4. if I run the application tab1 is default one. If I go to next tab I use navigation for every tab like NEXT<< and PREV>> .
If I click on a tab label, it is also changing the tabs. if I run the application, I want tab1 to be active and all others tabs are disabled (like tab2 or tab3 are disabled. If I click navigation buttons, only the tabs will be active.)
If I run the application, the tab1 will be active after fill up the tab1 details click the NEXT<< navigation then tab2 is active. Now the tab1 and tab2 are active. tab3 and tab4 are inactives.
What are the solution for the above two questions?

<rich:tabPanel switchType="ajax">
<rich:tab label="First">
Here is tab #1
</rich:tab>
<rich:tab label="Second" disabled="true">
Here is tab #2
</rich:tab>
<rich:tab label="Third" disabled="true">
Here is tab #3
</rich:tab>
</rich:tabPanel>
here second and third tab will be disabled , you can do something like
disabled= #{Bean.isDisabledTab1}
And handel it on next ,previous

Complementing org.life.java answer, you can add an action listener to the button or link that you are clicking when you switch tabs, for example:
<a4j:commandLink id="identifierLink" value="#{bean.ID_COUNT}"
actionListener="#{bean.switchTab}" reRender="clientTabPanel, clientTable">
<f:param id="internalID" value="#{bean.INTERNAL_ID}" name="internalIDParam"/>
</a4j:commandLink>
The switchTab action listener method would contain the logic to enable or disable the other tabs (just like org.life.java mentioned), and you could use f:param in case you want to pass something to your action listener when deciding to switch or not. I think you need to re-Render the tabPanel when you update the related property for the "disabled" attribute.

Related

JSF dropdown list inside a tab header

I'm using JSF and rich faces 4.5.5 and I'm trying to display a dropdown in the header of a tab panel. So far this is what I have:
<rich:tabPanel id="reportTabPanel" >
<a4j:repeat var="reportCategory" value="${workBean.categories}">
<rich:tab>
<f:facet name="header">
<h:panelGroup>
<h:selectOneMenu value="#{reportCategory.currentSelection}" style="background:none;border:none;width:15px">
<f:selectItems value="#{reportCategory.availableReports}" />
</h:selectOneMenu>
<h:outputText value="#{reportCategory.displayedTitle}" />
</h:panelGroup>
</f:facet>
<div id="reportContent" name="content" >
<h:outputText value="#{reportCategory.displayedContent}" escape="false" />
</div>
</rich:tab>
</a4j:repeat>
</rich:tabPanel>
It displays fine. I have the drop-down arrow displayed on the left and the tab's name on the right of each tab header. However the event handling is dodgy. When I click the dropdown, the list opens and closes as soon as I release the button (preventing me from making a selection in the list). In order to select anything from the dropdown list, I have to keep the mouse button pressed and release it outside of the header area so that the list does not close. Only then am I able to select my option in the dropdown zone.
I believe that the tab header is grabbing the release button event and using it to change tab if needed (which seems obvious).
What I would like is the dropdown to take priority over the tab header. Anyway of doing that?
Alternatively, is there a way of opening the dropdown when it is hovered over?
I'm not a huge expert in JSF. I've tried looking at implementing a custom Renderer but my issue is more to do with events than visual so not sure that is the right way to go. Any suggestion? Pointers?
Thanks
w.
Simply add onclick="event.stopPropagation()" to the h:selectOneMenu, that will prevent the click event reaching the tab.
(That said why do you need a select in the tab header? It's a navigation element.)

p:commandButton show other button after this button clicked

Hi I have a JSF "Register.xhtml" inside I have two Primefaces Command Buttons:
<p:commandButton id="registerButton"
action="#{registerController.register()}" rendered="#{!registerController.IsUserRegistered()}" />
<p:commandButton id="unregisterButton"
action="#{registerController.unregister()}" rendered="#{registerController.IsUserRegistered()}"/>
It works if I manually refresh the page.
I want a method to show the unregisterButtonand hiding the registerButton after I call the
registerController.register() function by clicking on the register Button.
You need to refresh the part of the page where the second button is after the click on the first button.
With Primefaces you can use PartialSubmit, http://www.primefaces.org/showcase/ui/ajax/partialSubmit.xhtml

How to upgrade select one of my other xhtml page?

I have a jsf form of registration that usually works on a select one menu is displayed a list of vehicles, in case the user needs to register a new vehicle for the issuance of the note he clicks one side of the select menu and opens a dialog to register .
Until then everything is working but when I close the dialog the registered vehicle only appears after typing F5. How can I do to update the select one menu. It is important to point out that the registration of the notes and open dialog xthmml are different pages, so do not know how.
Try putting styleClass="vehicles" to <p:selectOneMenu>, and update="#(.vehicles)" on <p:commandButton> in the dialog (the button in the dialog that adds the new vehicle). If everything is wired up correctly in the managed bean (the list that select one menu displays is updated), you should see the new car in the list.
<p:selectOneMenu styleClass="vehicles" ...>
<p:commandButton update="#(.vehicles)" ...>

refreshing a datatable

dudes, does any of you know how to do this?
i have a page that has a datatable on it. it has a button to delete a row. the button works as expected, when you click it, it will delete the selected row/s. i also have another button that opens a popup window where you search for items and them add them to the said datatable. i am having a hard time figuring out how to refresh the datatable once you click the "select" button on the popup window.
my solution is having a hidden button that will refresh the datatable. it works when i litterally click it. but when i trigger the click event on the popup window using javascript, it doesnt always work. sometime it refreshes, sometimes it doesnt.
what's actually the best way to refresh a datatable?
If you use JSF2.0, there is an option to update part of your application with
<h:form>
...
...(here you have the binding data)
<h:commandButton action="#{yourbean.updateRows}" >
<f:ajax render="tableName" />
</h:commandButton>
</h:form>
EDITED
If you want to invoke it from JAVASCRIPT use:
document.getElementById('elementName').click();
How are you accessing your DataTable in the popup window ? by keeping it in some session variable and in you parent page are you displaying the datatable through some UI Component like GridView ? In that case you can reload your parent window from where you opned the popu windo through javascript. E.g. window.opener.location.reload();
I can think of .. Datatable.AcceptChanges(); But that's for C#..

how to refresh the whole tabpanel in jsf

I am using richfaces and jsf.
I am using <rich:tabpanel> to create the tabs.
I have taken 4 tabs.
In 1st tab , one refresh button is available. If I click that button, the whole tabpanel is refreshed. whatever the data is kept in tab2, tab3 and tab4 will be clear.
use <a4j:support reRender="tabPanelComponentId"> inside your button, or use <a4j:commandButton reRender="tabPanelComponentId" />

Resources