How to visualize the elements in one line in Primefaces - jsf

I have the following form:
<h:form>
<h:selectOneMenu value="#{userRequestBean.selectedAgencyId}">
<f:selectItem itemLabel="Select" noSeletionOption="true" />
<f:selectItems
value="#{userRequestBean.requestAgencies[userActiveRequest]}"
var="agency" itemLabel="#{agency[0]}" itemValue="#{agency[1]}" />
</h:selectOneMenu>
<p:commandButton value="Hire"
action="#{userRequestBean.hireAgency}">
<f:setPropertyActionListener target="#{userRequestBean.request}"
value="${userActiveRequest}" />
</p:commandButton>
</h:form>
and i would like the SelectOneMenu and Button to be on one line. I tried with panelGrid but the select one menu becomes invisible, the same happens when i tried to use the standard HTML table. Can you give me an advice how to put then on one line? Thanks in advance!

use panelGrid and play with columns option. If you have N components and you want to put them in one line set columns value to N like:
<h:form>
<p:panelGrid columns="2" id="oneLineStyle">
<h:selectOneMenu value="#{userRequestBean.selectedAgencyId}">
<f:selectItem itemLabel="Select" noSeletionOption="true"/>
<f:selectItems
value="#{userRequestBean.requestAgencies[userActiveRequest]}"
var="agency" itemLabel="#{agency[0]}" itemValue="#{agency[1]}"/>
</h:selectOneMenu>
<p:commandButton value="Hire"
action="#{userRequestBean.hireAgency}">
<f:setPropertyActionListener target="#{userRequestBean.request}"
value="${userActiveRequest}"/>
</p:commandButton>
</p:panelGrid>
</h:form>

Related

How enable/disable <p:tab> without update form?

I have a big <h:form>, with a <p:tabView> with 3 <p:tab>
I want to enable/disable one <p:tab> based on <p:selectOneRadio> click.
How can I achieve this without updating the entire form?
<p:selectOneRadio id = "pessoa" required = "true"
value="#{myBean.typeChecked}" valueChangeListener="#{myBean.checkTypeSelec}">
<f:selectItem itemLabel="item 1" itemValue="PF" />
<f:selectItem itemLabel="item 2" itemValue="PJ" />
<p:ajax event="click" update="???" execute="#this"/>
</p:selectOneRadio>
<p:tab title="History" id="historyTab" disabled="#{myBean.historyDisabled}">...
I dont wanna update entire form because I dont wanna loose other inputs data

Default value from a list not passed to the next page while using <p:selectOneMenu> in jsf datatable

Default value from a list not passed to the next page while using in jsf datatable,all the default values get replaced with null value for all the items not selected in the datatable
You need to save the list using the managedbean in session scope.
Heading ##
<!-- <h:outputText value="#{rule.userAlertCategory.label}"/> -->
<p:selectOneMenu id="catCombo" value="#{rule.userAlertCategory}" style = "width:100%" converter="srUserAlertCategorySelectItemsConverter">
<p:ajax event="change" update="subCatCombo" listener="#{newAlertSetupController.onCategoryChanged}" process="#this"/>
<f:selectItem itemLabel="Select One" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{newAlertSetupController.userAlertCategoryList}" var="cat" itemLabel="#{cat.label}" itemValue="#{cat}"/>
</p:selectOneMenu>
</p:column>

Rerender multiple h:panelGrid on change of h:selectOneMenu in JSF 1.2

The situation:
I want to display specific panelGrid(s) on the page based on drop-down selection. I am doing this by storing several boolean which get set to true/false based on which item is selected in the drop down. I use the onchange="submit()" to refresh/re-render the page.
The problem:
I have validation on many fields in the form, so if I select an item it does validation and will not display the form.
The question:
How do I get the selectOneMenu change to re-render only the set of controls on the page being impacted instead of the whole page and causing validation?
The code: (JSF 1.2)
<h:selectOneMenu id="list" value="#{sessionBean.myDecorator.selectedItem}"
onchange="submit()" immediate="true" required="true"
valueChangeListener="#{requestBean.listChanged}">
<f:selectItem itemValue="#{null}" itemLabel="--Select One--" noSelectionOption="true" />
<f:selectItems value="#{sessionBean.myDecorator.mapItems}" />
</h:selectOneMenu>
Field causing validation:
<h:inputTextarea id="lblRequiredField" cols="100" rows="3" required="true" immediate="true"
value="#{sessionBean.myDecorator.myDo.myField}">
<f:validateLength minimum="1" maximum="300" />
</h:inputTextarea>

set default value for selectonemenu

I have a select menu like this :
<h:selectOneMenu value="#{serverMB.selectedServerType}" >
<f:converter binding="#{serverTypeConverter}"/>
<f:selectItems value="#{serverMB.serverTypesList}" var="servertypes"
itemLabel="#{servertypes.server_type_name}" />
<f:ajax listener="#{serverMB.changeSelectedOneMenuServerType}" render="selectservertype"/>
</h:selectOneMenu>
I want the default value of the select menu to be the value of one object that has been filled before, something like this:
<h:selectOneMenu value="#{serverMB.selectedServerType}" default="serverMB.server.servertype"> // <- default
or like this:
<h:selectOneMenu value="#{serverMB.selectedServerType}">
<f:converter binding="#{serverTypeConverter}"/>
<f:selectItem value"serverMB.server.servertype"/> <- but this item was the first one and has been selected
<f:selectItems value="#{serverMB.serverTypesList}" var="servertypes"
itemLabel="#{servertypes.server_type_name}" />
</h:selectOneMenu>
You can do something like this if your object is already populated when you call the page, if it is not, it will show the <f:selectItem/> message:
<h:selectOneMenu value="#{serverMB.server.servertype}">
<f:converter binding="#{serverTypeConverter}"/>
<f:selectItem itemLabel="Select a Server..." />
<f:selectItems value="#{serverMB.serverTypesList}" var="servertypes"
itemLabel="#{servertypes.server_type_name}"/>
<f:ajax listener="#{serverMB.changeSelectedOneMenuServerType}"
render="selectservertype"/>
</h:selectOneMenu>
You can also use the OmniFaces converter.
Here is my example. It works fine for me. (Note: Year is a object. Make sure, you have equals implemented. Year is name and id only.)
<h:selectOneMenu value="#{bean.user.year}"
converter="omnifaces.SelectItemsConverter">
<f:selectItem itemLabel="Please select a year." itemValue="#{null}"
noSelectionOption="true" />
<f:selectItems value="#{bean.allyears}" var="year"
itemValue="#{year}" itemLabel="#{year.name}" />
</h:selectOneMenu>

JSF SelectOneMenu Value not passing values to actionbean

I have a set of selectoneMenu list. The behavior of the dropdown is not constant.
Sometimes it passes the value as null, or still holds the existing values.
Anything i missed out? Or need to change any configuration?
<h:selectOneMenu id="blSearchzoneInput" value="#{bLDashBoardAction.zoneId}">
<f:selectItems value="#{bLDashBoardAction.zoneList}" var="c"
itemValue="#{c.zoneId}" />
</h:selectOneMenu>
thanks in advance
<h:selectOneMenu id="blSearchzoneInput" value="#{bLDashBoardAction.zoneId}">
<f:selectItems value="#{bLDashBoardAction.zoneList}" var="c"
itemValue="#{c.zoneId}" immediate="true" onchange="javascript: return this.form.submit();" />
</h:selectOneMenu>

Resources